我想以这样的方式配置我的消息驱动通道适配器,以便在以下情况下我可以获取“连接被拒绝”错误: 1)消息代理已关闭或2)指定了错误的代理URL
我尝试使用下面的代码执行此操作,但它不起作用:
<int:channel id="invalidChannel" />
<int-mqtt:message-driven-channel-adapter
id="myAdapter"
client-id="${inbound.client.id}"
url="${host.url}"
topics="${inbound.topic}"
channel="incomingChannel"
error-channel="errorChannel"
client-factory="clientFactory" />
<int:exception-type-router input-channel="errorChannel">
<int:mapping exception-type="java.net.ConnectException" channel="invalidChannel" />
</int:exception-type-router>
<int:service-activator id="ErrorActivator"
input-channel="invalidChannel"
ref="errorListener"
method="processError" />
<bean id="errorListener" class="com.ErrorListener" />
processError()方法定义如下:
public void processError(Message<MessageHandlingException> message)
{
System.out.println("an error / exception occured");
}
我正在尝试获取在连接异常的情况下记录的异常:
Unable to connect to server (32103) - java.net.ConnectException: Connection refused: connect
at org.eclipse.paho.client.mqttv3.internal.TCPNetworkModule.start(TCPNetworkModule.java:79)
at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:590)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at org.eclipse.paho.client.mqttv3.internal.TCPNetworkModule.start(TCPNetworkModule.java:70)
... 2 more
有人可以帮忙吗?
此致
答案 0 :(得分:1)
Connection refused
错误不是Messaging流的一部分,因此errorChannel
不会处理它。 M-m-m ......只是因为它是在任何Message
出现之前引起的。
<强>更新强>
从Spring Integration 4.2.2
开始,MqttConnectionFailedEvent
可用于这些情况。
请参阅“参考手册”中的更多信息:http://docs.spring.io/spring-integration/reference/html/mqtt.html