Apache Camel多个JMS路由

时间:2014-08-07 15:07:10

标签: jms apache-camel

我是骆驼新手,我对路线有疑问。在我的configure方法中,我使用了 - 简化代码:

from("file:folder1")
   .unmarshal().jaxb(BookBean.class.getPackage().getName())
      .bean(BeanToEntity.class);

from("jms:queue1")
   .to("file:folder2?fileName=$simple{date:now:yyyyMMddHHmmssSSS}.xml");

from("file:folder2")
   .unmarshal().jaxb(BookBean.class.getPackage().getName())
      .bean(BeanToEntity.class);

from("jms:queue2")
   .to("file:folder3?fileName=$simple{date:now:yyyyMMddHHmmssSSS}.xml");

from("file:folder3")
   .unmarshal().jaxb(BookBean.class.getPackage().getName())
      .bean(BeanToEntity.class);

现在,如果folder1中有一些文件会被定期处理,当我在queue2中放入一个带有xml正文的消息时,会发生同样的情况。但是当我在queue1中放入一条消息时,它不起作用,使用QBrowser我在该队列上看到了消息。我尝试定义两个JmsComponent,每个路由一个,类似于:

cdiCamelContext.addComponent("jms-1", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
cdiCamelContext.addComponent("jms-2", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));

但没有结果。我做错了什么?

修改 我简化了我的代码,无论如何我需要两个具有不同行为的路由。显然,当我将JMS组件定义为jms-1jms-2时,我编写了路由from("jms-1:queue1")from("jms-2:queue2"),但同样没有结果。 现在,在两个队列中将ConcurrentConsumers选项设置为10,消息将在两个队列中传递,但在Glassfish日志中我看到(GreenQueue和RedQueue就是我所谓的queue1和queue2):

[2014-08-08T09:35:57.040+0200] [glassfish 4.0] [WARNING] [] [org.apache.camel.component.jms.DefaultJmsMessageListenerContainer] [tid: _ThreadID=177 _ThreadName=Camel (camel-2) thread #6 - JmsConsumer[GreenQueue]] [timeMillis: 1407483357040] [levelValue: 900] [[
  Setup of JMS message listener invoker failed for destination 'GreenQueue' - trying to recover. Cause: MQJMSRA_DC4001: createSession():An active Session object already exists for this connection, only one active Session object allowed per connection.]]

[2014-08-08T09:35:57.040+0200] [glassfish 4.0] [WARNING] [] [org.apache.camel.component.jms.DefaultJmsMessageListenerContainer] [tid: _ThreadID=183 _ThreadName=Camel (camel-2) thread #12 - JmsConsumer[RedQueue]] [timeMillis: 1407483357040] [levelValue: 900] [[
  Setup of JMS message listener invoker failed for destination 'RedQueue' - trying to recover. Cause: MQJMSRA_DC4001: createSession():An active Session object already exists for this connection, only one active Session object allowed per connection.]]

[2014-08-08T09:35:59.032+0200] [glassfish 4.0] [WARNING] [] [javax.jms.Session.mqjmsra] [tid: _ThreadID=192 _ThreadName=Camel (camel-2) thread #21 - JmsConsumer[RedQueue]] [timeMillis: 1407483359032] [levelValue: 900] [[
  MQJMSRA_DS4001: getTransacted()Session is closed:Id=8349471074929595648]]

[2014-08-08T09:36:01.027+0200] [glassfish 4.0] [WARNING] [] [javax.jms.Session.mqjmsra] [tid: _ThreadID=178 _ThreadName=Camel (camel-2) thread #7 - JmsConsumer[GreenQueue]] [timeMillis: 1407483361027] [levelValue: 900] [[
  MQJMSRA_DS4001: getTransacted()Session is closed:Id=8349471074929591808]]

[2014-08-08T09:36:03.027+0200] [glassfish 4.0] [WARNING] [] [javax.jms.Session.mqjmsra] [tid: _ThreadID=181 _ThreadName=Camel (camel-2) thread #10 - JmsConsumer[GreenQueue]] [timeMillis: 1407483363027] [levelValue: 900] [[
  MQJMSRA_DS4001: getTransacted()Session is closed:Id=8349471074929591809]]

[2014-08-08T09:36:03.029+0200] [glassfish 4.0] [WARNING] [] [javax.jms.Session.mqjmsra] [tid: _ThreadID=191 _ThreadName=Camel (camel-2) thread #20 - JmsConsumer[RedQueue]] [timeMillis: 1407483363029] [levelValue: 900] [[
  MQJMSRA_DS4001: getTransacted()Session is closed:Id=8349471074929595649]]

[2014-08-08T09:36:03.031+0200] [glassfish 4.0] [WARNING] [] [javax.jms.Connection.mqjmsra] [tid: _ThreadID=183 _ThreadName=Camel (camel-2) thread #12 - JmsConsumer[RedQueue]] [timeMillis: 1407483363031] [levelValue: 900] [[
  MQJMSRA_DC2001: connectionId=8349471074926054656:_setClientID():JMSService.setClientId():JMSServiceException=setClientId: set client ID failed. Connection ID: 8349471074926054656, Client ID: MyID, Shareable: false, nameSpace: null Caused by:com.sun.messaging.jmq.jmsserver.util.BrokerException: conflict w/ clientID]]

