通过JmsTemplate向ActivemQ发送消息时setExceptionListener出错(作为Jboss-eap的外部代理)

时间:2015-01-27 08:18:10

标签: spring jms activemq spring-jms jboss-eap-6

根据this article,我已将Jboss eap 6.2与外部ActivemQ 5.9.0相关联。对于发送/接收消息,我在JmsTemplate中使用DefaultMessageListenerContainerspring-jms 4.1.1。接收消息工作正常,但在发送消息时我收到此错误:

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配置(reconnectOnException的{​​{1}}属性已激活SingleConnectionFactory

CachingConnectionFactory

Jboss <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> 用于ActivemQ(在resource-adapter中):

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> bean中注入singleConnectionFactory而不是cachingConnectionFactory时,错误就会消失!!

1 个答案:

答案 0 :(得分:1)

cachingConnectionFactory targetConnectionFactory SingleConnectionFactory不应该是另一个cachingConnectionFactory(因为它是一个子类,所以已经是{1}}。

相反,请将targetConnectionFactory&#39; userCredentialsConnectionFactoryAdapter设置为{{1}}。