1515package v5client
1616
1717import (
18+ "context"
1819 "crypto/tls"
1920 "errors"
2021 "fmt"
@@ -47,14 +48,15 @@ type Client struct {
4748}
4849
4950type ConnectionConfig struct {
50- Server string `json:"server"`
51- ClientId string `json:"clientid"`
52- Uname string `json:"username"`
53- Password string `json:"password"`
54- EnableClientSession bool `json:"enableClientSession"`
55- ClientStatePath string `json:"clientStatePath"`
56- serverUrl * url.URL
57- tls * tls.Config
51+ Server string `json:"server"`
52+ ClientId string `json:"clientid"`
53+ Uname string `json:"username"`
54+ Password string `json:"password"`
55+ EnableClientSession bool `json:"enableClientSession"`
56+ ClientStatePath string `json:"clientStatePath"`
57+ SessionExpiryIntervalSeconds int `json:"sessionExpiryIntervalSeconds"`
58+ serverUrl * url.URL
59+ tls * tls.Config
5860}
5961
6062func Provision (ctx api.StreamContext , props map [string ]any , onConnect client.ConnectHandler , onConnectLost client.ConnectErrorHandler , _ client.ConnectHandler ) (* Client , error ) {
@@ -79,7 +81,7 @@ func Provision(ctx api.StreamContext, props map[string]any, onConnect client.Con
7981 // It is important to set this because otherwise, any queued messages will be lost if the connection drops and
8082 // the server will not queue messages while it is down. The specific setting will depend upon your needs
8183 // (60 = 1 minute, 3600 = 1 hour, 86400 = one day, 0xFFFFFFFE = 136 years, 0xFFFFFFFF = don't expire)
82- SessionExpiryInterval : 60 ,
84+ SessionExpiryInterval : uint32 ( cc . SessionExpiryIntervalSeconds ) ,
8385 OnConnectionUp : func (cm * autopaho.ConnectionManager , connAck * paho.Connack ) {
8486 onConnect (ctx )
8587 },
@@ -235,7 +237,9 @@ func (c *Client) Unsubscribe(ctx api.StreamContext, topic string) error {
235237}
236238
237239func (c * Client ) Disconnect (ctx api.StreamContext ) {
238- err := c .cm .Disconnect (ctx )
240+ dctx , dcancel := context .WithTimeout (context .Background (), time .Second * 5 )
241+ defer dcancel ()
242+ err := c .cm .Disconnect (dctx )
239243 if err != nil {
240244 ctx .GetLogger ().Warnf ("disconnect error: %s" , err )
241245 }
@@ -263,7 +267,9 @@ func (c *Client) ParseMsg(ctx api.StreamContext, msg any) ([]byte, map[string]an
263267}
264268
265269func ValidateConfig (ctx api.StreamContext , props map [string ]any ) (* ConnectionConfig , error ) {
266- c := & ConnectionConfig {}
270+ c := & ConnectionConfig {
271+ SessionExpiryIntervalSeconds : 60 ,
272+ }
267273 err := cast .MapToStruct (props , c )
268274 if err != nil {
269275 return nil , err
0 commit comments