在嘗試使用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