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

feat: Allow NameFieldPath configurable #1506

Merged
merged 2 commits into from
Sep 13, 2023
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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ go 1.21

require (
github.com/OneOfOne/xxhash v1.2.8
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.1.0-dev.32
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.1.0-dev.9
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.1.0-dev.34
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.1.0-dev.11
github.com/edgexfoundry/go-mod-messaging/v3 v3.1.0-dev.20
github.com/google/uuid v1.3.1
github.com/hashicorp/go-multierror v1.1.1
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/eclipse/paho.mqtt.golang v1.4.3 h1:2kwcUGn8seMUfWndX0hGbvH8r7crgcJguQNCyp70xik=
github.com/eclipse/paho.mqtt.golang v1.4.3/go.mod h1:CSYvoAlsMkhYOXh/oKyxa8EcBci6dVkLCbo5tTC1RIE=
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.1.0-dev.32 h1:UhWAi2oyRa8alqOXPyFWdMOcG0pCUoIVNMkOgP5xRQE=
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.1.0-dev.32/go.mod h1:eC4dNTeMuXJ9h+i4F4Mqj464U0UCmLXWMh6rsHAPPHg=
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.1.0-dev.34 h1:cuQmkVACCdIsBbjKI/bkeaqn6xyzrK9gQ7wG7mTaQlI=
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.1.0-dev.34/go.mod h1:4EUbI5oJBsuMQnz9kgdLNHeXmQ/Q9NQuw2PRZbEkxkM=
github.com/edgexfoundry/go-mod-configuration/v3 v3.1.0-dev.5 h1:wTs2qOG/RHeizCHcPp8KOQcSzGrvNOhVQnK+JdAHJNs=
github.com/edgexfoundry/go-mod-configuration/v3 v3.1.0-dev.5/go.mod h1:mZyBGQ7eX+K63b46/K/OdiWSHtYbl/TK2GTfc0eOM6Q=
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.1.0-dev.9 h1:ZvCeuB1CXzNzg2WhpLCEKhkPSZpS0Geoh0AqTbj08X4=
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.1.0-dev.9/go.mod h1:L7i97+A+bMpvXFo1M6t0WHeRrsSocTgDEl3ayfVxCmo=
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.1.0-dev.11 h1:vYzWq4xbJJ4LVkagj+/01UOD8x4HZTK5k2x7EZh9ZjQ=
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.1.0-dev.11/go.mod h1:MztlrH+8hPRX6XNZrbdvbV0RNgkoAN1etcvAtgSHeuQ=
github.com/edgexfoundry/go-mod-messaging/v3 v3.1.0-dev.20 h1:iKhaDrfN0plO95MjPmrOEhfiUrE9gMD9Os7odtOrM10=
github.com/edgexfoundry/go-mod-messaging/v3 v3.1.0-dev.20/go.mod h1:cD3WRffguDrR/G7dIyzYewfoOk44VlJfGSkgbuUzvYM=
github.com/edgexfoundry/go-mod-registry/v3 v3.1.0-dev.5 h1:Xu1Jxk8gjMGMROqOf2C5pLY6lx1nWNYSDife2d623UE=
Expand Down
4 changes: 3 additions & 1 deletion internal/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ func SendEvent(event *dtos.Event, correlationID string, dic *di.Container) {
ctx = context.WithValue(ctx, common.ContentType, encoding) // nolint: staticcheck
envelope := types.NewMessageEnvelope(bytes, ctx)
serviceName := container.DeviceServiceFrom(dic.Get).Name
publishTopic := common.BuildTopic(configuration.MessageBus.GetBaseTopicPrefix(), common.EventsPublishTopic, DeviceServiceEventPrefix, common.URLEncode(serviceName), common.URLEncode(event.ProfileName), common.URLEncode(event.DeviceName), common.URLEncode(event.SourceName))
publishTopic := common.NewPathBuilder().EnableNameFieldEscape(configuration.Service.EnableNameFieldEscape).
SetPath(configuration.MessageBus.GetBaseTopicPrefix()).SetPath(common.EventsPublishTopic).SetPath(DeviceServiceEventPrefix).
SetNameFieldPath(serviceName).SetNameFieldPath(event.ProfileName).SetNameFieldPath(event.DeviceName).SetNameFieldPath(event.SourceName).BuildPath()
err = mc.Publish(envelope, publishTopic)
if err != nil {
lc.Errorf("Failed to publish event to MessageBus: %s", err)
Expand Down
9 changes: 5 additions & 4 deletions internal/controller/messaging/callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ import (

func MetadataSystemEventsCallback(ctx context.Context, serviceBaseName string, dic *di.Container) errors.EdgeX {
lc := bootstrapContainer.LoggingClientFrom(dic.Get)
configuration := container.ConfigurationFrom(dic.Get)
messageBusInfo := container.ConfigurationFrom(dic.Get).MessageBus
deviceService := container.DeviceServiceFrom(dic.Get)
metadataSystemEventTopic := common.BuildTopic(messageBusInfo.GetBaseTopicPrefix(),
common.MetadataSystemEventSubscribeTopic, common.URLEncode(deviceService.Name), "#")
metadataSystemEventTopic := common.NewPathBuilder().EnableNameFieldEscape(configuration.Service.EnableNameFieldEscape).
SetPath(messageBusInfo.GetBaseTopicPrefix()).SetPath(common.MetadataSystemEventSubscribeTopic).SetNameFieldPath(deviceService.Name).SetPath("#").BuildPath()

lc.Infof("Subscribing to System Events on topic: %s", metadataSystemEventTopic)

Expand All @@ -48,8 +49,8 @@ func MetadataSystemEventsCallback(ctx context.Context, serviceBaseName string, d
if serviceBaseName != deviceService.Name {
// Must replace the first wildcard with the type for Provision Watchers
baseSubscribeTopic := strings.Replace(common.MetadataSystemEventSubscribeTopic, "+", common.ProvisionWatcherSystemEventType, 1)
provisionWatcherSystemEventSubscribeTopic := common.BuildTopic(messageBusInfo.GetBaseTopicPrefix(),
baseSubscribeTopic, common.URLEncode(serviceBaseName), "#")
provisionWatcherSystemEventSubscribeTopic := common.NewPathBuilder().EnableNameFieldEscape(configuration.Service.EnableNameFieldEscape).
SetPath(messageBusInfo.GetBaseTopicPrefix()).SetPath(baseSubscribeTopic).SetNameFieldPath(serviceBaseName).SetPath("#").BuildPath()

topics = append(topics, types.TopicChannel{
Topic: provisionWatcherSystemEventSubscribeTopic,
Expand Down
8 changes: 5 additions & 3 deletions internal/controller/messaging/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ import (

func SubscribeCommands(ctx context.Context, dic *di.Container) errors.EdgeX {
lc := bootstrapContainer.LoggingClientFrom(dic.Get)
configuration := container.ConfigurationFrom(dic.Get)
messageBusInfo := container.ConfigurationFrom(dic.Get).MessageBus
deviceService := container.DeviceServiceFrom(dic.Get)
escapedDeviceServiceName := common.URLEncode(deviceService.Name)

requestSubscribeTopic := common.BuildTopic(messageBusInfo.GetBaseTopicPrefix(), common.CommandRequestSubscribeTopic, escapedDeviceServiceName, "#")
requestSubscribeTopic := common.NewPathBuilder().EnableNameFieldEscape(configuration.Service.EnableNameFieldEscape).
SetPath(messageBusInfo.GetBaseTopicPrefix()).SetPath(common.CommandRequestSubscribeTopic).SetNameFieldPath(deviceService.Name).SetPath("#").BuildPath()
lc.Infof("Subscribing to command requests on topic: %s", requestSubscribeTopic)

responsePublishTopicPrefix := common.BuildTopic(messageBusInfo.GetBaseTopicPrefix(), common.ResponseTopic, escapedDeviceServiceName)
responsePublishTopicPrefix := common.NewPathBuilder().EnableNameFieldEscape(configuration.Service.EnableNameFieldEscape).
SetPath(messageBusInfo.GetBaseTopicPrefix()).SetPath(common.ResponseTopic).SetNameFieldPath(deviceService.Name).BuildPath()
lc.Infof("Responses to command requests will be published on topic: %s/<requestId>", responsePublishTopicPrefix)

messages := make(chan types.MessageEnvelope, 1)
Expand Down
9 changes: 6 additions & 3 deletions internal/controller/messaging/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ import (

func SubscribeDeviceValidation(ctx context.Context, dic *di.Container) errors.EdgeX {
lc := bootstrapContainer.LoggingClientFrom(dic.Get)
configuration := container.ConfigurationFrom(dic.Get)
messageBusInfo := container.ConfigurationFrom(dic.Get).MessageBus
serviceName := common.URLEncode(container.DeviceServiceFrom(dic.Get).Name)
serviceName := container.DeviceServiceFrom(dic.Get).Name

requestTopic := common.BuildTopic(messageBusInfo.GetBaseTopicPrefix(), serviceName, common.ValidateDeviceSubscribeTopic)
requestTopic := common.NewPathBuilder().EnableNameFieldEscape(configuration.Service.EnableNameFieldEscape).
SetPath(messageBusInfo.GetBaseTopicPrefix()).SetNameFieldPath(serviceName).SetPath(common.ValidateDeviceSubscribeTopic).BuildPath()
lc.Infof("Subscribing to device validation requests on topic: %s", requestTopic)

responseTopicPrefix := common.BuildTopic(messageBusInfo.GetBaseTopicPrefix(), common.ResponseTopic, serviceName)
responseTopicPrefix := common.NewPathBuilder().EnableNameFieldEscape(configuration.Service.EnableNameFieldEscape).
SetPath(messageBusInfo.GetBaseTopicPrefix()).SetPath(common.ResponseTopic).SetNameFieldPath(serviceName).BuildPath()
lc.Infof("Responses to device validation requests will be published on topic: %s/<requestId>", responseTopicPrefix)

messages := make(chan types.MessageEnvelope, 1)
Expand Down