Consume Things connect event in Bootstrap
JeffMboya opened this issue · comments
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.
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:
This is related to #1955.