所以我的用例是这样的: 我有一组Camel(2.14)路由,它们轮询几个数据库表,进行一些转换,然后将消息放在不同的ActiveMQ(5.10.0)队列上。为此我设置了一个连接池,如Camel wiki:
中所述<!-- ActiveMQ Connection Pooling-->
<bean id="pooledConnectionFactory"
class="org.apache.activemq.pool.PooledConnectionFactory" init-method="start" destroy-method="stop">
<property name="maxConnections" value="8" />
<property name="connectionFactory" ref="activeMQConnectionFactory" />
</bean>
<bean id="activemqConfig"
class="org.apache.camel.component.jms.JmsConfiguration">
<property name="connectionFactory" ref="pooledConnectionFactory"/>
<property name="concurrentConsumers" value="10"/>
</bean>
<bean id="activemq"
class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="configuration" ref="activemqConfig"/>
</bean>
我目前正在开发一组额外的Camel组件,它们将从一些ActiveMQ队列中获取数据,并将消息推送到某些JMS主题。这些主题基于OracleAQ,我目前的设置如下:
<!-- AQ JMS -->
<bean id="connectionFactoryOracleAQ" class="oracle.jms.AQjmsFactory"
factory-method="getQueueConnectionFactory">
<constructor-arg index="0">
<value>${rib.host}</value>
</constructor-arg>
<constructor-arg index="1" type="java.lang.String">
<value>${rib.sid}</value>
</constructor-arg>
<constructor-arg index="2" type="int">
<value>${rib.port}</value>
</constructor-arg>
<constructor-arg index="3">
<value>${rib.driverType}</value>
</constructor-arg>
</bean>
<bean id="credentials"
class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
<property name="targetConnectionFactory">
<ref bean="connectionFactoryOracleAQ"/>
</property>
<property name="username">
<value>${aq.user}</value>
</property>
<property name="password">
<value>${aq.pass}</value>
</property>
</bean>
<bean id="jms" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="connectionFactory" ref="credentials"/>
</bean>
不幸的是,发送到OracleAQ非常缓慢。我的骆驼路线中的to()步骤大约需要2.5秒,这还不够好。所以我想我会设置第二个连接池来查看是否有所改进,所以我改为设置连接工厂到这个::
<!-- AQ JMS -->
<bean id="connectionFactoryOracleAQ" class="oracle.jms.AQjmsFactory"
factory-method="getQueueConnectionFactory">
<constructor-arg index="0">
<value>${rib.host}</value>
</constructor-arg>
<constructor-arg index="1" type="java.lang.String">
<value>${rib.sid}</value>
</constructor-arg>
<constructor-arg index="2" type="int">
<value>${rib.port}</value>
</constructor-arg>
<constructor-arg index="3">
<value>${rib.driverType}</value>
</constructor-arg>
</bean>
<bean id="credentials"
class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
<property name="targetConnectionFactory">
<ref bean="connectionFactoryOracleAQ"/>
</property>
<property name="username">
<value>${aq.user}</value>
</property>
<property name="password">
<value>${aq.pass}</value>
</property>
</bean>
<!-- ActiveMQ Connection Pooling for AQ -->
<bean id="pooledConnectionFactoryAq"
class="org.apache.activemq.pool.PooledConnectionFactory" init-method="start" destroy-method="stop">
<property name="maxConnections" value="8" />
<property name="connectionFactory" ref="credentials" />
</bean>
<bean id="activemqConfigAq"
class="org.apache.camel.component.jms.JmsConfiguration">
<property name="connectionFactory" ref="pooledConnectionFactoryAq"/>
<property name="concurrentConsumers" value="10"/>
</bean>
<bean id="activemqAq"
class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="configuration" ref="activemqConfigAq"/>
</bean>
然而,当使用ActiveMQ启动我的路线时,我现在看到下面的例外情况。我在这里做错了什么?日志说该异常将被忽略,但我不想忽视它而不理解为什么它会被抛出:
2014-10-09 20:50:43,783 | INFO | Connector vm://localhost started | org.apache.activemq.broker.TransportConnector | WrapperSimpleAppMain
2014-10-09 20:50:44,760 | WARN | Create pooled connection during start failed. This exception will be ignored. | org.apache.activemq.jms.pool.PooledConnectionFactory | WrapperSimpleAppMain
javax.jms.JMSException: Error while attempting to add new Connection to the pool
at org.apache.activemq.jms.pool.PooledConnectionFactory.createJmsException(PooledConnectionFactory.java:247)[integration-routes-1.0-jar-with-dependencies.jar:]
at org.apache.activemq.jms.pool.PooledConnectionFactory.createConnection(PooledConnectionFactory.java:202)[integration-routes-1.0-jar-with-dependencies.jar:]
at org.apache.activemq.jms.pool.PooledConnectionFactory.createConnection(PooledConnectionFactory.java:181)[integration-routes-1.0-jar-with-dependencies.jar:]
at org.apache.activemq.jms.pool.PooledConnectionFactory.start(PooledConnectionFactory.java:267)[integration-routes-1.0-jar-with-dependencies.jar:]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.7.0_45]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)[:1.7.0_45]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.7.0_45]
at java.lang.reflect.Method.invoke(Method.java:606)[:1.7.0_45]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1640)[integration-routes-1.0-jar-with-dependencies.jar:]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1581)[integration-routes-1.0-jar-with-dependencies.jar:]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1511)[integration-routes-1.0-jar-with-dependencies.jar:]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)[integration-routes-1.0-jar-with-dependencies.jar:]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)[integration-routes-1.0-jar-with-dependencies.jar:]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)[integration-routes-1.0-jar-with-dependencies.jar:]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)[integration-routes-1.0-jar-with-dependencies.jar:]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)[integration-routes-1.0-jar-with-dependencies.jar:]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:191)[integration-routes-1.0-jar-with-dependencies.jar:]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:636)[integration-routes-1.0-jar-with-dependencies.jar:]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:934)[integration-routes-1.0-jar-with-dependencies.jar:]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)[integration-routes-1.0-jar-with-dependencies.jar:]
at org.apache.xbean.spring.context.ResourceXmlApplicationContext.<init>(ResourceXmlApplicationContext.java:64)[integration-routes-1.0-jar-with-dependencies.jar:]
at org.apache.xbean.spring.context.ResourceXmlApplicationContext.<init>(ResourceXmlApplicationContext.java:52)[integration-routes-1.0-jar-with-dependencies.jar:]
at org.apache.activemq.xbean.XBeanBrokerFactory$1.<init>(XBeanBrokerFactory.java:104)[activemq-spring-5.10.0.jar:5.10.0]
at org.apache.activemq.xbean.XBeanBrokerFactory.createApplicationContext(XBeanBrokerFactory.java:104)[activemq-spring-5.10.0.jar:5.10.0]
at org.apache.activemq.xbean.XBeanBrokerFactory.createBroker(XBeanBrokerFactory.java:67)[activemq-spring-5.10.0.jar:5.10.0]
at org.apache.activemq.broker.BrokerFactory.createBroker(BrokerFactory.java:71)[activemq-broker-5.10.0.jar:5.10.0]
at org.apache.activemq.broker.BrokerFactory.createBroker(BrokerFactory.java:54)[activemq-broker-5.10.0.jar:5.10.0]
at org.apache.activemq.console.command.StartCommand.runTask(StartCommand.java:87)[activemq-console-5.10.0.jar:5.10.0]
at org.apache.activemq.console.command.AbstractCommand.execute(AbstractCommand.java:57)[activemq-console-5.10.0.jar:5.10.0]
at org.apache.activemq.console.command.ShellCommand.runTask(ShellCommand.java:150)[activemq-console-5.10.0.jar:5.10.0]
at org.apache.activemq.console.command.AbstractCommand.execute(AbstractCommand.java:57)[activemq-console-5.10.0.jar:5.10.0]
at org.apache.activemq.console.command.ShellCommand.main(ShellCommand.java:104)[activemq-console-5.10.0.jar:5.10.0]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.7.0_45]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)[:1.7.0_45]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.7.0_45]
at java.lang.reflect.Method.invoke(Method.java:606)[:1.7.0_45]
at org.apache.activemq.console.Main.runTaskClass(Main.java:262)[activemq.jar:5.10.0]
at org.apache.activemq.console.Main.main(Main.java:115)[activemq.jar:5.10.0]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.7.0_45]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)[:1.7.0_45]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.7.0_45]
at java.lang.reflect.Method.invoke(Method.java:606)[:1.7.0_45]
at org.tanukisoftware.wrapper.WrapperSimpleApp.run(WrapperSimpleApp.java:240)[wrapper.jar:3.2.3]
at java.lang.Thread.run(Thread.java:744)[:1.7.0_45]