Repository: edgexfoundry/device-sdk-go
Pull request #1684 (2025-02-04 09:55:34)

feat: Update to use go-mod-messaging new message envelope
relate: https://github.com/edgexfoundry/go-mod-messaging/issues/381

<!-- Expected Commit Message Description (imported automatically by GitHub) -->
<!-- Must conform to [conventional commits guidelines](https://github.com/edgexfoundry/device-sdk-go/blob/main/.github/Contributing.md) -->
<!-- Expected Commit message must contain Closes/Fixes #IssueNumber statement when there is a related issue -->

<!-- Add additional detailed description of need for change if no related issue -->

**If your build fails** due to your commit message not passing the build checks, please review the guidelines here: https://github.com/edgexfoundry/device-sdk-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)
- [x] I am not introducing a new dependency (add notes below if you are)
- [x] 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?)
  <link to docs PR>

## Testing Instructions
<!-- How can the reviewers test your change? -->

## New Dependency Instructions (If applicable)
<!-- Please follow [vetting instructions](https://wiki.edgexfoundry.org/display/FA/Vetting+Process+for+3rd+Party+Dependencies) and place results here -->

codecov-commenter: :warning: Please install the !['codecov app svg image'](https://github.com/codecov/engineering-team/assets/152432831/e90313f4-9d3a-4b63-8b54-cfe14e7ec20d) to ensure uploads and comments are reliably processed by Codecov.

## [Codecov](https://app.codecov.io/gh/edgexfoundry/device-sdk-go/pull/1684?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=edgexfoundry) Report
Attention: Patch coverage is `25.00000%` with `3 lines` in your changes missing coverage. Please review.
> Project coverage is 32.22%. Comparing base [(`9af0642`)](https://app.codecov.io/gh/edgexfoundry/device-sdk-go/commit/9af0642e0454afe5e7d0bd4928537ff3f2da2e70?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=edgexfoundry) to head [(`ec81ec3`)](https://app.codecov.io/gh/edgexfoundry/device-sdk-go/commit/ec81ec31b0efc21b0613f01b7051873941b9b756?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=edgexfoundry).

| [Files with missing lines](https://app.codecov.io/gh/edgexfoundry/device-sdk-go/pull/1684?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=edgexfoundry) | Patch % | Lines |
|---|---|---|
| [internal/controller/messaging/callback.go](https://app.codecov.io/gh/edgexfoundry/device-sdk-go/pull/1684?src=pr&el=tree&filepath=internal%2Fcontroller%2Fmessaging%2Fcallback.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=edgexfoundry#diff-aW50ZXJuYWwvY29udHJvbGxlci9tZXNzYWdpbmcvY2FsbGJhY2suZ28=) | 0.00% | [1 Missing :warning: ](https://app.codecov.io/gh/edgexfoundry/device-sdk-go/pull/1684?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=edgexfoundry) |
| [internal/controller/messaging/command.go](https://app.codecov.io/gh/edgexfoundry/device-sdk-go/pull/1684?src=pr&el=tree&filepath=internal%2Fcontroller%2Fmessaging%2Fcommand.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=edgexfoundry#diff-aW50ZXJuYWwvY29udHJvbGxlci9tZXNzYWdpbmcvY29tbWFuZC5nbw==) | 0.00% | [1 Missing :warning: ](https://app.codecov.io/gh/edgexfoundry/device-sdk-go/pull/1684?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=edgexfoundry) |
| [internal/utils/notify.go](https://app.codecov.io/gh/edgexfoundry/device-sdk-go/pull/1684?src=pr&el=tree&filepath=internal%2Futils%2Fnotify.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=edgexfoundry#diff-aW50ZXJuYWwvdXRpbHMvbm90aWZ5Lmdv) | 0.00% | [1 Missing :warning: ](https://app.codecov.io/gh/edgexfoundry/device-sdk-go/pull/1684?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=edgexfoundry) |

:exclamation: Your organization needs to install the [Codecov GitHub app](https://github.com/apps/codecov/installations/select_target) to enable full functionality.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##             main    #1684      +/-   ##
==========================================
+ Coverage   32.21%   32.22%   +0.01%     
==========================================
  Files          51       51              
  Lines        4914     4912       -2     
==========================================
  Hits         1583     1583              
+ Misses       3191     3189       -2     
  Partials      140      140              
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/edgexfoundry/device-sdk-go/pull/1684?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=edgexfoundry).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=edgexfoundry).


Patch:
diff --git a/go.mod b/go.mod
index c4082850..52ec5bec 100644
--- a/go.mod
+++ b/go.mod
@@ -4,9 +4,9 @@ go 1.23
 
 require (
 	github.com/OneOfOne/xxhash v1.2.8
-	github.com/edgexfoundry/go-mod-bootstrap/v4 v4.0.0-dev.20
-	github.com/edgexfoundry/go-mod-core-contracts/v4 v4.0.0-dev.22
-	github.com/edgexfoundry/go-mod-messaging/v4 v4.0.0-dev.10
+	github.com/edgexfoundry/go-mod-bootstrap/v4 v4.0.0-dev.26
+	github.com/edgexfoundry/go-mod-core-contracts/v4 v4.0.0-dev.23
+	github.com/edgexfoundry/go-mod-messaging/v4 v4.0.0-dev.14
 	github.com/google/uuid v1.6.0
 	github.com/hashicorp/go-multierror v1.1.1
 	github.com/labstack/echo/v4 v4.13.3
@@ -24,7 +24,7 @@ require (
 	github.com/cenkalti/backoff/v4 v4.3.0 // indirect
 	github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
 	github.com/eclipse/paho.mqtt.golang v1.5.0 // indirect
-	github.com/edgexfoundry/go-mod-configuration/v4 v4.0.0-dev.10 // indirect
+	github.com/edgexfoundry/go-mod-configuration/v4 v4.0.0-dev.12 // indirect
 	github.com/edgexfoundry/go-mod-registry/v4 v4.0.0-dev.3 // indirect
 	github.com/edgexfoundry/go-mod-secrets/v4 v4.0.0-dev.5 // indirect
 	github.com/fsnotify/fsnotify v1.7.0 // indirect
@@ -50,9 +50,8 @@ require (
 	github.com/go-playground/locales v0.14.1 // indirect
 	github.com/go-playground/universal-translator v0.18.1 // indirect
 	github.com/go-playground/validator/v10 v10.24.0 // indirect
-	github.com/go-resty/resty/v2 v2.15.3 // indirect
+	github.com/go-resty/resty/v2 v2.16.4 // indirect
 	github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
-	github.com/golang/protobuf v1.5.4 // indirect
 	github.com/gorilla/mux v1.8.1 // indirect
 	github.com/gorilla/schema v1.4.1 // indirect
 	github.com/gorilla/securecookie v1.1.2 // indirect
@@ -65,7 +64,7 @@ require (
 	github.com/leodido/go-urn v1.4.0 // indirect
 	github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
 	github.com/mailru/easyjson v0.7.7 // indirect
-	github.com/mattn/go-colorable v0.1.13 // indirect
+	github.com/mattn/go-colorable v0.1.14 // indirect
 	github.com/mattn/go-isatty v0.0.20 // indirect
 	github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
 	github.com/michaelquigley/pfxlog v0.6.10 // indirect
@@ -80,14 +79,14 @@ require (
 	github.com/nats-io/nuid v1.0.1 // indirect
 	github.com/oklog/ulid v1.3.1 // indirect
 	github.com/opentracing/opentracing-go v1.2.0 // indirect
-	github.com/openziti/channel/v3 v3.0.26 // indirect
-	github.com/openziti/edge-api v0.26.36 // indirect
+	github.com/openziti/channel/v3 v3.0.27 // indirect
+	github.com/openziti/edge-api v0.26.38 // indirect
 	github.com/openziti/foundation/v2 v2.0.56 // indirect
 	github.com/openziti/identity v1.0.94 // indirect
 	github.com/openziti/metrics v1.2.65 // indirect
-	github.com/openziti/sdk-golang v0.23.45 // indirect
+	github.com/openziti/sdk-golang v0.24.1 // indirect
 	github.com/openziti/secretstream v0.1.28 // indirect
-	github.com/openziti/transport/v2 v2.0.159 // indirect
+	github.com/openziti/transport/v2 v2.0.160 // indirect
 	github.com/orcaman/concurrent-map/v2 v2.0.1 // indirect
 	github.com/parallaxsecond/parsec-client-go v0.0.0-20221025095442-f0a77d263cf9 // indirect
 	github.com/pkg/errors v0.9.1 // indirect
@@ -114,7 +113,7 @@ require (
 	go.opentelemetry.io/otel/trace v1.29.0 // indirect
 	golang.org/x/crypto v0.32.0 // indirect
 	golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 // indirect
-	golang.org/x/oauth2 v0.23.0 // indirect
+	golang.org/x/oauth2 v0.25.0 // indirect
 	golang.org/x/sync v0.10.0 // indirect
 	golang.org/x/sys v0.29.0 // indirect
 	golang.org/x/term v0.28.0 // indirect
@@ -122,7 +121,7 @@ require (
 	golang.org/x/time v0.8.0 // indirect
 	google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect
 	google.golang.org/grpc v1.67.1 // indirect
-	google.golang.org/protobuf v1.36.2 // indirect
+	google.golang.org/protobuf v1.36.3 // indirect
 	gopkg.in/go-jose/go-jose.v2 v2.6.3 // indirect
 	nhooyr.io/websocket v1.8.17 // indirect
 )
diff --git a/go.sum b/go.sum
index a6977467..976c3663 100644
--- a/go.sum
+++ b/go.sum
@@ -70,14 +70,14 @@ 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.5.0 h1:EH+bUVJNgttidWFkLLVKaQPGmkTUfQQqjOsyvMGvD6o=
 github.com/eclipse/paho.mqtt.golang v1.5.0/go.mod h1:du/2qNQVqJf/Sqs4MEL77kR8QTqANF7XU7Fk0aOTAgk=
-github.com/edgexfoundry/go-mod-bootstrap/v4 v4.0.0-dev.20 h1:nijx+kCDRIFOBuWcPtGMoxNwmjF5U6Cacun6z85fh+Q=
-github.com/edgexfoundry/go-mod-bootstrap/v4 v4.0.0-dev.20/go.mod h1:OBvLqNUh/8TzbTLVmlBDDI/MSXV2N3pNuJNlPs2LIWc=
-github.com/edgexfoundry/go-mod-configuration/v4 v4.0.0-dev.10 h1:DMv5LZDxcqUeb1dREMd/vK+reXmZYlpafgtm8XhYdHQ=
-github.com/edgexfoundry/go-mod-configuration/v4 v4.0.0-dev.10/go.mod h1:ltUpMcOpJSzmabBtZox5qg1AK2wEikvZJyIBXtJ7mUQ=
-github.com/edgexfoundry/go-mod-core-contracts/v4 v4.0.0-dev.22 h1:XzDtbAmvp/v+DZlFoSgttnUQsIXGhlf+H8xgGxBClUA=
-github.com/edgexfoundry/go-mod-core-contracts/v4 v4.0.0-dev.22/go.mod h1:D35HIMZkFFy82shKtPYaEL3Nn+ZNEjUjZI1RLn1j23E=
-github.com/edgexfoundry/go-mod-messaging/v4 v4.0.0-dev.10 h1:xvDQDIJtmj/ZCmKzbAzg3h1F2ZdWz1MPoJSNfYZANGc=
-github.com/edgexfoundry/go-mod-messaging/v4 v4.0.0-dev.10/go.mod h1:ibaiw7r3RgLYDuuFfWT1kh//bjP+onDOOQsnSsdD4E8=
+github.com/edgexfoundry/go-mod-bootstrap/v4 v4.0.0-dev.26 h1:59f5u/cEj/P2Dd0BDqD0i2hBirODpvO9+hV6NdlxhUw=
+github.com/edgexfoundry/go-mod-bootstrap/v4 v4.0.0-dev.26/go.mod h1:o6qcqfq0ihA8RYs7FZldrslEeMIXK6XiHJg0fxF7GRA=
+github.com/edgexfoundry/go-mod-configuration/v4 v4.0.0-dev.12 h1:2P7kCcGMd5BX9NFubHxfZ+Q19Q0ctMwh11rgSyPT5uc=
+github.com/edgexfoundry/go-mod-configuration/v4 v4.0.0-dev.12/go.mod h1:sx5Zx+zAhmlFRNK2EblvOnCuUc099F2mHLWtZGfoWB8=
+github.com/edgexfoundry/go-mod-core-contracts/v4 v4.0.0-dev.23 h1:/EA6knujjIr7Js/l8YxEcTFM3RFcWL+GDGaqjE66vUU=
+github.com/edgexfoundry/go-mod-core-contracts/v4 v4.0.0-dev.23/go.mod h1:D35HIMZkFFy82shKtPYaEL3Nn+ZNEjUjZI1RLn1j23E=
+github.com/edgexfoundry/go-mod-messaging/v4 v4.0.0-dev.14 h1:5AtY1UzgwpKUAI5k48KsOb52SdfY7prTSQDHagh//+U=
+github.com/edgexfoundry/go-mod-messaging/v4 v4.0.0-dev.14/go.mod h1:XEtpg3VhYz3DnGNweOlaX9DOFjH388xA5gxEQqra80I=
 github.com/edgexfoundry/go-mod-registry/v4 v4.0.0-dev.3 h1:6tw6JqEJDOqo2lEgxjZ+scvsub5R20WGpInCuoxS6zE=
 github.com/edgexfoundry/go-mod-registry/v4 v4.0.0-dev.3/go.mod h1:QpZW5bWxsk0Leh1nvgojBZrpHA/B6dSw6LgT0zxh9hg=
 github.com/edgexfoundry/go-mod-secrets/v4 v4.0.0-dev.5 h1:PnbvMnedIlbqXsnUp2+i18BJ9e6CJ7GzwNA9vjPU3Jk=
@@ -149,8 +149,8 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn
 github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
 github.com/go-playground/validator/v10 v10.24.0 h1:KHQckvo8G6hlWnrPX4NJJ+aBfWNAE/HH+qdL2cBpCmg=
 github.com/go-playground/validator/v10 v10.24.0/go.mod h1:GGzBIJMuE98Ic/kJsBXbz1x/7cByt++cQ+YOuDM5wus=
-github.com/go-resty/resty/v2 v2.15.3 h1:bqff+hcqAflpiF591hhJzNdkRsFhlB96CYfBwSFvql8=
-github.com/go-resty/resty/v2 v2.15.3/go.mod h1:0fHAoK7JoBy/Ch36N8VFeMsK7xQOHhvWaC3iOktwmIU=
+github.com/go-resty/resty/v2 v2.16.4 h1:81IjtszQKwbz7dot4LLYGwhJNUsNwECD2O7nru5q60E=
+github.com/go-resty/resty/v2 v2.16.4/go.mod h1:hkJtXbA2iKHzJheXYvQ8snQES5ZLGKMwQ07xAwp/fiA=
 github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
 github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
 github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=
@@ -184,8 +184,6 @@ github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw
 github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
 github.com/golang/protobuf v1.5.1/go.mod h1:DopwsBzvsk0Fs44TXzsVbJyPhcCPeIwnvohx4u74HPM=
 github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
-github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
-github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
 github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
 github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
 github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
@@ -298,12 +296,11 @@ github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0
 github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
 github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
 github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
-github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
-github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
+github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
+github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
 github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
 github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
 github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
-github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
 github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
 github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
 github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
@@ -361,22 +358,22 @@ github.com/onsi/gomega v1.13.0 h1:7lLHu94wT9Ij0o6EWWclhu0aOh32VxhkwEJvzuWPeak=
 github.com/onsi/gomega v1.13.0/go.mod h1:lRk9szgn8TxENtWd0Tp4c3wjlRfMTMH27I+3Je41yGY=
 github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs=
 github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
-github.com/openziti/channel/v3 v3.0.26 h1:KVMOpqA8teIUcjG8u21pg8iI1YOjaY/SQyWWozWfXpA=
-github.com/openziti/channel/v3 v3.0.26/go.mod h1:o5/tWvfHgEzVBqdl8WBHFJNc7m8zHcCb3S5ymocDZEk=
-github.com/openziti/edge-api v0.26.36 h1:zy2DjmIz/B+WxPpIzhFOAxi/LhM/yeKa8s1Vz2h8cQk=
-github.com/openziti/edge-api v0.26.36/go.mod h1:sYHVpm26Jr1u7VooNJzTb2b2nGSlmCHMnbGC8XfWSng=
+github.com/openziti/channel/v3 v3.0.27 h1:Jx56fuxuvlkap+zNXIDPdfLW1mA6GjrnCxjbDqdBgco=
+github.com/openziti/channel/v3 v3.0.27/go.mod h1:vmLGw7KS1mhFDBoYal7O4dIcsm6TAVi9WqjI4TvAemQ=
+github.com/openziti/edge-api v0.26.38 h1:3xDWC5SFn3qUVR428TIBpRc2lrjVV7Gz0Rx4pQx0JSg=
+github.com/openziti/edge-api v0.26.38/go.mod h1:sYHVpm26Jr1u7VooNJzTb2b2nGSlmCHMnbGC8XfWSng=
 github.com/openziti/foundation/v2 v2.0.56 h1:YXqBmkrN0fYr3TqIlWZSZGluE2QpJxlA29Z6okZyQ5I=
 github.com/openziti/foundation/v2 v2.0.56/go.mod h1:f12R1pwEod348qONZr6esZgackX1ScLGDcEyPF2G5/w=
 github.com/openziti/identity v1.0.94 h1:nF4etu/5LmOlbT24lpSKq9p+90A9jeyLr5U23LemgD4=
 github.com/openziti/identity v1.0.94/go.mod h1:3VGYqa9E26zPPA8lJwE7eUPvRH2Oz8ZAd46cUCWKz/M=
 github.com/openziti/metrics v1.2.65 h1:Jhhbds+BUbywfspxcb9oyz9p9LI/oERT9lbeDpnNpmY=
 github.com/openziti/metrics v1.2.65/go.mod h1:GJObRZX05cxCs23mrsEA9fT9Vk5pbXA6/FkUaslVi8k=
-github.com/openziti/sdk-golang v0.23.45 h1:6rH1GxKUs71lhMc2MXC2tralimi+YD6cpi0ojSr9YCg=
-github.com/openziti/sdk-golang v0.23.45/go.mod h1:anMPCyFB1i25ZiOG8zepx6rNjNvUQk/jTtWSKIOq9uc=
+github.com/openziti/sdk-golang v0.24.1 h1:5b3BFRspkHWq0UAMQz4J4QbXDDIdWTRy7stqMhmlEJk=
+github.com/openziti/sdk-golang v0.24.1/go.mod h1:aYijpXHfoc6r5hFDl5lu3WV9ZTLg97QBhUdhI9c9kOo=
 github.com/openziti/secretstream v0.1.28 h1:D+a5TcvbY3i7HOIecoTL0Pq8HJGnJqS0XmUyO1ohObg=
 github.com/openziti/secretstream v0.1.28/go.mod h1:BESAWnpyIr9A+ditH4vk15ZVsnP8zdy6vGi8Qr1lgAg=
-github.com/openziti/transport/v2 v2.0.159 h1:Ol6vTrXWJdkfRLWYI2hjDTeH2Ji0cYC26UuPnBylALg=
-github.com/openziti/transport/v2 v2.0.159/go.mod h1:Hw4TIlDd97D5m8BrlxTZ3bqO01+hwddTDMSOOzz/4cs=
+github.com/openziti/transport/v2 v2.0.160 h1:bYBBj8gqZ8DCF6aCJThq2v89h5ILwqTVaFkyfjFmHpk=
+github.com/openziti/transport/v2 v2.0.160/go.mod h1:Hw4TIlDd97D5m8BrlxTZ3bqO01+hwddTDMSOOzz/4cs=
 github.com/orcaman/concurrent-map/v2 v2.0.1 h1:jOJ5Pg2w1oeB6PeDurIYf6k9PQ+aTITr/6lP/L/zp6c=
 github.com/orcaman/concurrent-map/v2 v2.0.1/go.mod h1:9Eq3TG2oBe5FirmYWQfYO5iH1q0Jv47PLaNK++uCdOM=
 github.com/panjf2000/ants/v2 v2.11.0 h1:sHrqEwTBQTQ2w6PMvbMfvBtVUuhsaYPzUmAYDLYmJPg=
@@ -594,8 +591,8 @@ golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ
 golang.org/x/oauth2 v0.0.0-20210220000619-9bb904979d93/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
 golang.org/x/oauth2 v0.0.0-20210313182246-cd4f82c27b84/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
 golang.org/x/oauth2 v0.0.0-20210402161424-2e8d93401602/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
-golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs=
-golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
+golang.org/x/oauth2 v0.25.0 h1:CY4y7XT9v0cRI9oupztF8AgiIu99L/ksR/Xp/6jrZ70=
+golang.org/x/oauth2 v0.25.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
 golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -663,7 +660,6 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
 golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
@@ -854,8 +850,8 @@ google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGj
 google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
 google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
 google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
-google.golang.org/protobuf v1.36.2 h1:R8FeyR1/eLmkutZOM5CWghmo5itiG9z0ktFlTVLuTmU=
-google.golang.org/protobuf v1.36.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
+google.golang.org/protobuf v1.36.3 h1:82DV7MYdb8anAVi3qge1wSnMDrnKK7ebr+I0hHRN1BU=
+google.golang.org/protobuf v1.36.3/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
 gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
 gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
diff --git a/internal/common/utils.go b/internal/common/utils.go
index 381e97a1..24517b38 100644
--- a/internal/common/utils.go
+++ b/internal/common/utils.go
@@ -1,7 +1,7 @@
 // -*- Mode: Go; indent-tabs-mode: t -*-
 //
 // Copyright (C) 2017-2018 Canonical Ltd
-// Copyright (C) 2018-2023 IOTech Ltd
+// Copyright (C) 2018-2025 IOTech Ltd
 //
 // SPDX-License-Identifier: Apache-2.0
 
@@ -54,27 +54,17 @@ func SendEvent(event *dtos.Event, correlationID string, dic *di.Container) {
 	configuration := container.ConfigurationFrom(dic.Get)
 	ctx := context.WithValue(context.Background(), common.CorrelationHeader, correlationID) // nolint: staticcheck
 	req := requests.NewAddEventRequest(*event)
-
-	bytes, encoding, err := req.Encode()
-	if err != nil {
-		lc.Error(err.Error())
-	}
-
-	// Check event size in kilobytes
-	if configuration.MaxEventSize > 0 && int64(len(bytes)) > configuration.MaxEventSize*1024 {
-		lc.Errorf("event size exceed MaxEventSize(%d KB)", configuration.MaxEventSize)
-		return
-	}
+	encoding := req.GetEncodingContentType()
+	ctx = context.WithValue(ctx, common.ContentType, encoding) // nolint: staticcheck
+	envelope := types.NewMessageEnvelope(req, ctx)
 
 	sent := false
 	mc := bootstrapContainer.MessagingClientFrom(dic.Get)
-	ctx = context.WithValue(ctx, common.ContentType, encoding) // nolint: staticcheck
-	envelope := types.NewMessageEnvelope(bytes, ctx)
 	serviceName := container.DeviceServiceFrom(dic.Get).Name
 	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)
+	err := mc.PublishWithSizeLimit(envelope, publishTopic, configuration.MaxEventSize)
 	if err != nil {
 		lc.Errorf("Failed to publish event to MessageBus: %s", err)
 		return
@@ -83,7 +73,7 @@ func SendEvent(event *dtos.Event, correlationID string, dic *di.Container) {
 		event.ProfileName, event.DeviceName, event.SourceName, event.Id, publishTopic)
 	sent = true
 
-	if sent {
+	if sent && eventsSent != nil && readingsSent != nil {
 		eventsSent.Inc(1)
 		readingsSent.Inc(int64(len(event.Readings)))
 	}
diff --git a/internal/controller/messaging/callback.go b/internal/controller/messaging/callback.go
index 61e4bf64..e07ff426 100644
--- a/internal/controller/messaging/callback.go
+++ b/internal/controller/messaging/callback.go
@@ -1,5 +1,5 @@
 //
-// Copyright (C) 2023 IOTech Ltd
+// Copyright (C) 2023-2025 IOTech Ltd
 //
 // SPDX-License-Identifier: Apache-2.0
 
@@ -7,7 +7,6 @@ package messaging
 
 import (
 	"context"
-	"encoding/json"
 	"fmt"
 	"strings"
 
@@ -85,7 +84,7 @@ func MetadataSystemEventsCallback(ctx context.Context, serviceBaseName string, d
 				lc.Debugf("System event received on message queue. Topic: %s, Correlation-id: %s", msgEnvelope.ReceivedTopic, msgEnvelope.CorrelationID)
 
 				var systemEvent dtos.SystemEvent
-				err := json.Unmarshal(msgEnvelope.Payload, &systemEvent)
+				systemEvent, err := types.GetMsgPayload[dtos.SystemEvent](msgEnvelope)
 				if err != nil {
 					lc.Errorf("failed to JSON decoding system event: %s", err.Error())
 					continue
diff --git a/internal/controller/messaging/command.go b/internal/controller/messaging/command.go
index 13d7891e..7f2200b5 100644
--- a/internal/controller/messaging/command.go
+++ b/internal/controller/messaging/command.go
@@ -1,5 +1,5 @@
 //
-// Copyright (C) 2022-2023 IOTech Ltd
+// Copyright (C) 2022-2025 IOTech Ltd
 //
 // SPDX-License-Identifier: Apache-2.0
 
@@ -7,7 +7,6 @@ package messaging
 
 import (
 	"context"
-	"encoding/json"
 	"fmt"
 	"net/http"
 	"net/url"
@@ -128,25 +127,16 @@ func getCommand(ctx context.Context, msgEnvelope types.MessageEnvelope, response
 
 	var err error
 	var encoding string
-	var eventResponseBytes []byte
+	var eventResponse any
 	if reserved[common.ReturnEvent] {
-		eventResponse := responses.NewEventResponse(msgEnvelope.RequestID, "", http.StatusOK, *event)
-		eventResponseBytes, encoding, err = eventResponse.Encode()
-		if err != nil {
-			lc.Errorf("Failed to encode event response: %s", err.Error())
-			responseEnvelope = types.NewMessageEnvelopeWithError(msgEnvelope.RequestID, err.Error())
-			err = messageBus.Publish(responseEnvelope, responseTopic)
-			if err != nil {
-				lc.Errorf("Failed to publish command error response: %s", err.Error())
-			}
-			return
-		}
+		resp := responses.NewEventResponse(msgEnvelope.RequestID, "", http.StatusOK, *event)
+		encoding = resp.GetEncodingContentType()
+		eventResponse = resp
 	} else {
-		eventResponseBytes = nil
 		encoding = common.ContentTypeJSON
 	}
 
-	responseEnvelope, err = types.NewMessageEnvelopeForResponse(eventResponseBytes, msgEnvelope.RequestID, msgEnvelope.CorrelationID, encoding)
+	responseEnvelope, err = types.NewMessageEnvelopeForResponse(eventResponse, msgEnvelope.RequestID, msgEnvelope.CorrelationID, encoding)
 	if err != nil {
 		lc.Errorf("Failed to create response message envelope: %s", err.Error())
 		responseEnvelope = types.NewMessageEnvelopeWithError(msgEnvelope.RequestID, err.Error())
@@ -157,9 +147,15 @@ func getCommand(ctx context.Context, msgEnvelope types.MessageEnvelope, response
 		return
 	}
 
-	err = messageBus.Publish(responseEnvelope, responseTopic)
+	configuration := container.ConfigurationFrom(dic.Get)
+	err = messageBus.PublishWithSizeLimit(responseEnvelope, responseTopic, configuration.MaxEventSize)
 	if err != nil {
 		lc.Errorf("Failed to publish command response: %s", err.Error())
+		responseEnvelope = types.NewMessageEnvelopeWithError(msgEnvelope.RequestID, err.Error())
+		err = messageBus.Publish(responseEnvelope, responseTopic)
+		if err != nil {
+			lc.Errorf("Failed to publish command error response: %s", err.Error())
+		}
 		return
 	}
 
@@ -175,9 +171,7 @@ func setCommand(ctx context.Context, msgEnvelope types.MessageEnvelope, response
 	lc := bootstrapContainer.LoggingClientFrom(dic.Get)
 	messageBus := bootstrapContainer.MessagingClientFrom(dic.Get)
 	rawQuery, _ := filterQueryParams(msgEnvelope.QueryParams)
-
-	requestPayload := make(map[string]any)
-	err := json.Unmarshal(msgEnvelope.Payload, &requestPayload)
+	requestPayload, err := types.GetMsgPayload[map[string]any](msgEnvelope)
 	if err != nil {
 		lc.Errorf("Failed to decode set command request payload: %s", err.Error())
 		responseEnvelope = types.NewMessageEnvelopeWithError(msgEnvelope.RequestID, err.Error())
diff --git a/internal/controller/messaging/validation.go b/internal/controller/messaging/validation.go
index 627dab15..5b9a4316 100644
--- a/internal/controller/messaging/validation.go
+++ b/internal/controller/messaging/validation.go
@@ -1,5 +1,5 @@
 //
-// Copyright (C) 2023 IOTech Ltd
+// Copyright (C) 2023-2025 IOTech Ltd
 //
 // SPDX-License-Identifier: Apache-2.0
 
@@ -7,7 +7,6 @@ package messaging
 
 import (
 	"context"
-	"encoding/json"
 
 	bootstrapContainer "github.com/edgexfoundry/go-mod-bootstrap/v4/bootstrap/container"
 	"github.com/edgexfoundry/go-mod-bootstrap/v4/di"
@@ -65,7 +64,7 @@ func SubscribeDeviceValidation(ctx context.Context, dic *di.Container) errors.Ed
 				driver := container.ProtocolDriverFrom(dic.Get)
 
 				var deviceRequest requests.AddDeviceRequest
-				err = json.Unmarshal(msgEnvelope.Payload, &deviceRequest)
+				deviceRequest, err = types.GetMsgPayload[requests.AddDeviceRequest](msgEnvelope)
 				if err != nil {
 					lc.Errorf("Failed to JSON decoding AddDeviceRequest: %s", err.Error())
 					res := types.NewMessageEnvelopeWithError(msgEnvelope.RequestID, err.Error())
diff --git a/internal/utils/notify.go b/internal/utils/notify.go
index d4f1238b..967c94f2 100644
--- a/internal/utils/notify.go
+++ b/internal/utils/notify.go
@@ -1,5 +1,5 @@
 //
-// Copyright (C) 2024 IOTech Ltd
+// Copyright (C) 2024-2025 IOTech Ltd
 //
 // SPDX-License-Identifier: Apache-2.0
 
@@ -7,7 +7,6 @@ package utils
 
 import (
 	"context"
-	"encoding/json"
 
 	"github.com/edgexfoundry/device-sdk-go/v4/internal/container"
 	sdkModels "github.com/edgexfoundry/device-sdk-go/v4/pkg/models"
@@ -46,8 +45,7 @@ func PublishGenericSystemEvent(eventType, action string, details any, ctx contex
 	topicPathBuilder := common.NewPathBuilder().EnableNameFieldEscape(config.Service.EnableNameFieldEscape)
 	publishTopic := topicPathBuilder.SetPath(config.MessageBus.GetBaseTopicPrefix()).SetPath(common.SystemEventPublishTopic).
 		SetPath(systemEvent.Source).SetPath(systemEvent.Type).SetPath(systemEvent.Action).SetNameFieldPath(systemEvent.Owner).BuildPath()
-	payload, _ := json.Marshal(systemEvent)
-	envelope := types.NewMessageEnvelope(payload, ctx)
+	envelope := types.NewMessageEnvelope(systemEvent, ctx)
 	// Correlation ID and Content type are set by the above factory function from the context of the request that
 	// triggered this System Event. We'll keep that Correlation ID, but need to make sure the Content Type is set appropriate
 	// for how the payload was encoded above.


Test patch:
diff --git a/internal/common/utils_test.go b/internal/common/utils_test.go
index 81ec64e9..9353388a 100644
--- a/internal/common/utils_test.go
+++ b/internal/common/utils_test.go
@@ -173,7 +173,9 @@ func TestSendEvent(t *testing.T) {
 		t.Run(tt.name, func(t *testing.T) {
 			dic := NewMockDIC()
 			mcMock := &msgMocks.MessageClient{}
-			mcMock.On("Publish", mock.Anything, mock.Anything).Return(nil)
+			mcMock.On("PublishWithSizeLimit", mock.Anything, mock.Anything, int64(0)).Return(nil)
+			mcMock.On("PublishWithSizeLimit", mock.Anything, mock.Anything, int64(eventSize+1)).Return(nil)
+			mcMock.On("PublishWithSizeLimit", mock.Anything, mock.Anything, int64(eventSize-1)).Return(errors.New("message size exceed limit"))
 
 			dic.Update(di.ServiceConstructorMap{
 				container.ConfigurationName: func(get di.Get) interface{} {
@@ -189,12 +191,11 @@ func TestSendEvent(t *testing.T) {
 			InitializeSentMetrics(logger.NewMockClient(), dic)
 
 			SendEvent(tt.event, testUUIDString, dic)
+			mcMock.AssertNumberOfCalls(t, "PublishWithSizeLimit", 1)
 			if tt.eventTooLarge {
-				mcMock.AssertNumberOfCalls(t, "Publish", 0)
 				assert.Equal(t, int64(0), eventsSent.Count())
 				assert.Equal(t, int64(0), readingsSent.Count())
 			} else {
-				mcMock.AssertNumberOfCalls(t, "Publish", 1)
 				assert.Equal(t, int64(1), eventsSent.Count())
 				assert.Equal(t, int64(1), readingsSent.Count())
 			}
diff --git a/internal/controller/http/command_test.go b/internal/controller/http/command_test.go
index 89b0b330..2d425cbc 100644
--- a/internal/controller/http/command_test.go
+++ b/internal/controller/http/command_test.go
@@ -396,7 +396,7 @@ func TestRestController_SetCommand(t *testing.T) {
 				wg.Add(1)
 			}
 			messagingClientMock := &messagingMocks.MessageClient{}
-			messagingClientMock.On("Publish", mock.Anything, mock.Anything).Run(func(args mock.Arguments) {
+			messagingClientMock.On("PublishWithSizeLimit", mock.Anything, mock.Anything, mock.Anything).Run(func(args mock.Arguments) {
 				go func() {
 					defer wg.Done()
 				}()
@@ -428,7 +428,7 @@ func TestRestController_SetCommand(t *testing.T) {
 
 				wg.Wait()
 				if testCase.commandName != writeOnlyCommand && testCase.commandName != writeOnlyResource {
-					messagingClientMock.AssertNumberOfCalls(t, "Publish", 1)
+					messagingClientMock.AssertNumberOfCalls(t, "PublishWithSizeLimit", 1)
 				}
 			} else {
 				assert.NotEmpty(t, res.Message, "Response message doesn't contain the error message")
diff --git a/internal/controller/messaging/validation_test.go b/internal/controller/messaging/validation_test.go
index 0fc3067b..328c04ca 100644
--- a/internal/controller/messaging/validation_test.go
+++ b/internal/controller/messaging/validation_test.go
@@ -1,5 +1,5 @@
 //
-// Copyright (C) 2023 IOTech Ltd
+// Copyright (C) 2023-2025 IOTech Ltd
 //
 // SPDX-License-Identifier: Apache-2.0
 
@@ -9,6 +9,7 @@ import (
 	"context"
 	"encoding/json"
 	"errors"
+	"os"
 	"sync"
 	"testing"
 	"time"
@@ -55,11 +56,13 @@ func TestDeviceValidation(t *testing.T) {
 			testProtocolName: {"key": "value"},
 		},
 	}
+	expectedAddDeviceRequest := requests.NewAddDeviceRequest(expectedDevice)
+	expectedAddDeviceRequestBytes, err := json.Marshal(expectedAddDeviceRequest)
+	require.NoError(t, err)
 	validationFailedDevice := expectedDevice
 	validationFailedDevice.Name = "validationFailedDevice"
-	expectedAddDeviceRequestBytes, err := json.Marshal(requests.NewAddDeviceRequest(expectedDevice))
-	require.NoError(t, err)
-	validationFailedDeviceBytes, err := json.Marshal(requests.NewAddDeviceRequest(validationFailedDevice))
+	validationFailedDeviceRequest := requests.NewAddDeviceRequest(validationFailedDevice)
+	validationFailedDeviceRequestBytes, err := json.Marshal(validationFailedDeviceRequest)
 	require.NoError(t, err)
 
 	mockLogger := &loggerMocks.LoggingClient{}
@@ -88,15 +91,23 @@ func TestDeviceValidation(t *testing.T) {
 
 	tests := []struct {
 		name          string
-		requestBytes  []byte
+		request       any
 		expectedError bool
+		withEnv       bool
 	}{
-		{"valid - device validation succeed", expectedAddDeviceRequestBytes, false},
-		{"valid - device validation failed", validationFailedDeviceBytes, true},
-		{"invalid - message payload is not AddDeviceRequest", []byte("invalid"), true},
+		{"valid with env - device validation succeed", expectedAddDeviceRequestBytes, false, true},
+		{"valid with env - device validation failed", validationFailedDeviceRequestBytes, true, true},
+		{"invalid with env - message payload is not AddDeviceRequest", []byte("invalid"), true, true},
+		{"valid - device validation succeed", expectedAddDeviceRequest, false, false},
+		{"valid - device validation failed", validationFailedDeviceRequest, true, false},
+		{"invalid - message payload is not AddDeviceRequest", []byte("invalid"), true, false},
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
+			if tt.withEnv {
+				_ = os.Setenv("EDGEX_MSG_BASE64_PAYLOAD", common.ValueTrue)
+				defer os.Setenv("EDGEX_MSG_BASE64_PAYLOAD", common.ValueFalse)
+			}
 			mockMessaging := &messagingMocks.MessageClient{}
 			mockMessaging.On("Subscribe", mock.Anything, mock.Anything).Run(func(args mock.Arguments) {
 				topics := args.Get(0).([]types.TopicChannel)
@@ -109,7 +120,8 @@ func TestDeviceValidation(t *testing.T) {
 						RequestID:     expectedRequestId,
 						CorrelationID: expectedCorrelationId,
 						ReceivedTopic: expectedRequestTopic,
-						Payload:       tt.requestBytes,
+						ContentType:   common.ContentTypeJSON,
+						Payload:       tt.request,
 					}
 					time.Sleep(time.Second * 1)
 				}()
@@ -118,14 +130,14 @@ func TestDeviceValidation(t *testing.T) {
 				response := args.Get(0).(types.MessageEnvelope)
 				assert.Equal(t, expectedRequestId, response.RequestID)
 				if tt.expectedError {
-					assert.Equal(t, response.ErrorCode, 1)
+					assert.Equal(t, 1, response.ErrorCode)
 					assert.NotEmpty(t, response.Payload)
-					assert.Equal(t, response.ContentType, common.ContentTypeText)
+					assert.Equal(t, common.ContentTypeText, response.ContentType)
 				} else {
 					assert.Equal(t, expectedCorrelationId, response.CorrelationID)
-					assert.Equal(t, response.ErrorCode, 0)
+					assert.Equal(t, 0, response.ErrorCode)
 					assert.Empty(t, response.Payload)
-					assert.Equal(t, response.ContentType, common.ContentTypeJSON)
+					assert.Equal(t, common.ContentTypeJSON, response.ContentType)
 				}
 			}).Return(nil)