Spring Message-Drived Channel-Adapter:处理连接拒绝错误 [英] Spring message-driven-channel-adapter: handling connection refused error

查看:285
本文介绍了Spring Message-Drived Channel-Adapter:处理连接拒绝错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以某种方式配置我的message-driven-channel-adapter,以便在出现以下情况时可以捕获连接被拒绝"错误: 1)消息代理已关闭或2)指定的代理URL错误

I want to configure my message-driven-channel-adapter in such a way that I can grab the 'connection refused' error in case when: 1) the message broker is down or 2) A wrong broker URL is specified

我尝试使用下面的代码执行此操作,但是它不起作用:

I tried doing this with the code below but it did not work:

<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()方法的定义如下:

The processError() method is defined as below:

public void processError(Message<MessageHandlingException> message)
    {
        System.out.println("an error / exception occured");
    }

我正在尝试获取连接异常的情况下记录如下的异常:

I am trying to grab the exception which is logged as below in case of connection exception:

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 

有人可以帮忙吗?

致谢

推荐答案

Connection refused错误不是消息流的一部分,因此errorChannel不会处理该错误. M-m-m ...仅仅是因为它是在Message出现之前引起的.

Connection refused error isn't a part of Messaging flow, so it isn't handled by the errorChannel. M-m-m... Just because it is caused before any Message appears.

更新

从Spring Integration 4.2.2开始,MqttConnectionFailedEvent在这些情况下可用.

Starting with Spring Integration 4.2.2 the MqttConnectionFailedEvent is available for these cases.

请参阅参考手册中的更多信息: http://docs. spring.io/spring-integration/reference/html/mqtt.html

See more information in the Reference Manual: http://docs.spring.io/spring-integration/reference/html/mqtt.html

这篇关于Spring Message-Drived Channel-Adapter:处理连接拒绝错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