如何为Camel + ActiveMQ + Glassfish配置JNDI
该配置有效!
<bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://10.100.200.6:61616" />
<property name="userName" value="admin" />
<property name="password" value="admin" />
</bean>
<bean id="destResolver" class="org.springframework.jms.support.destination.JndiDestinationResolver"/>
<bean id="pooledConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory" init-method="start"
destroy-method="stop">
<property name="maxConnections" value="2" />
<property name="connectionFactory" ref="jmsConnectionFactory" />
</bean>
<bean id="jmsConfig" class="org.apache.camel.component.jms.JmsConfiguration">
<property name="connectionFactory" ref="pooledConnectionFactory" />
<property name="concurrentConsumers" value="10" />
<property name="destinationResolver" ref="destResolver"/>
</bean>
<bean id="mq" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="configuration" ref="jmsConfig" />
</bean>
但我想使用JNDI,因为我没有在已部署的xml文件中引用url,user,password。
我按照教程Integrating Apache ActiveMQ with Glassfish进行操作即可。
但是当我替换<bean id="jmsConnectionFactory"
使用<jee:jndi-lookup
<jee:jndi-lookup id="jmsConnectionFactory" jndi-name="jms/BandMqConnFactory" />
我收到了错误:
Stracktrace:
org.springframework.jms.UncategorizedJmsException: Uncategorized exception occurred during JMS processing; nested exception is javax.jms.JMSException: Error while attempting to add new Connection to the pool; nested exception is java.lang.ClassCastException: org.apache.activemq.ra.ManagedConnectionProxy cannot be cast to org.apache.activemq.ActiveMQConnection
at org.springframework.jms.support.JmsUtils.convertJmsAccessException(JmsUtils.java:316)
at org.springframework.jms.support.JmsAccessor.convertJmsAccessException(JmsAccessor.java:169)
at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:487)
at org.apache.camel.component.jms.JmsConfiguration$CamelJmsTemplate.send(JmsConfiguration.java:484)
at org.apache.camel.component.jms.JmsProducer.doSend(JmsProducer.java:440)
at org.apache.camel.component.jms.JmsProducer.processInOnly(JmsProducer.java:394)
at org.apache.camel.component.jms.JmsProducer.process(JmsProducer.java:157)
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:145)
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:541)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:198)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:120)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:198)
at org.apache.camel.component.timer.TimerConsumer.sendTimerExchange(TimerConsumer.java:196)
at org.apache.camel.component.timer.TimerConsumer$1.run(TimerConsumer.java:78)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)
Caused by: javax.jms.JMSException: Error while attempting to add new Connection to the pool
at org.apache.activemq.jms.pool.PooledConnectionFactory.createJmsException(PooledConnectionFactory.java:266)
at org.apache.activemq.jms.pool.PooledConnectionFactory.createConnection(PooledConnectionFactory.java:225)
at org.apache.activemq.jms.pool.PooledConnectionFactory.createConnection(PooledConnectionFactory.java:204)
at org.springframework.jms.support.JmsAccessor.createConnection(JmsAccessor.java:180)
at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:474)
... 15 more
Caused by: java.lang.ClassCastException: org.apache.activemq.ra.ManagedConnectionProxy cannot be cast to org.apache.activemq.ActiveMQConnection
at org.apache.activemq.pool.PooledConnectionFactory$1.wrap(PooledConnectionFactory.java:104)
at org.apache.activemq.jms.pool.ConnectionPool.<init>(ConnectionPool.java:69)
at org.apache.activemq.pool.PooledConnectionFactory$1.<init>(PooledConnectionFactory.java:98)
at org.apache.activemq.pool.PooledConnectionFactory.createConnectionPool(PooledConnectionFactory.java:98)
at org.apache.activemq.jms.pool.PooledConnectionFactory$1.makeObject(PooledConnectionFactory.java:97)
at org.apache.activemq.jms.pool.PooledConnectionFactory$1.makeObject(PooledConnectionFactory.java:92)
at org.apache.commons.pool2.impl.GenericKeyedObjectPool.create(GenericKeyedObjectPool.java:1041)
at org.apache.commons.pool2.impl.GenericKeyedObjectPool.addObject(GenericKeyedObjectPool.java:1221)
at org.apache.activemq.jms.pool.PooledConnectionFactory.createConnection(PooledConnectionFactory.java:221)
... 18 more
Apache Camel 2.16.x - 2.19.0
Glassfish 4.1 Buld 13
ActiveMQ 5.14.3
JDK 1.8