Skip to content

Commit

Permalink
refactor!: Replace internal topics from config with new constants (#1301
Browse files Browse the repository at this point in the history
)

BREAKING CHANGE: Internal topics no longer configurable, except the base topic. Trigger topics for edgex-messagebus and external-mqtt now directly under Trigger section.

Signed-off-by: Leonard Goodell <leonard.goodell@intel.com>
  • Loading branch information
Lenny Goodell authored Feb 15, 2023
1 parent 1be498e commit a57f3f5
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 101 deletions.
6 changes: 3 additions & 3 deletions app-service-template/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ replace github.com/edgexfoundry/app-functions-sdk-go/v3 => ../

require (
github.com/edgexfoundry/app-functions-sdk-go/v3 v3.0.0-dev.9
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.10
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.14
github.com/google/uuid v1.3.0
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475
github.com/stretchr/testify v1.8.1
Expand All @@ -23,9 +23,9 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/diegoholiveira/jsonlogic/v3 v3.2.7 // indirect
github.com/eclipse/paho.mqtt.golang v1.4.2 // indirect
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.0.0-dev.22 // indirect
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.0.0-dev.24 // indirect
github.com/edgexfoundry/go-mod-configuration/v3 v3.0.0-dev.3 // indirect
github.com/edgexfoundry/go-mod-messaging/v3 v3.0.0-dev.7 // indirect
github.com/edgexfoundry/go-mod-messaging/v3 v3.0.0-dev.9 // indirect
github.com/edgexfoundry/go-mod-registry/v3 v3.0.0-dev.3 // indirect
github.com/edgexfoundry/go-mod-secrets/v3 v3.0.0-dev.7 // indirect
github.com/fatih/color v1.9.0 // indirect
Expand Down
12 changes: 6 additions & 6 deletions app-service-template/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ github.com/diegoholiveira/jsonlogic/v3 v3.2.7 h1:awX07pFPnlntZzRNBcO4a2Ivxa77NMt
github.com/diegoholiveira/jsonlogic/v3 v3.2.7/go.mod h1:9oE8z9G+0OMxOoLHF3fhek3KuqD5CBqM0B6XFL08MSg=
github.com/eclipse/paho.mqtt.golang v1.4.2 h1:66wOzfUHSSI1zamx7jR6yMEI5EuHnT1G6rNA5PM12m4=
github.com/eclipse/paho.mqtt.golang v1.4.2/go.mod h1:JGt0RsEwEX+Xa/agj90YJ9d9DH2b7upDZMK9HRbFvCA=
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.0.0-dev.22 h1:DrtTbcDU6VMoMmsAn9tQpxQ+MIwgtSBmSwuZLgFuDEQ=
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.0.0-dev.22/go.mod h1:rVklwwUju+/MGOij+KJeBJZ+/HIo6YsQwlFv7UmsA+8=
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.0.0-dev.24 h1:H9MC0ahbkMw4w1SHeX6/GVR5tC6E+Bz6ZiPECmnzO3c=
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.0.0-dev.24/go.mod h1:iv/czxi4ciFWMgrO+3nnanGfkT2X1QW5L3iCb+deewk=
github.com/edgexfoundry/go-mod-configuration/v3 v3.0.0-dev.3 h1:0Ew4PzLSFJ+sb7AYtvb9m1mRN45Sh0ELU1HdMCel5t8=
github.com/edgexfoundry/go-mod-configuration/v3 v3.0.0-dev.3/go.mod h1:ESOWI4GokQfQ3Bn2hGsdfOVx5idj7QEdCPT/SAQDd9M=
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.10 h1:o5yenvmLn8+0AOz0d5GIek011Tt5ZRbvPlgE4VhozEU=
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.10/go.mod h1:4lpZUM54ZareGU/yuAJvLEw0BoJ43SvCj1LO+gsKm9c=
github.com/edgexfoundry/go-mod-messaging/v3 v3.0.0-dev.7 h1:jgDQA/7SENURXQkIX11pNgA/pX9IK9ZULenj/vF17Vw=
github.com/edgexfoundry/go-mod-messaging/v3 v3.0.0-dev.7/go.mod h1:r6Klfz+QBDx1Z5UV0z70MKdK2/cgHwhtqTm2HFXoWug=
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.14 h1:o7CFEIyKn/quin5lrAlUbUu9x1dnecK0tZs5waLhdCc=
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.14/go.mod h1:4lpZUM54ZareGU/yuAJvLEw0BoJ43SvCj1LO+gsKm9c=
github.com/edgexfoundry/go-mod-messaging/v3 v3.0.0-dev.9 h1:CUUieXQ8roD4M770GXj1he707V3V9Jiygk302+dwvKk=
github.com/edgexfoundry/go-mod-messaging/v3 v3.0.0-dev.9/go.mod h1:iKBxmZkc7jdOrT99+IR1nyg7PlRgooAQMhZxDh2mTUQ=
github.com/edgexfoundry/go-mod-registry/v3 v3.0.0-dev.3 h1:QgZF9f70Cwpvkjw3tP1aiVGHc+yNFJNzW6hO8pDs3fg=
github.com/edgexfoundry/go-mod-registry/v3 v3.0.0-dev.3/go.mod h1:2w8v0sv+i21nY+DY6JV4PFxsNTuxpGAjlNFlFMTfZkk=
github.com/edgexfoundry/go-mod-secrets/v3 v3.0.0-dev.7 h1:9Mn389IHlgoPgGUpwnLzoe/shylkQI+nXI3E/AfnYDA=
Expand Down
8 changes: 4 additions & 4 deletions app-service-template/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ func (app *myApp) CreateAndRunAppService(serviceKey string, newServiceFactory fu
// Or remove default above if your use case needs multiple pipelines by topic.
// Example of adding functions pipelines by topic.
// These pipelines will only execute if the specified topic match the incoming topic.
// Note: Device services publish to the 'edgex/events/device/<profile-name>/<device-name>/<source-name>' topic
// Core Data publishes to the 'edgex/events/core/<profile-name>/<device-name>/<source-name>' topic
// Note: Device services publish to the 'edgex/events/device/<device-service-name><profile-name>/<device-name>/<source-name>' topic
// Core Data publishes to the 'edgex/events/core/<device-service-name>/<profile-name>/<device-name>/<source-name>' topic
// Note: This example with default above causes Events from Random-Float-Device device to be processed twice
// resulting in the XML to be published back to the MessageBus twice.
// See https://docs.edgexfoundry.org/latest/microservices/application/AdvancedTopics/#pipeline-per-topics for more details.
err = app.service.AddFunctionsPipelineForTopics("Floats", []string{"edgex/events/+/+/Random-Float-Device/#"},
err = app.service.AddFunctionsPipelineForTopics("Floats", []string{"edgex/events/+/device-virtual/+/Random-Float-Device/#"},
transforms.NewFilterFor(deviceNames).FilterByDeviceName,
sample.LogEventDetails,
sample.ConvertEventToXML,
Expand All @@ -133,7 +133,7 @@ func (app *myApp) CreateAndRunAppService(serviceKey string, newServiceFactory fu
}
// Note: This example with default above causes Events from Int32 source to be processed twice
// resulting in the XML to be published back to the MessageBus twice.
err = app.service.AddFunctionsPipelineForTopics("Int32s", []string{"edgex/events/+/+/+/Int32"},
err = app.service.AddFunctionsPipelineForTopics("Int32s", []string{"edgex/events/+/device-virtual/+/+/Int32"},
transforms.NewFilterFor(deviceNames).FilterByDeviceName,
sample.LogEventDetails,
sample.ConvertEventToXML,
Expand Down
34 changes: 4 additions & 30 deletions app-service-template/res/configuration.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ HTTPSKeyName = "key"
# Only valid if MessageBus Trigger is used
# If prefer REST, remove below and uncomment above
UseMessageBus = true
[Clients.core-command.Topics]
CommandQueryRequestTopicPrefix = "edgex/core/commandquery/request"
CommandRequestTopicPrefix = "edgex/core/command/request"
ResponseTopicPrefix = "edgex/response"

[Clients.support-notifications]
Protocol = "http"
Expand All @@ -58,51 +54,29 @@ HTTPSKeyName = "key"

[MessageBus]
Disabled = false # TODO: set to true if not using edgex-messagebus Trigger below and don't want Metrics or Commands via MessageBus
[MessageBus.Topics]
SubscribeTopics = "edgex/events/#"
PublishTopic="event-xml"
[MessageBus.Optional]
# Default MQTT Specific options that need to be here to enable environment variable overrides of them
ClientId ="app-new-service"

# TODO: If using mqtt messagebus, Uncomment this section and remove above [MessageBus] section,
# Otherwise remove this commented out block
#[MessageBus]
#Protocol = "tcp"
#Host = "localhost"
#Port = 1883
#Type = "mqtt"
#AuthMode = "none" # required for redis messagebus (secure or insecure).
#SecretName = "mqtt-bus"
# [MessageBus.Topics]
# SubscribeTopics = "edgex/events/#"
# PublishTopic="event-xml"
# [MessageBus.Optional]
# ClientId ="app-new-service"
# Qos = "0" # Quality of Sevice values are 0 (At most once), 1 (At least once) or 2 (Exactly once)
# KeepAlive = "10" # Seconds (must be 2 or greater)
# Retained = "false"
# AutoReconnect = "true"
# ConnectTimeout = "5" # Seconds
# SkipCertVerify = "false"

[Trigger]
# Note that the MessaegBus connection above is used by edgex-messagebus trigger
Type="edgex-messagebus"
SubscribeTopics = "edgex/events/#"
PublishTopic="event-xml"

# TODO: Add custom settings needed by your app service or remove if you don't have any settings.
# This can be any Key/Value pair you need.
# For more details see: https://docs.edgexfoundry.org/latest/microservices/application/GeneralAppServiceConfig/#application-settings
# Example that works with devices from the Virtual Device service:
[ApplicationSettings]
DeviceNames = "Random-Boolean-Device, Random-Integer-Device, Random-UnsignedInteger-Device, Random-Float-Device, Random-Binary-Device, sample-numeric"
DeviceNames = "Simple-Device01, Random-Boolean-Device, Random-Integer-Device, Random-UnsignedInteger-Device, Random-Float-Device, Random-Binary-Device, sample-numeric"

# TODO: Replace this section with your actual structured custom configuration section
# or remove if you don't have a need for structured custom configuration
# This can be any structure you need, but it can not contain slices. Use a maps instead of slices.
# For more details see: https://docs.edgexfoundry.org/latest/microservices/application/GeneralAppServiceConfig/#custom-configuration
[AppCustom]
ResourceNames = "Boolean, Int32, Uint32, Float32, Binary, Switch"
ResourceNames = "Boolean, Int32, Uint32, Float32, Binary, SwitchButton"
SomeValue = 123
[AppCustom.SomeService]
Host = "localhost"
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ go 1.18
require (
github.com/diegoholiveira/jsonlogic/v3 v3.2.7
github.com/eclipse/paho.mqtt.golang v1.4.2
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.0.0-dev.22
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.10
github.com/edgexfoundry/go-mod-messaging/v3 v3.0.0-dev.7
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.0.0-dev.24
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.14
github.com/edgexfoundry/go-mod-messaging/v3 v3.0.0-dev.9
github.com/edgexfoundry/go-mod-registry/v3 v3.0.0-dev.3
github.com/fxamacker/cbor/v2 v2.4.0
github.com/gomodule/redigo v1.8.9
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ github.com/diegoholiveira/jsonlogic/v3 v3.2.7 h1:awX07pFPnlntZzRNBcO4a2Ivxa77NMt
github.com/diegoholiveira/jsonlogic/v3 v3.2.7/go.mod h1:9oE8z9G+0OMxOoLHF3fhek3KuqD5CBqM0B6XFL08MSg=
github.com/eclipse/paho.mqtt.golang v1.4.2 h1:66wOzfUHSSI1zamx7jR6yMEI5EuHnT1G6rNA5PM12m4=
github.com/eclipse/paho.mqtt.golang v1.4.2/go.mod h1:JGt0RsEwEX+Xa/agj90YJ9d9DH2b7upDZMK9HRbFvCA=
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.0.0-dev.22 h1:DrtTbcDU6VMoMmsAn9tQpxQ+MIwgtSBmSwuZLgFuDEQ=
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.0.0-dev.22/go.mod h1:rVklwwUju+/MGOij+KJeBJZ+/HIo6YsQwlFv7UmsA+8=
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.0.0-dev.24 h1:H9MC0ahbkMw4w1SHeX6/GVR5tC6E+Bz6ZiPECmnzO3c=
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.0.0-dev.24/go.mod h1:iv/czxi4ciFWMgrO+3nnanGfkT2X1QW5L3iCb+deewk=
github.com/edgexfoundry/go-mod-configuration/v3 v3.0.0-dev.3 h1:0Ew4PzLSFJ+sb7AYtvb9m1mRN45Sh0ELU1HdMCel5t8=
github.com/edgexfoundry/go-mod-configuration/v3 v3.0.0-dev.3/go.mod h1:ESOWI4GokQfQ3Bn2hGsdfOVx5idj7QEdCPT/SAQDd9M=
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.10 h1:o5yenvmLn8+0AOz0d5GIek011Tt5ZRbvPlgE4VhozEU=
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.10/go.mod h1:4lpZUM54ZareGU/yuAJvLEw0BoJ43SvCj1LO+gsKm9c=
github.com/edgexfoundry/go-mod-messaging/v3 v3.0.0-dev.7 h1:jgDQA/7SENURXQkIX11pNgA/pX9IK9ZULenj/vF17Vw=
github.com/edgexfoundry/go-mod-messaging/v3 v3.0.0-dev.7/go.mod h1:r6Klfz+QBDx1Z5UV0z70MKdK2/cgHwhtqTm2HFXoWug=
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.14 h1:o7CFEIyKn/quin5lrAlUbUu9x1dnecK0tZs5waLhdCc=
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.14/go.mod h1:4lpZUM54ZareGU/yuAJvLEw0BoJ43SvCj1LO+gsKm9c=
github.com/edgexfoundry/go-mod-messaging/v3 v3.0.0-dev.9 h1:CUUieXQ8roD4M770GXj1he707V3V9Jiygk302+dwvKk=
github.com/edgexfoundry/go-mod-messaging/v3 v3.0.0-dev.9/go.mod h1:iKBxmZkc7jdOrT99+IR1nyg7PlRgooAQMhZxDh2mTUQ=
github.com/edgexfoundry/go-mod-registry/v3 v3.0.0-dev.3 h1:QgZF9f70Cwpvkjw3tP1aiVGHc+yNFJNzW6hO8pDs3fg=
github.com/edgexfoundry/go-mod-registry/v3 v3.0.0-dev.3/go.mod h1:2w8v0sv+i21nY+DY6JV4PFxsNTuxpGAjlNFlFMTfZkk=
github.com/edgexfoundry/go-mod-secrets/v3 v3.0.0-dev.7 h1:9Mn389IHlgoPgGUpwnLzoe/shylkQI+nXI3E/AfnYDA=
Expand Down
9 changes: 5 additions & 4 deletions internal/app/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,13 @@ func (svc *Service) AddRoute(route string, handler func(nethttp.ResponseWriter,
// AddBackgroundPublisher will create a channel of provided capacity to be
// consumed by the MessageBus output and return a publisher that writes to it
func (svc *Service) AddBackgroundPublisher(capacity int) (interfaces.BackgroundPublisher, error) {
topic := svc.config.MessageBus.Topics[internal.MessageBusPublishTopic]
publishTopic := strings.TrimSpace(svc.config.Trigger.PublishTopic)

if topic == "" {
return nil, errors.New("no publish topic configured for messagebus, background publishing unavailable")
if len(publishTopic) == 0 {
return nil, errors.New("publish topic not configured for Trigger, background publishing unavailable")
}
return svc.AddBackgroundPublisherWithTopic(capacity, topic)

return svc.AddBackgroundPublisherWithTopic(capacity, publishTopic)
}

// AddBackgroundPublisherWithTopic will create a channel of provided capacity to be
Expand Down
19 changes: 6 additions & 13 deletions internal/app/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
bootstrapContainer "github.com/edgexfoundry/go-mod-bootstrap/v3/bootstrap/container"
bootstrapInterfaces "github.com/edgexfoundry/go-mod-bootstrap/v3/bootstrap/interfaces"
"github.com/edgexfoundry/go-mod-bootstrap/v3/bootstrap/interfaces/mocks"
"github.com/edgexfoundry/go-mod-bootstrap/v3/config"
"github.com/edgexfoundry/go-mod-bootstrap/v3/di"
clients "github.com/edgexfoundry/go-mod-core-contracts/v3/clients/http"
"github.com/edgexfoundry/go-mod-core-contracts/v3/clients/logger"
Expand Down Expand Up @@ -124,13 +123,9 @@ func TestAddBackgroundPublisherNoTopic(t *testing.T) {
func TestAddBackgroundPublisherMessageBus(t *testing.T) {
sdk := Service{
config: &common.ConfigurationStruct{
MessageBus: config.MessageBusInfo{
Topics: map[string]string{
"PublishTopic": "topic",
},
},
Trigger: common.TriggerInfo{
Type: TriggerTypeMessageBus,
Type: TriggerTypeMessageBus,
PublishTopic: "topic",
},
},
}
Expand All @@ -147,7 +142,7 @@ func TestAddBackgroundPublisherMessageBus(t *testing.T) {

require.NotNil(t, pub.output, "publisher should have an output channel set")
require.NotNil(t, sdk.backgroundPublishChannel, "svc should have a background channel set for passing to trigger initialization")
require.Equal(t, sdk.config.MessageBus.Topics["PublishTopic"], pub.topic)
require.Equal(t, sdk.config.Trigger.PublishTopic, pub.topic)

// compare addresses since types will not match
assert.Equal(t, fmt.Sprintf("%p", sdk.backgroundPublishChannel), fmt.Sprintf("%p", pub.output),
Expand All @@ -157,11 +152,9 @@ func TestAddBackgroundPublisherMessageBus(t *testing.T) {
func TestAddBackgroundPublisher_Arbitrary(t *testing.T) {
sdk := Service{
config: &common.ConfigurationStruct{
MessageBus: config.MessageBusInfo{
Topics: map[string]string{"PublishTopic": "topic"},
},
Trigger: common.TriggerInfo{
Type: "NOT MQTT OR HTTP",
Type: "NOT MQTT OR HTTP",
PublishTopic: "topic",
},
},
}
Expand All @@ -178,7 +171,7 @@ func TestAddBackgroundPublisher_Arbitrary(t *testing.T) {

require.NotNil(t, pub.output, "publisher should have an output channel set")
require.NotNil(t, sdk.backgroundPublishChannel, "svc should have a background channel set for passing to trigger initialization")
require.Equal(t, sdk.config.MessageBus.Topics["PublishTopic"], pub.topic)
require.Equal(t, sdk.config.Trigger.PublishTopic, pub.topic)

// compare addresses since types will not match
assert.Equal(t, fmt.Sprintf("%p", sdk.backgroundPublishChannel), fmt.Sprintf("%p", pub.output),
Expand Down
10 changes: 6 additions & 4 deletions internal/common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ type TriggerInfo struct {
// Type of trigger to start pipeline
// enum: http, edgex-messagebus, or external-mqtt
Type string
// SubscribeTopics is a comma separated list of topics in which to subscribe
// Used when type in edgex-messagebus, or external-mqtt
SubscribeTopics string
// PublishTopic is the topic to publish pipeline output (if any)
// Used when type in edgex-messagebus, or external-mqtt
PublishTopic string
// Used when Type=external-mqtt
ExternalMqtt ExternalMqttConfig
}
Expand All @@ -85,10 +91,6 @@ type HttpConfig struct {
type ExternalMqttConfig struct {
// Url contains the fully qualified URL to connect to the MQTT broker
Url string
// SubscribeTopics is a comma separated list of topics in which to subscribe
SubscribeTopics string
// PublishTopic is the topic to publish pipeline output (if any)
PublishTopic string
// ClientId to connect to the broker with.
ClientId string
// ConnectTimeout is a time duration indicating how long to wait timing out on the broker connection
Expand Down
18 changes: 5 additions & 13 deletions internal/trigger/messagebus/messaging.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,7 @@ func (trigger *Trigger) Initialize(appWg *sync.WaitGroup, appCtx context.Context
return nil, errors.New("unable to find MessageBus Client. Make sure it is configured properly")
}

subscribeTopics, exists := config.MessageBus.Topics[internal.MessageBusSubscribeTopics]
if !exists {
return nil, fmt.Errorf("missing '%s' from 'MessageBus.Topics' configuration", internal.MessageBusSubscribeTopics)
}

subscribeTopics = strings.TrimSpace(subscribeTopics)
subscribeTopics := strings.TrimSpace(config.Trigger.SubscribeTopics)
if len(subscribeTopics) == 0 {
return nil, fmt.Errorf("'%s' can not be an empty string. Must contain one or more topic seperated by commas", internal.MessageBusSubscribeTopics)
} else {
Expand All @@ -94,14 +89,11 @@ func (trigger *Trigger) Initialize(appWg *sync.WaitGroup, appCtx context.Context

lc.Infof("Subscribing to topic(s): '%s'", subscribeTopics)

publishTopic, exists := config.MessageBus.Topics[internal.MessageBusPublishTopic]

if exists {
trigger.publishTopic = strings.TrimSpace(publishTopic)
if len(trigger.publishTopic) == 0 {
return nil, fmt.Errorf("'%s' can not be an empty string. Must contain conatin a single non-empty topic", internal.MessageBusPublishTopic)
}
trigger.publishTopic = strings.TrimSpace(config.Trigger.PublishTopic)
if len(trigger.publishTopic) > 0 {
lc.Infof("Publishing to topic: '%s'", trigger.publishTopic)
} else {
lc.Infof("Publish topic not set for Trigger. Response data, if set, will not be published")
}

// Need to have a go func for each subscription, so we know with topic the data was received for.
Expand Down
13 changes: 3 additions & 10 deletions internal/trigger/messagebus/messaging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ import (
"sync"
"testing"

"github.com/edgexfoundry/app-functions-sdk-go/v3/internal"
bootstrapContainer "github.com/edgexfoundry/go-mod-bootstrap/v3/bootstrap/container"
bootstrapConfig "github.com/edgexfoundry/go-mod-bootstrap/v3/config"
"github.com/edgexfoundry/go-mod-bootstrap/v3/di"
"github.com/edgexfoundry/go-mod-messaging/v3/messaging/mocks"

Expand Down Expand Up @@ -71,15 +69,10 @@ func TestMain(m *testing.M) {
func TestInitialize(t *testing.T) {

config := sdkCommon.ConfigurationStruct{
MessageBus: bootstrapConfig.MessageBusInfo{
Topics: map[string]string{
internal.MessageBusSubscribeTopics: "events",
internal.MessageBusPublishTopic: "publish",
},
},

Trigger: sdkCommon.TriggerInfo{
Type: TriggerTypeMessageBus,
Type: TriggerTypeMessageBus,
SubscribeTopics: "events",
PublishTopic: "publish",
},
}

Expand Down
8 changes: 4 additions & 4 deletions internal/trigger/mqtt/mqtt.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ func (trigger *Trigger) Initialize(_ *sync.WaitGroup, ctx context.Context, backg
config := trigger.serviceBinding.Config()

brokerConfig := config.Trigger.ExternalMqtt
topics := config.Trigger.ExternalMqtt.SubscribeTopics
topics := config.Trigger.SubscribeTopics

trigger.qos = brokerConfig.QoS
trigger.retain = brokerConfig.Retain
trigger.publishTopic = config.Trigger.ExternalMqtt.PublishTopic
trigger.publishTopic = config.Trigger.PublishTopic

lc.Info("Initializing MQTT Trigger")

Expand Down Expand Up @@ -151,7 +151,7 @@ func (trigger *Trigger) onConnectHandler(mqttClient pahoMqtt.Client) {
// Convenience short cuts
lc := trigger.serviceBinding.LoggingClient()
config := trigger.serviceBinding.Config()
topics := util.DeleteEmptyAndTrim(strings.FieldsFunc(config.Trigger.ExternalMqtt.SubscribeTopics, util.SplitComma))
topics := util.DeleteEmptyAndTrim(strings.FieldsFunc(config.Trigger.SubscribeTopics, util.SplitComma))
topicMap := map[string]byte{}
for _, topic := range topics {
topicMap[topic] = config.Trigger.ExternalMqtt.QoS
Expand All @@ -162,7 +162,7 @@ func (trigger *Trigger) onConnectHandler(mqttClient pahoMqtt.Client) {
topicMap, token.Error().Error())
}

lc.Infof("Subscribed to topic(s) '%s' for MQTT trigger", config.Trigger.ExternalMqtt.SubscribeTopics)
lc.Infof("Subscribed to topic(s) '%s' for MQTT trigger", config.Trigger.SubscribeTopics)
}

func (trigger *Trigger) messageHandler(_ pahoMqtt.Client, mqttMessage pahoMqtt.Message) {
Expand Down
Loading

0 comments on commit a57f3f5

Please sign in to comment.