Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Consume Things connect event in bootstrap #2142

Open
JeffMboya opened this issue Apr 8, 2024 · 1 comment · May be fixed by #2192
Open

Feature: Consume Things connect event in bootstrap #2142

JeffMboya opened this issue Apr 8, 2024 · 1 comment · May be fixed by #2192

Comments

@JeffMboya
Copy link
Contributor

JeffMboya commented Apr 8, 2024

Is your feature request related to a problem? Please describe.

Currently, Bootstrap events.go handles removeEvent, updateChannelEvent, and disconnectEvent in the consumer package. However, we do not have a mechanism to consume a connectEvent when a Thing connect event

Describe the feature you are requesting, as well as the possible use case(s) for it.

Addition of a connectEvent struct in the consumer package. This struct would contain the thingID and channelID, similar to the disconnectEvent shown below. This event would be triggered whenever a Thing connects to the system.
image

Indicate the importance of this feature to you.

Must-have

Anything else?

Here's a rough idea of what the independent connectEvent struct might look like:

type connectEvent struct {
	thingID   string
	channelID string
}

Alternatively, define a connection event that consumes both Thing connect and Thing disconnect as below:

type connectionEvent struct {
	chanID  string
	thingID string
}

func decodeConnectionThing(event map[string]interface{}) connectionThingEvent {
	return connectionThingEvent{
		chanID:  read(event, "chan_id", ""),
		thingID: read(event, "thing_id", ""),
	}
func (es *eventHandler) Handle(ctx context.Context, event events.Event) error {
	msg, err := event.Encode()
	if err != nil {
		return err
	}
	switch msg["operation"] {
	case thingConnect:
		tce := decodeConnectionThing(msg)
		err = es.svc.ConnectThing(ctx, tce.chanID, tce.thingID)
	case thingDisconnect:
		tde := decodeConnectionThing(msg)
		err = es.svc.DisconnectThing(ctx, tde.chanID, tde.thingID)
	}
	if err != nil && err != errMetadataType {
		return err
	}

	return nil
}

This feature request is based on the current code in the consumer package:

@JeffMboya JeffMboya self-assigned this Apr 8, 2024
@dborovcanin dborovcanin modified the milestones: S2, S3 Apr 17, 2024
@dborovcanin
Copy link
Collaborator

This is related to #1955.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 🧪 Review and testing in progress
Development

Successfully merging a pull request may close this issue.

2 participants