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

fix: Add call to Message Bus Connect() #2467

Merged
merged 1 commit into from
Apr 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/edgexfoundry/go-mod-bootstrap v0.0.26
github.com/edgexfoundry/go-mod-configuration v0.0.3
github.com/edgexfoundry/go-mod-core-contracts v0.1.52
github.com/edgexfoundry/go-mod-messaging v0.1.14
github.com/edgexfoundry/go-mod-messaging v0.1.16
github.com/edgexfoundry/go-mod-registry v0.1.17
github.com/edgexfoundry/go-mod-secrets v0.0.17
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8
Expand Down
33 changes: 32 additions & 1 deletion internal/core/data/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func (b *Bootstrap) BootstrapHandler(ctx context.Context, wg *sync.WaitGroup, _

configuration := dataContainer.ConfigurationFrom(dic.Get)
registryClient := container.RegistryFrom(dic.Get)
lc := container.LoggingClientFrom(dic.Get)

mdc := metadata.NewDeviceClient(
urlclient.New(
Expand Down Expand Up @@ -90,12 +91,42 @@ func (b *Bootstrap) BootstrapHandler(ctx context.Context, wg *sync.WaitGroup, _
Optional: configuration.MessageQueue.Optional,
})

lc := container.LoggingClientFrom(dic.Get)
if err != nil {
lc.Error(fmt.Sprintf("failed to create messaging client: %s", err.Error()))
return false
}

err = msgClient.Connect()
if err != nil {
lc.Error(fmt.Sprintf("failed to connect to message bus: %s", err.Error()))
return false
}

// Setup special "defer" go func that will disconnect from the message bus when the service is exiting
wg.Add(1)
go func() {
defer wg.Done()
for {
select {
case <-ctx.Done():
if err := msgClient.Disconnect(); err != nil {
lc.Error("failed to disconnect from the Message Bus")
return
}
lc.Info("Message Bus disconnected")
return
}
}
}()

lc.Info(fmt.Sprintf(
"Connected to %s Message Bus @ %s://%s:%d publishing on '%s' topic",
configuration.MessageQueue.Type,
configuration.MessageQueue.Protocol,
configuration.MessageQueue.Host,
configuration.MessageQueue.Port,
configuration.MessageQueue.Topic))

chEvents := make(chan interface{}, 100)
// initialize event handlers
initEventHandlers(lc, chEvents, mdc, msc, configuration)
Expand Down