Based on this article, I've connected Jboss eap 6.2
to an external ActivemQ 5.9.0
. For sending/receiving message i'm using JmsTemplate
and DefaultMessageListenerContainer
in spring-jms 4.1.1
. Receiving message is working fine, but in sending message i get this error:
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
Here is my spring/jms configurations (reconnectOnException
property of SingleConnectionFactory
and CachingConnectionFactory
is activated):
<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>
And Jboss resource-adapter
for ActivemQ (in 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>
UPDATE:
When i inject singleConnectionFactory
instead of cachingConnectionFactory
in my defaultJmsTemplate
bean, the error disappears!!
Your cachingConnectionFactory
's targetConnectionFactory
should not be another SingleConnectionFactory
(it's already one because it's a subclass).
Instead, set the cachingConnectionFactory
's targetConnectionFactory
to userCredentialsConnectionFactoryAdapter
.
来源:https://stackoverflow.com/questions/28165924/error-in-setexceptionlistener-in-sending-message-via-jmstemplate-to-activemq-as