【发布时间】:2015-06-23 15:28:22
【问题描述】:
在尝试使用 Spring MQTT 集成时,我们看到了本主题标题中提到的异常。
设置详情如下: 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) 为消息驱动通道适配器配置的侦听器 bean 处理传入消息,并且还将响应发布到出站通道适配器的通道。
示例代码如下:
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...
有人可以就上述问题提出建议吗?
有没有办法确保在消息发布到出站适配器后入站适配器不会断开连接?
问候。
【问题讨论】: