Skip to content

Commit c47232d

Browse files
authored
Merge pull request #962 from jinlinGuan/edgex-go-issue-5007
feat: Add MQTT and ZeroMQ channels support to support-notification
2 parents a17a865 + c48e209 commit c47232d

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

common/constants.go

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ const (
8989
ApiNotificationByCategoryRoute = ApiNotificationRoute + "/" + Category + "/:" + Category
9090
ApiNotificationByLabelRoute = ApiNotificationRoute + "/" + Label + "/:" + Label
9191
ApiNotificationByIdRoute = ApiNotificationRoute + "/" + Id + "/:" + Id
92+
ApiNotificationByIdsRoute = ApiNotificationRoute + "/" + Ids + "/:" + Ids
9293
ApiNotificationByStatusRoute = ApiNotificationRoute + "/" + Status + "/:" + Status
9394
ApiNotificationBySubscriptionNameRoute = ApiNotificationRoute + "/" + Subscription + "/" + Name + "/:" + Name
9495
ApiNotificationAcknowledgeByIdsRoute = ApiNotificationRoute + "/" + Acknowledge + "/" + Ids + "/:" + Ids

dtos/address.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,11 @@ type Security struct {
144144
type ZeroMQAddress struct {
145145
}
146146

147-
func NewZeroMQAddress(topic string) Address {
147+
func NewZeroMQAddress(host string, port int, topic string) Address {
148148
return Address{
149149
Type: common.ZeroMQ,
150+
Host: host,
151+
Port: port,
150152
MessageBus: MessageBus{Topic: topic},
151153
}
152154
}

dtos/requests/subscription.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
//
2-
// Copyright (C) 2020-2021 IOTech Ltd
2+
// Copyright (C) 2020-2024 IOTech Ltd
33
//
44
// SPDX-License-Identifier: Apache-2.0
55

66
package requests
77

88
import (
99
"encoding/json"
10+
"fmt"
1011

1112
"github.com/edgexfoundry/go-mod-core-contracts/v4/common"
1213
"github.com/edgexfoundry/go-mod-core-contracts/v4/dtos"
@@ -15,7 +16,7 @@ import (
1516
"github.com/edgexfoundry/go-mod-core-contracts/v4/models"
1617
)
1718

18-
var supportedChannelTypes = []string{common.EMAIL, common.REST}
19+
var supportedChannelTypes = []string{common.EMAIL, common.REST, common.MQTT, common.ZeroMQ}
1920

2021
// AddSubscriptionRequest defines the Request Content for POST Subscription DTO.
2122
type AddSubscriptionRequest struct {
@@ -34,7 +35,7 @@ func (request AddSubscriptionRequest) Validate() error {
3435
if err != nil {
3536
return errors.NewCommonEdgeXWrapper(err)
3637
} else if !contains(supportedChannelTypes, c.Type) {
37-
return errors.NewCommonEdgeX(errors.KindContractInvalid, "MQTT is not valid type for Channel", nil)
38+
return errors.NewCommonEdgeX(errors.KindContractInvalid, fmt.Sprintf("%s is not valid type for Channel", c.Type), nil)
3839
}
3940
}
4041
return nil
@@ -85,7 +86,7 @@ func (request UpdateSubscriptionRequest) Validate() error {
8586
if err != nil {
8687
return errors.NewCommonEdgeXWrapper(err)
8788
} else if !contains(supportedChannelTypes, c.Type) {
88-
return errors.NewCommonEdgeX(errors.KindContractInvalid, "MQTT is not valid type for Channel", nil)
89+
return errors.NewCommonEdgeX(errors.KindContractInvalid, fmt.Sprintf("%s is not valid type for Channel", c.Type), nil)
8990
}
9091
}
9192
if request.Subscription.Categories != nil && request.Subscription.Labels != nil &&

dtos/requests/subscription_test.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
//
2-
// Copyright (C) 2020-2021 IOTech Ltd
2+
// Copyright (C) 2020-2024 IOTech Ltd
33
//
44
// SPDX-License-Identifier: Apache-2.0
55

66
package requests
77

88
import (
99
"encoding/json"
10+
"net/http"
1011
"testing"
1112

1213
"github.com/edgexfoundry/go-mod-core-contracts/v4/dtos"
@@ -20,8 +21,13 @@ var (
2021
testSubscriptionName = "subscriptionName"
2122
testSubscriptionCategories = []string{"category1", "category2"}
2223
testSubscriptionLabels = []string{"label"}
24+
testHost = "host"
25+
testPort = 123
2326
testSubscriptionChannels = []dtos.Address{
27+
dtos.NewRESTAddress(testHost, testPort, http.MethodGet),
2428
dtos.NewEmailAddress([]string{"[email protected]"}),
29+
dtos.NewMQTTAddress(testHost, testPort, "publisher", "topic"),
30+
dtos.NewZeroMQAddress(testHost, testPort, "topic"),
2531
}
2632
testSubscriptionDescription = "description"
2733
testSubscriptionReceiver = "receiver"
@@ -87,7 +93,7 @@ func TestAddSubscriptionRequest_Validate(t *testing.T) {
8793
}
8894
unsupportedChannelType := addSubscriptionRequestData()
8995
unsupportedChannelType.Subscription.Channels = []dtos.Address{
90-
dtos.NewMQTTAddress("host", 123, "publisher", "topic"),
96+
{Type: "unknown"},
9197
}
9298

9399
noCategories := addSubscriptionRequestData()
@@ -212,7 +218,7 @@ func TestUpdateSubscriptionRequest_Validate(t *testing.T) {
212218
}
213219
unsupportedChannelType := NewUpdateSubscriptionRequest(updateSubscriptionData())
214220
unsupportedChannelType.Subscription.Channels = []dtos.Address{
215-
dtos.NewMQTTAddress("host", 123, "publisher", "topic"),
221+
{Type: "unknown"},
216222
}
217223
validWithoutChannels := NewUpdateSubscriptionRequest(updateSubscriptionData())
218224
validWithoutChannels.Subscription.Channels = nil

0 commit comments

Comments
 (0)