我有两个jms侦听器应用程序,一个应用程序使用DefaultMessageListenerContainer
,另一个应用软件使用SimpleMessageListenerContainer
具有DefaultMessageListenerContainer
的应用程序能够在EMS代理故障转移时重新连接,以下是日志
Setup of JMS message listener invoker failed for destination 'SOME.TOPIC.T' - trying to recover. Cause: Connection is closed
Could not refresh JMS Connection for destination 'SOME.TOPIC.T' - retrying using FixedBackOff{interval=5000, currentAttempts=0, maxAttempts=unlimited}. Cause: Failed to connect to any server at: tcp://localhost:8285,tcp://localhost:8286
Could not refresh JMS Connection for destination 'SOME.TOPIC.T' - retrying using FixedBackOff{interval=5000, currentAttempts=1, maxAttempts=unlimited}. Cause: Failed to connect to any server at: tcp://localhost:8285,tcp://localhost:8286
带有SimpleMessageListenerContainer
的应用程序无法在EMS代理故障转移时重新连接,以下是日志
[TIBCO EMS TCPLink Reader (Server-109365)] INFO org.springframework.jms.listener.SimpleMessageListenerContainer - Trying to recover from JMS Connection exception: javax.jms.JMSException: Connection has been terminated
[TIBCO EMS TCPLink Reader (Server-109366)] ERROR org.springframework.jms.listener.SimpleMessageListenerContainer - Encountered non-recoverable JMSException
javax.jms.JMSException: Connection has been terminated
at com.tibco.tibjms.Tibjmsx.buildException(Tibjmsx.java:659) ~[tibjms-8.3.0.jar!/:?]
at com.tibco.tibjms.TibjmsConnection._invokeOnExceptionCallback(TibjmsConnection.java:2118) [tibjms-8.3.0.jar!/:?]
at com.tibco.tibjms.TibjmsConnection._onDisconnected(TibjmsConnection.java:2487) [tibjms-8.3.0.jar!/:?]
at com.tibco.tibjms.TibjmsConnection$ServerLinkEventHandler.onEventDisconnected(TibjmsConnection.java:367) [tibjms-8.3.0.jar!/:?]
at com.tibco.tibjms.TibjmsxLinkTcp$LinkReader.work(TibjmsxLinkTcp.java:328) [tibjms-8.3.0.jar!/:?]
at com.tibco.tibjms.TibjmsxLinkTcp$LinkReader.run(TibjmsxLinkTcp.java:259) [tibjms-8.3.0.jar!/:?]
两者都连接到同一个broker实例,如何使SimpleMessageListenerContainer
侦听器在JMS异常上重新连接?
简单的容器是。。。呃。。。易于理解的
它只尝试恢复连接一次。
默认容器更为复杂,并配置了BackOff
(对于无限次尝试,默认为每5秒一次(。
如果您需要这种复杂度,请使用默认容器,但它需要是事务性的,以避免消息丢失的可能性——请参阅javadocs。