通过 JmsTemplate 向 ActivemQ 发送消息时 setExceptionListener 出错(作为 Jboss-eap 的外部代理)
Error in setExceptionListener in sending message via JmsTemplate to ActivemQ (as external broker of Jboss-eap)
基于 this article,我已将 Jboss eap 6.2
连接到外部 ActivemQ 5.9.0
。对于 sending/receiving 消息,我在 spring-jms 4.1.1
中使用 JmsTemplate
和 DefaultMessageListenerContainer
。接收消息工作正常,但在发送消息时出现此错误:
11:33:37,059 ERROR [stderr] java.lang.reflect.InvocationTargetException
11:33:37,060 ERROR [stderr] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
11:33:37,060 ERROR [stderr] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
11:33:37,060 ERROR [stderr] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
11:33:37,061 ERROR [stderr] at java.lang.reflect.Method.invoke(Method.java:601)
11:33:37,061 ERROR [stderr] at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:269)
11:33:37,061 ERROR [stderr] at core.util.timer.MethodInvocationScheduledJob.run(MethodInvocationScheduledJob.java:19)
11:33:37,061 ERROR [stderr] at core.util.timer.JobScheduler$ScheduledJobThread.run(JobScheduler.java:132)
11:33:37,062 ERROR [stderr] Caused by: org.springframework.jms.IllegalStateException: setExceptionListener call not supported on proxy for shared Connection. Set the 'exceptionListener' property on the SingleConnectionFactory instead. Alternatively, activate SingleConnectionFactory's 'reconnectOnException' feature, which will allow for registering further ExceptionListeners to the recovery chain.; nested exception is javax.jms.IllegalStateException: setExceptionListener call not supported on proxy for shared Connection. Set the 'exceptionListener' property on the SingleConnectionFactory instead. Alternatively, activate SingleConnectionFactory's 'reconnectOnException' feature, which will allow for registering further ExceptionListeners to the recovery chain.
11:33:37,062 ERROR [stderr] at org.springframework.jms.support.JmsUtils.convertJmsAccessException(JmsUtils.java:279)
11:33:37,062 ERROR [stderr] at org.springframework.jms.support.JmsAccessor.convertJmsAccessException(JmsAccessor.java:168)
11:33:37,063 ERROR [stderr] at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:469)
11:33:37,063 ERROR [stderr] at org.springframework.jms.core.JmsTemplate.send(JmsTemplate.java:59)
11:33:37,063 ERROR [stderr] at core.security.jms.SecurityMessageSender.sendSecuritySetting(SecurityMessageSender.java:19)
11:33:37,064 ERROR [stderr] at core.security.synchronizer.SecuritySynchronizer.synchronize(SecuritySynchronizer.java:34)
11:33:37,064 ERROR [stderr] ... 7 more
11:33:37,064 ERROR [stderr] Caused by: javax.jms.IllegalStateException: setExceptionListener call not supported on proxy for shared Connection. Set the 'exceptionListener' property on the SingleConnectionFactory instead. Alternatively, activate SingleConnectionFactory's 'reconnectOnException' feature, which will allow for registering further ExceptionListeners to the recovery chain.
11:33:37,065 ERROR [stderr] at org.springframework.jms.connection.SingleConnectionFactory$SharedConnectionInvocationHandler.invoke(SingleConnectionFactory.java:504)
11:33:37,065 ERROR [stderr] at $Proxy147.setExceptionListener(Unknown Source)
11:33:37,065 ERROR [stderr] at org.springframework.jms.connection.SingleConnectionFactory.prepareConnection(SingleConnectionFactory.java:364)
11:33:37,065 ERROR [stderr] at org.springframework.jms.connection.SingleConnectionFactory.initConnection(SingleConnectionFactory.java:289)
11:33:37,065 ERROR [stderr] at org.springframework.jms.connection.SingleConnectionFactory.createConnection(SingleConnectionFactory.java:225)
11:33:37,066 ERROR [stderr] at org.springframework.jms.support.JmsAccessor.createConnection(JmsAccessor.java:184)
11:33:37,066 ERROR [stderr] at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:456)
11:33:37,066 ERROR [stderr] ... 11 more
这是我的 spring/jms 配置(SingleConnectionFactory
和 CachingConnectionFactory
的 reconnectOnException
属性 已激活):
<bean name="defaultJmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="cachingConnectionFactory" />
<property name="sessionTransacted" value="true" />
</bean>
<bean id="abstractMessageListenerContainer" abstract="true"
class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="singleConncetionFactory" />
<property name="concurrentConsumers" value="1" />
<property name="maxConcurrentConsumers" value="1" />
<property name="idleConsumerLimit" value="1" />
<property name="idleTaskExecutionLimit" value="5" />
<property name="receiveTimeout" value="5000" />
<property name="recoveryInterval" value="7000" />
<property name="sessionTransacted" value="true" />
</bean>
<bean id="cachingConnectionFactory"
class="org.springframework.jms.connection.CachingConnectionFactory">
<property name="targetConnectionFactory" ref="singleConncetionFactory" />
<property name="reconnectOnException" value="true" />
<property name="sessionCacheSize" value="10" />
</bean>
<bean id="singleConncetionFactory"
class="org.springframework.jms.connection.SingleConnectionFactory">
<property name="targetConnectionFactory" ref="userCredentialsConnectionFactoryAdapter" />
<property name="reconnectOnException" value="true" />
</bean>
<bean id="userCredentialsConnectionFactoryAdapter"
class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
<property name="targetConnectionFactory" ref="jmsConnectionFactory" />
<property name="username" value="${jms.connectionfactory.username}" />
<property name="password" value="${jms.connectionfactory.password}" />
</bean>
<bean id="jmsConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="${jms.connectionfactory.jndi}" />
<property name="lookupOnStartup" value="false"/>
<property name="proxyInterface" value="javax.jms.ConnectionFactory"/>
</bean>
和 Jboss resource-adapter
对于 ActivemQ(在 standalone.xml
中):
<resource-adapter id="activemq-rar.ra">
<module slot="main" id="org.apache.activemq"/>
<transaction-support>LocalTransaction</transaction-support>
<config-property name="ServerUrl">tcp://localhost:61616</config-property>
<connection-definitions>
<connection-definition class-name="org.apache.activemq.ra.ActiveMQManagedConnectionFactory" jndi-name="java:/activemq/ConnectionFactory"enabled="true" use-java-context="true" pool-name="ActiveMQConnectionFactoryPool">
</connection-definition>
</connection-definitions>
</resource-adapter>
更新:
当我在 defaultJmsTemplate
bean 中注入 singleConnectionFactory
而不是 cachingConnectionFactory
时,错误消失了!!
你的cachingConnectionFactory
的targetConnectionFactory
不应该是另一个SingleConnectionFactory
(它已经是一个,因为它是一个子类)。
相反,将 cachingConnectionFactory
的 targetConnectionFactory
设置为 userCredentialsConnectionFactoryAdapter
。
基于 this article,我已将 Jboss eap 6.2
连接到外部 ActivemQ 5.9.0
。对于 sending/receiving 消息,我在 spring-jms 4.1.1
中使用 JmsTemplate
和 DefaultMessageListenerContainer
。接收消息工作正常,但在发送消息时出现此错误:
11:33:37,059 ERROR [stderr] java.lang.reflect.InvocationTargetException
11:33:37,060 ERROR [stderr] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
11:33:37,060 ERROR [stderr] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
11:33:37,060 ERROR [stderr] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
11:33:37,061 ERROR [stderr] at java.lang.reflect.Method.invoke(Method.java:601)
11:33:37,061 ERROR [stderr] at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:269)
11:33:37,061 ERROR [stderr] at core.util.timer.MethodInvocationScheduledJob.run(MethodInvocationScheduledJob.java:19)
11:33:37,061 ERROR [stderr] at core.util.timer.JobScheduler$ScheduledJobThread.run(JobScheduler.java:132)
11:33:37,062 ERROR [stderr] Caused by: org.springframework.jms.IllegalStateException: setExceptionListener call not supported on proxy for shared Connection. Set the 'exceptionListener' property on the SingleConnectionFactory instead. Alternatively, activate SingleConnectionFactory's 'reconnectOnException' feature, which will allow for registering further ExceptionListeners to the recovery chain.; nested exception is javax.jms.IllegalStateException: setExceptionListener call not supported on proxy for shared Connection. Set the 'exceptionListener' property on the SingleConnectionFactory instead. Alternatively, activate SingleConnectionFactory's 'reconnectOnException' feature, which will allow for registering further ExceptionListeners to the recovery chain.
11:33:37,062 ERROR [stderr] at org.springframework.jms.support.JmsUtils.convertJmsAccessException(JmsUtils.java:279)
11:33:37,062 ERROR [stderr] at org.springframework.jms.support.JmsAccessor.convertJmsAccessException(JmsAccessor.java:168)
11:33:37,063 ERROR [stderr] at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:469)
11:33:37,063 ERROR [stderr] at org.springframework.jms.core.JmsTemplate.send(JmsTemplate.java:59)
11:33:37,063 ERROR [stderr] at core.security.jms.SecurityMessageSender.sendSecuritySetting(SecurityMessageSender.java:19)
11:33:37,064 ERROR [stderr] at core.security.synchronizer.SecuritySynchronizer.synchronize(SecuritySynchronizer.java:34)
11:33:37,064 ERROR [stderr] ... 7 more
11:33:37,064 ERROR [stderr] Caused by: javax.jms.IllegalStateException: setExceptionListener call not supported on proxy for shared Connection. Set the 'exceptionListener' property on the SingleConnectionFactory instead. Alternatively, activate SingleConnectionFactory's 'reconnectOnException' feature, which will allow for registering further ExceptionListeners to the recovery chain.
11:33:37,065 ERROR [stderr] at org.springframework.jms.connection.SingleConnectionFactory$SharedConnectionInvocationHandler.invoke(SingleConnectionFactory.java:504)
11:33:37,065 ERROR [stderr] at $Proxy147.setExceptionListener(Unknown Source)
11:33:37,065 ERROR [stderr] at org.springframework.jms.connection.SingleConnectionFactory.prepareConnection(SingleConnectionFactory.java:364)
11:33:37,065 ERROR [stderr] at org.springframework.jms.connection.SingleConnectionFactory.initConnection(SingleConnectionFactory.java:289)
11:33:37,065 ERROR [stderr] at org.springframework.jms.connection.SingleConnectionFactory.createConnection(SingleConnectionFactory.java:225)
11:33:37,066 ERROR [stderr] at org.springframework.jms.support.JmsAccessor.createConnection(JmsAccessor.java:184)
11:33:37,066 ERROR [stderr] at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:456)
11:33:37,066 ERROR [stderr] ... 11 more
这是我的 spring/jms 配置(SingleConnectionFactory
和 CachingConnectionFactory
的 reconnectOnException
属性 已激活):
<bean name="defaultJmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="cachingConnectionFactory" />
<property name="sessionTransacted" value="true" />
</bean>
<bean id="abstractMessageListenerContainer" abstract="true"
class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="singleConncetionFactory" />
<property name="concurrentConsumers" value="1" />
<property name="maxConcurrentConsumers" value="1" />
<property name="idleConsumerLimit" value="1" />
<property name="idleTaskExecutionLimit" value="5" />
<property name="receiveTimeout" value="5000" />
<property name="recoveryInterval" value="7000" />
<property name="sessionTransacted" value="true" />
</bean>
<bean id="cachingConnectionFactory"
class="org.springframework.jms.connection.CachingConnectionFactory">
<property name="targetConnectionFactory" ref="singleConncetionFactory" />
<property name="reconnectOnException" value="true" />
<property name="sessionCacheSize" value="10" />
</bean>
<bean id="singleConncetionFactory"
class="org.springframework.jms.connection.SingleConnectionFactory">
<property name="targetConnectionFactory" ref="userCredentialsConnectionFactoryAdapter" />
<property name="reconnectOnException" value="true" />
</bean>
<bean id="userCredentialsConnectionFactoryAdapter"
class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
<property name="targetConnectionFactory" ref="jmsConnectionFactory" />
<property name="username" value="${jms.connectionfactory.username}" />
<property name="password" value="${jms.connectionfactory.password}" />
</bean>
<bean id="jmsConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="${jms.connectionfactory.jndi}" />
<property name="lookupOnStartup" value="false"/>
<property name="proxyInterface" value="javax.jms.ConnectionFactory"/>
</bean>
和 Jboss resource-adapter
对于 ActivemQ(在 standalone.xml
中):
<resource-adapter id="activemq-rar.ra">
<module slot="main" id="org.apache.activemq"/>
<transaction-support>LocalTransaction</transaction-support>
<config-property name="ServerUrl">tcp://localhost:61616</config-property>
<connection-definitions>
<connection-definition class-name="org.apache.activemq.ra.ActiveMQManagedConnectionFactory" jndi-name="java:/activemq/ConnectionFactory"enabled="true" use-java-context="true" pool-name="ActiveMQConnectionFactoryPool">
</connection-definition>
</connection-definitions>
</resource-adapter>
更新:
当我在 defaultJmsTemplate
bean 中注入 singleConnectionFactory
而不是 cachingConnectionFactory
时,错误消失了!!
你的cachingConnectionFactory
的targetConnectionFactory
不应该是另一个SingleConnectionFactory
(它已经是一个,因为它是一个子类)。
相反,将 cachingConnectionFactory
的 targetConnectionFactory
设置为 userCredentialsConnectionFactoryAdapter
。