在尝试使用Spring MQTT集成时,我们看到本主题标题中提到的异常。Spring Mqtt:MqttPahoMessageDrivenChannelAdapter - 丢失的连接:连接丢失;正在重试
设置细节如下: 1)我们有两个不同的消息适配器:消息驱动通道适配器和出站通道适配器。两者都有唯一的客户ID
2)桌面应用程序用作Mqtt客户端发布消息驱动通道适配器处理的某些消息。示例代码如下:
ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
DefaultMqttPahoClientFactory mqttClientFactory = (DefaultMqttPahoClientFactory) ac.getBean("clientFactory");
MqttClient gatewayClient = mqttClientFactory.getClientInstance("tcp://abc.com:1883", "STCLP014CI021CLIENT1");
String test = "this is test"
gatewayClient.connect();
MqttMessage message = new MqttMessage(test.getBytes());
message.setQos(1);
gatewayClient.publish("store/entity/mpg/zmesg/fromdevice/014/00021/eco/pos/a56f4302004b1200/1420221417963/2ce6f45f-97a6-49d2-91e5-640effcfa651/192.168.10.70", message);
gatewayClient.disconnect();
3)听者豆配置消息驱动通道适配器处理进入的消息,并还出版到出站信道适配器的信道响应。
的示例代码如下:
public void processMessage(String message)
{
ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
System.out.println("message received " + message);
String response = "response message";
MessageChannel responseChannel = (MessageChannel) ac.getBean("mpgResponseChannel");
responseChannel.send(new GenericMessage<String>(response));
}
上面的代码发布成功的消息,但断开“入站”消息驱动通道适配器和我们如下看到一个连续堆栈跟踪控制台上:
11:09:33.675 [MQTT Rec: STCLP014CI021CLIENT3] ERROR o.s.i.m.i.MqttPahoMessageDrivenChannelAdapter - Lost connection:Connection lost; retrying...
11:09:33.787 [MQTT Rec: STCLP014CI021CLIENT3] ERROR o.s.i.m.i.MqttPahoMessageDrivenChannelAdapter - Lost connection:Connection lost; retrying...
11:09:33.850 [MQTT Rec: STCLP014CI021CLIENT3] ERROR o.s.i.m.i.MqttPahoMessageDrivenChannelAdapter - Lost connection:Connection lost; retrying...
11:09:33.959 [MQTT Rec: STCLP014CI021CLIENT3] ERROR o.s.i.m.i.MqttPahoMessageDrivenChannelAdapter - Lost connection:Connection lost; retrying...
11:09:34.021 [MQTT Rec: STCLP014CI021CLIENT3] ERROR o.s.i.m.i.MqttPahoMessageDrivenChannelAdapter - Lost connection:Connection lost; retrying...
有人可以请建议上述吗?
有一种方法可以确保入站适配器在消息发布到出站适配器后不会断开连接吗?
关于。
得到同样的错误.. https://stackoverflow.com/questions/44885702/spring-mqttpahomessagedrivenchanneladapter-lost-connectionconnection-lost -retr – HybrisFreelance