[2014-08-08T09:36:03.031+0200] [glassfish 4.0] [INFO] [] [org.apache.camel.component.jms.DefaultJmsMessageListenerContainer] [tid: _ThreadID=183 _ThreadName=Camel (camel-2) thread #12 - JmsConsumer[RedQueue]] [timeMillis: 1407483363031] [levelValue: 800] [[
  Successfully refreshed JMS Connection]]

[2014-08-08T09:36:03.035+0200] [glassfish 4.0] [WARNING] [] [javax.jms.Connection.mqjmsra] [tid: _ThreadID=185 _ThreadName=Camel (camel-2) thread #14 - JmsConsumer[RedQueue]] [timeMillis: 1407483363035] [levelValue: 900] [[
  MQJMSRA_DC4001: createSession():An active Session object already exists for this connection, only one active Session object allowed per connection.]]

[2014-08-08T09:36:03.036+0200] [glassfish 4.0] [WARNING] [] [javax.jms.Connection.mqjmsra] [tid: _ThreadID=190 _ThreadName=Camel (camel-2) thread #19 - JmsConsumer[RedQueue]] [timeMillis: 1407483363036] [levelValue: 900] [[
  MQJMSRA_DC4001: createSession():An active Session object already exists for this connection, only one active Session object allowed per connection.]]

[2014-08-08T09:36:03.035+0200] [glassfish 4.0] [WARNING] [] [javax.jms.Connection.mqjmsra] [tid: _ThreadID=184 _ThreadName=Camel (camel-2) thread #13 - JmsConsumer[RedQueue]] [timeMillis: 1407483363035] [levelValue: 900] [[
  MQJMSRA_DC4001: createSession():An active Session object already exists for this connection, only one active Session object allowed per connection.]]

[2014-08-08T09:36:03.035+0200] [glassfish 4.0] [WARNING] [] [javax.jms.Connection.mqjmsra] [tid: _ThreadID=188 _ThreadName=Camel (camel-2) thread #17 - JmsConsumer[RedQueue]] [timeMillis: 1407483363035] [levelValue: 900] [[
  MQJMSRA_DC4001: createSession():An active Session object already exists for this connection, only one active Session object allowed per connection.]]

[2014-08-08T09:36:03.035+0200] [glassfish 4.0] [WARNING] [] [javax.jms.Connection.mqjmsra] [tid: _ThreadID=189 _ThreadName=Camel (camel-2) thread #18 - JmsConsumer[RedQueue]] [timeMillis: 1407483363035] [levelValue: 900] [[
  MQJMSRA_DC4001: createSession():An active Session object already exists for this connection, only one active Session object allowed per connection.]]

[2014-08-08T09:36:03.035+0200] [glassfish 4.0] [WARNING] [] [javax.jms.Connection.mqjmsra] [tid: _ThreadID=192 _ThreadName=Camel (camel-2) thread #21 - JmsConsumer[RedQueue]] [timeMillis: 1407483363035] [levelValue: 900] [[
  MQJMSRA_DC4001: createSession():An active Session object already exists for this connection, only one active Session object allowed per connection.]]

[2014-08-08T09:36:03.035+0200] [glassfish 4.0] [WARNING] [] [javax.jms.Connection.mqjmsra] [tid: _ThreadID=187 _ThreadName=Camel (camel-2) thread #16 - JmsConsumer[RedQueue]] [timeMillis: 1407483363035] [levelValue: 900] [[
  MQJMSRA_DC4001: createSession():An active Session object already exists for this connection, only one active Session object allowed per connection.]]

[2014-08-08T09:36:07.025+0200] [glassfish 4.0] [WARNING] [] [javax.jms.Session.mqjmsra] [tid: _ThreadID=179 _ThreadName=Camel (camel-2) thread #8 - JmsConsumer[GreenQueue]] [timeMillis: 1407483367025] [levelValue: 900] [[
  MQJMSRA_DS4001: getTransacted()Session is closed:Id=8349471074929592064]]

[2014-08-08T09:36:07.025+0200] [glassfish 4.0] [INFO] [] [org.apache.camel.component.jms.DefaultJmsMessageListenerContainer] [tid: _ThreadID=177 _ThreadName=Camel (camel-2) thread #6 - JmsConsumer[GreenQueue]] [timeMillis: 1407483367025] [levelValue: 800] [[
  Successfully refreshed JMS Connection]]

....等等,直到我停止服务器。

我首先尝试使用Glassfish4提供的默认ConnectionFactory,然后使用此xml配置文件另一个:

<resources> ... <connector-resource enabled="true" jndi-name="jms/DurableConnectionFactory" object-type="user" pool-name="jms/DurableConnectionFactory-Connection-Pool"> <description/> </connector-resource> <connector-connection-pool associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-definition-name="javax.jms.ConnectionFactory" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="true" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="jms/DurableConnectionFactory-Connection-Pool" ping="false" pool-resize-quantity="2" pooling="true" resource-adapter-name="jmsra" steady-pool-size="8" validate-atmost-once-period-in-seconds="0"> <property name="ClientId" value="MyID"/> </connector-connection-pool> </resources>

并将其注入我的应用中:

@Resource(lookup = "jms/DurableConnectionFactory")
private ConnectionFactory connectionFactory;

0 个答案:

没有答案