Skip to content

Commit

Permalink
feat: Add SetOnConnectHandler in BuiltInPipelinsFuncions (#1348)
Browse files Browse the repository at this point in the history
Signed-off-by: Jieke Choo <jiekechoo@yiqisoft.cn>
  • Loading branch information
jiekechoo authored Mar 11, 2024
1 parent 89c5253 commit 26d7bc2
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ The `URLFormatter` option allows you to override the default formatter with your
| Method | Description |
| ------------------------------------------------------------ | ------------------------------------------------------------ |
| ConnectToBroker(lc logger.LoggingClient, sp bootstrapInterfaces.SecretProvider, retryCount int, retryInterval time.Duration) | Pre-connects to the external MQTT Broker that data will be exported. If this function is not called, then lazy connection will be made when the first data needs to be exported. |
| SetOnConnectHandler(onConnect MQTT.OnConnectHandler) | SetOnConnect sets the OnConnect Handler before client is connected so client can be captured. |

!!! example - "Pre-Connecting to MQTT Broker"
```go
Expand All @@ -309,6 +310,27 @@ The `URLFormatter` option allows you to override the default formatter with your
!!! edgey - "EdgeX 3.2"
ConnectToBroker is new in EdgeX 3.2

!!! example - "Subscribe from MQTT Broker"
```go
...
sender.SetOnConnectHandler(onConnectHandler)
sender.ConnectToBroker(lc,sp,1,10)
...
func onConnectHandler(client mqtt.Client) {
// subscribe topic
incomingTopic := "your_topic"
token := client.Subscribe(incomingTopic, qos, onIncomingDataReceived)
...
}
...
func onIncomingDataReceived(_ mqtt.client, message mqtt.Message) {
...
}
```

!!! edgey - "EdgeX 3.2"
SetOnConnectHandler is new in EdgeX 3.2

```go
type MQTTSecretConfig struct {
// BrokerAddress should be set to the complete broker address i.e. mqtts://mosquitto:8883/mybroker
Expand Down

0 comments on commit 26d7bc2

Please sign in to comment.