Skip to content

feat(command): publish device service response to external MQTT#4166

Merged
cloudxxx8 merged 3 commits intoedgexfoundry:mainfrom
chr1shung:issue-4076
Oct 3, 2022
Merged

feat(command): publish device service response to external MQTT#4166
cloudxxx8 merged 3 commits intoedgexfoundry:mainfrom
chr1shung:issue-4076

Conversation

@chr1shung
Copy link
Copy Markdown

fix #4076

If your build fails due to your commit message not passing the build checks, please review the guidelines here: https://github.com/edgexfoundry/edgex-go/blob/main/.github/Contributing.md

PR Checklist

Please check if your PR fulfills the following requirements:

  • I am not introducing a breaking change (if you are, flag in conventional commit message with BREAKING CHANGE: describing the break)
  • I am not introducing a new dependency (add notes below if you are)
  • I have added unit tests for the new feature or bug fix (if not, why?)
  • I have fully tested (add details below) this the new feature or bug fix (if not, why?)
  • I have opened a PR for the related docs change (if not, why?)

Testing Instructions

  1. Run core-command from this branch with external MQTT broker and MESSAGEQUEUE_REQUIRED=true environment variable
  2. Run device-simple from device-sdk-go
  3. Send command request to edgex/command/request/<device-name>/<command-name>/<method> topic. For example send following request to edgex/command/Simple-Device01/Xrotation/get:
{
  "CorrelationID": "14a42ea6-c394-41c3-8bcd-a29b9f5e6835",
  "ApiVersion": "v2",
  "RequestId": "e6e8a2f4-eb14-4649-9e2b-175247911369",
  "ContentType": "application/json",
  "QueryParams": {
    "ds-pushevent": "no",
    "ds-returnevent": "yes"
  },
}
  1. check the response is received on edgex/command/response/<device-name>/<command-name>/<method> topic:
{"ReceivedTopic":"edgex/command/response/device-simple/Simple-Device01/Xrotation/get","CorrelationID":"14a42ea6-c394-41c3-8bcd-a29b9f5e6835","ApiVersion":"v2","RequestID":"e6e8a2f4-eb14-4649-9e2b-175247911369","ErrorCode":0,"Payload":"eyJhcGlWZXJzaW9uIjoidjIiLCJzdGF0dXNDb2RlIjoyMDAsImV2ZW50Ijp7ImFwaVZlcnNpb24iOiJ2MiIsImlkIjoiZDVhMDA2YjYtYmY4OS00ZDQ4LWEyOWUtMTFhYzRlMzJjZWY3IiwiZGV2aWNlTmFtZSI6IlNpbXBsZS1EZXZpY2UwMSIsInByb2ZpbGVOYW1lIjoiU2ltcGxlLURldmljZSIsInNvdXJjZU5hbWUiOiJYcm90YXRpb24iLCJvcmlnaW4iOjE2NjM5MDgzMDQ1Mjk4OTEwMDAsInJlYWRpbmdzIjpbeyJpZCI6IjgwMTExNWI3LWEyZTEtNDE2Ny1iNzVmLWRkMjg1ODY2YjZlNiIsIm9yaWdpbiI6MTY2MzkwODMwNDUyOTg5MTAwMCwiZGV2aWNlTmFtZSI6IlNpbXBsZS1EZXZpY2UwMSIsInJlc291cmNlTmFtZSI6Ilhyb3RhdGlvbiIsInByb2ZpbGVOYW1lIjoiU2ltcGxlLURldmljZSIsInZhbHVlVHlwZSI6IkludDMyIiwidW5pdHMiOiJycG0iLCJ2YWx1ZSI6IjIwIn1dfX0=","ContentType":"application/json","QueryParams":{}}

New Dependency Instructions (If applicable)

Signed-off-by: Chris Hung <chris@iotechsys.com>
Copy link
Copy Markdown
Member

@lenny-goodell lenny-goodell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just small name tweak for clarification

Comment thread internal/core/command/controller/messaging/internal.go Outdated
subscribe to device command response from device service via internal
message bus and publish response back to 3rd-party requester

Signed-off-by: Chris Hung <chris@iotechsys.com>
Comment thread internal/core/command/controller/messaging/internal.go Outdated
@chr1shung chr1shung requested review from cloudxxx8 and lenny-goodell and removed request for cloudxxx8 and lenny-goodell September 28, 2022 05:12
Comment thread internal/core/command/controller/messaging/external.go Outdated
Comment thread internal/core/command/controller/messaging/external_test.go Outdated
Comment thread internal/core/command/controller/messaging/external_test.go Outdated
Comment thread internal/core/command/controller/messaging/router.go Outdated
Set(string, string)
}

func NewMessagingRouter() MessagingRouter {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this Router determining which bus the response message goes to?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad I forgot the most cirtical problem ...

A quick thought came to my mind is to maintain 2 maps internally :

func (r *MessagingRouter) Get(id string) (string, bool) {
    topic, ok := r.ExternalMap[id]
    if ok {
        return topic, true
    }

    topic, _ = r.InternalMap[id]
    return topic, false
}

func (r *MessagingRouter) Set(id string, topic string, source string) {
    switch source {
    case "internal":
        r.InternalMap[id] = topic
    case "external":
        r.ExternalMap[id] = topic
    }
}

Will try to improve it or find if there's better solution tomorrow ...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that was what I had in mind.

Comment thread internal/core/command/main.go Outdated
Comment thread internal/core/command/controller/messaging/internal.go Outdated
lenny-goodell
lenny-goodell previously approved these changes Sep 29, 2022
Copy link
Copy Markdown
Member

@lenny-goodell lenny-goodell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread internal/core/command/controller/messaging/internal.go
Comment thread internal/core/command/controller/messaging/router.go
Save active requests in two maps using requestId as keys.
This allows command service to know where to route the response
(to external MQTT or internal MessageBus)

Signed-off-by: Chris Hung <chris@iotechsys.com>
@sonarqubecloud
Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

Copy link
Copy Markdown
Member

@cloudxxx8 cloudxxx8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cloudxxx8 cloudxxx8 merged commit 1845739 into edgexfoundry:main Oct 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Core command subscribes to device service responses and publishes responses to 3rd party requester via messaging

3 participants