tx7do / kratos-transport

kratos transport layer extension
MIT License
348 stars 95 forks source link

MQTT断线后重连,订阅消息无法恢复 #57

Closed happychenleilei closed 1 year ago

happychenleilei commented 1 year ago

问题描述: MQTT断线再次重连后,之前订阅过的主题,无法收到消息 期望:MQTT断线后重连,之前订阅的消息能够正常收到消息 代码如下,

func NewMQTTServer(
    c *conf.Bootstrap, svc *service.OperationStatService,
) *mqtt.Server {
    ctx := context.Background()
    var opts = []mqtt.ServerOption{
        mqtt.WithAddress([]string{c.Server.Mqtt.Addr}),
        mqtt.WithCodec("json"),
        mqtt.WithAuth(c.Server.Mqtt.Username, c.Server.Mqtt.Password),
        mqtt.WithClientId(c.Server.Mqtt.ClientId),
        mqtt.WithCleanSession(true),
    }
    srv := mqtt.NewServer(opts...)
    _ = srv.RegisterSubscriber(
        ctx,
        c.OperationStat.SubTopic,
        biz.RegisterDeviceAckJsonHandler(svc.DeviceAckHandler),
        biz.DeviceAckCreator,
    )
    svc.SetMqttBroker(srv)
    return srv
}