Could you try:

<camelContext xmlns="http://camel.apache.org/schema/spring";>
  <route id="routeOne">
    <from uri="timer://myTimer?fixedRate=true&amp;period=5s" />
    <to uri="activemq:queue:routeTwo" />
  </route>

  <route id="routeTwo">
    <from uri="activemq:queue:routeTwo" />
    <bean ref="myBean" method="print" />
    <setExchangePattern pattern="InOut"/>
    <enrich uri="activemq:queue:enrichTest" strategyRef="myEnrichStrategy"/>
    <bean ref="myBean" method="printAfterEnrich" />
  </route>

  <route id="routeThree">
    <from uri="activemq:queue:enrichTest" />
    <bean ref="myBean" method="enrich" />
  </route>
</camelContext>

By default, the timer component use the InOnly message exchange pattern
(MEP). This means the message which is send to "activemq:queue:enrichTest"
will not produce a response the enricher is waiting for. Have a look at [1].

[1] http://camel.apache.org/request-reply.html

Best

Christian
-----------------

Software Integration Specialist

Apache Member
V.P. Apache Camel | Apache Camel PMC Member | Apache Camel committer
Apache Incubator PMC Member

https://www.linkedin.com/pub/christian-mueller/11/551/642


On Thu, Oct 24, 2013 at 8:29 AM, ak-dak <ku...@dakosy.de> wrote:

> Hi,
>
> I have a simple example which works as expected:
>
> -----------------------------------------------------------------------------------
> *Camel-Routes:*
> <beans ...>
>        <bean id="myBean" class="de.mycompany.activemq.MyBean" />
>         <bean id="myEnrichStrategy"
> class="de.mycompany.activemq.MyEnrichStrategy"/>
>
>         <camelContext xmlns="http://camel.apache.org/schema/spring";>
>
> <route id="routeOne">
>                         <from
> uri="timer://myTimer?fixedRate=true&amp;period=5s" />
>                         <bean ref="myBean" method="print" />
>                         <enrich uri="activemq:queue:enrichTest"
> strategyRef="myEnrichStrategy"/>
>                         <bean ref="myBean" method="printAfterEnrich" />
>                 </route>
>
>                 <route id="routeTwo">
>                         <from uri="activemq:queue:enrichTest" />
>                         <bean ref="myBean" method="enrich" />
>                 </route>
>
>         </camelContext>
> </beans>
>
> *Bean-Class:*
> public class MyBean {
>
>         public void print(Exchange exchange) {
>                 System.out.println("start");
>                 exchange.getOut().setBody("beforeEnrich: ");
>         }
>
>         public void enrich(Exchange exchange) {
>                 System.out.println("enrich");
>
>                 exchange.getOut().setBody("enrich-body");
>         }
>
>         public void printAfterEnrich(Exchange exchange) {
>                 System.out.println("printAfterEnrich-body: " +
> exchange.getIn().getBody());
>         }
> }
>
> *Enricher-Class:*
> public class MyEnrichStrategy implements AggregationStrategy {
>
>         @Override
>         public Exchange aggregate(Exchange original, Exchange resource) {
>                 String originalBody =
> original.getIn().getBody(String.class);
>                 String resourceResponse =
> resource.getIn().getBody(String.class);
>
>                 originalBody += resourceResponse;
>                 original.getIn().setBody(originalBody);
>
>                 return original;
>         }
> }
>
>
> -----------------------------------------------------------------------------------
>
> But if I separate the routes with activeMq it doesn't works anymore.
> Thats are not working camel routes:
>
> <camelContext xmlns="http://camel.apache.org/schema/spring";>
>
>                 <route id="routeOne">
>                         <from
> uri="timer://myTimer?fixedRate=true&amp;period=5s" />
>                         <to uri="activemq:queue:routeTwo" />
>                 </route>
>
>                 <route id="routeTwo">
>                         <from uri="activemq:queue:routeTwo" />
>                         <bean ref="myBean" method="print" />
>                         <enrich uri="activemq:queue:enrichTest"
> strategyRef="myEnrichStrategy"/>
>                         <bean ref="myBean" method="printAfterEnrich" />
>                 </route>
>
>                 <route id="routeThree">
>                         <from uri="activemq:queue:enrichTest" />
>                         <bean ref="myBean" method="enrich" />
>                 </route>
>
>         </camelContext>
>
> I got a time out exception:
>
> 08:27:08,236 WARN
> [org.apache.camel.component.jms.reply.TemporaryQueueReplyManager] Timeout
> occurred after 20000 millis waiting for reply message with correlationID
> [ID-P00563-49858-1382595520631-4-17]. Setting ExchangeTimedOutException on
> (MessageId: ID-P00563-49858-1382595520631-4-16 on ExchangeId:
> ID-P00563-49858-1382595520631-4-22) and continue routing.
> 08:27:08,236 ERROR [org.apache.camel.processor.DefaultErrorHandler] Failed
> delivery for (MessageId: ID-P00563-49858-1382595520631-4-16 on ExchangeId:
> ID-P00563-49858-1382595520631-4-15). Exhausted after delivery attempt: 1
> caught: org.apache.camel.ExchangeTimedOutException: The OUT message was not
> received within: 20000 millis due reply message with correlationID:
> ID-P00563-49858-1382595520631-4-17 not received.
> Exchange[JmsMessage@0x1997f541]:
> org.apache.camel.ExchangeTimedOutException:
> The OUT message was not received within: 20000 millis due reply message
> with
> correlationID: ID-P00563-49858-1382595520631-4-17 not received.
> Exchange[JmsMessage@0x1997f541]
>         at
>
> org.apache.camel.component.jms.reply.ReplyManagerSupport.processReply(ReplyManagerSupport.java:133)
> [camel-jms-2.10.1.jar:2.10.1]
>         at
>
> org.apache.camel.component.jms.reply.TemporaryQueueReplyHandler.onTimeout(TemporaryQueueReplyHandler.java:61)
> [camel-jms-2.10.1.jar:2.10.1]
>         at
>
> org.apache.camel.component.jms.reply.CorrelationTimeoutMap.onEviction(CorrelationTimeoutMap.java:53)
> [camel-jms-2.10.1.jar:2.10.1]
>         at
>
> org.apache.camel.component.jms.reply.CorrelationTimeoutMap.onEviction(CorrelationTimeoutMap.java:30)
> [camel-jms-2.10.1.jar:2.10.1]
>         at
>
> org.apache.camel.support.DefaultTimeoutMap.purge(DefaultTimeoutMap.java:203)
> [camel-core-2.10.0.jar:2.10.0]
>         at
> org.apache.camel.support.DefaultTimeoutMap.run(DefaultTimeoutMap.java:159)
> [camel-core-2.10.0.jar:2.10.0]
>         at
> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
> [rt.jar:1.7.0_13]
>         at
> java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:351)
> [rt.jar:1.7.0_13]
>         at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:178)
> [rt.jar:1.7.0_13]
>         at
>
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
> [rt.jar:1.7.0_13]
>         at
>
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
> [rt.jar:1.7.0_13]
>         at
>
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
> [rt.jar:1.7.0_13]
>         at
>
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
> [rt.jar:1.7.0_13]
>         at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_13]
>
> 08:27:08,236 WARN  [org.apache.camel.component.jms.EndpointMessageListener]
> Execution of JMS message listener failed. Caused by:
> [org.apache.camel.RuntimeCamelException -
> org.apache.camel.ExchangeTimedOutException: The OUT message was not
> received
> within: 20000 millis due reply message with correlationID:
> ID-P00563-49858-1382595520631-4-17 not received.
> Exchange[JmsMessage@0x1997f541]]: org.apache.camel.RuntimeCamelException:
> org.apache.camel.ExchangeTimedOutException: The OUT message was not
> received
> within: 20000 millis due reply message with correlationID:
> ID-P00563-49858-1382595520631-4-17 not received.
> Exchange[JmsMessage@0x1997f541]
>         at
>
> org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1280)
> [camel-core-2.10.0.jar:2.10.0]
>         at
>
> org.apache.camel.component.jms.EndpointMessageListener$EndpointMessageListenerAsyncCallback.done(EndpointMessageListener.java:187)
> [camel-jms-2.10.1.jar:2.10.1]
>         at
>
> org.apache.camel.component.jms.EndpointMessageListener.onMessage(EndpointMessageListener.java:108)
> [camel-jms-2.10.1.jar:2.10.1]
>         at
>
> org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:560)
> [spring-jms-3.0.7.RELEASE.jar:3.0.7.RELEASE]
>         at
>
> org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:498)
> [spring-jms-3.0.7.RELEASE.jar:3.0.7.RELEASE]
>         at
>
> org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:467)
> [spring-jms-3.0.7.RELEASE.jar:3.0.7.RELEASE]
>         at
>
> org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:325)
> [spring-jms-3.0.7.RELEASE.jar:3.0.7.RELEASE]
>         at
>
> org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:243)
> [spring-jms-3.0.7.RELEASE.jar:3.0.7.RELEASE]
>         at
>
> org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1058)
> [spring-jms-3.0.7.RELEASE.jar:3.0.7.RELEASE]
>         at
>
> org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1050)
> [spring-jms-3.0.7.RELEASE.jar:3.0.7.RELEASE]
>         at
>
> org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:947)
> [spring-jms-3.0.7.RELEASE.jar:3.0.7.RELEASE]
>         at
>
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
> [rt.jar:1.7.0_13]
>         at
>
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
> [rt.jar:1.7.0_13]
>         at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_13]
> Caused by: org.apache.camel.ExchangeTimedOutException: The OUT message was
> not received within: 20000 millis due reply message with correlationID:
> ID-P00563-49858-1382595520631-4-17 not received.
> Exchange[JmsMessage@0x1997f541]
>         at
>
> org.apache.camel.component.jms.reply.ReplyManagerSupport.processReply(ReplyManagerSupport.java:133)
> [camel-jms-2.10.1.jar:2.10.1]
>         at
>
> org.apache.camel.component.jms.reply.TemporaryQueueReplyHandler.onTimeout(TemporaryQueueReplyHandler.java:61)
> [camel-jms-2.10.1.jar:2.10.1]
>         at
>
> org.apache.camel.component.jms.reply.CorrelationTimeoutMap.onEviction(CorrelationTimeoutMap.java:53)
> [camel-jms-2.10.1.jar:2.10.1]
>         at
>
> org.apache.camel.component.jms.reply.CorrelationTimeoutMap.onEviction(CorrelationTimeoutMap.java:30)
> [camel-jms-2.10.1.jar:2.10.1]
>         at
>
> org.apache.camel.support.DefaultTimeoutMap.purge(DefaultTimeoutMap.java:203)
> [camel-core-2.10.0.jar:2.10.0]
>         at
> org.apache.camel.support.DefaultTimeoutMap.run(DefaultTimeoutMap.java:159)
> [camel-core-2.10.0.jar:2.10.0]
>         at
> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
> [rt.jar:1.7.0_13]
>         at
> java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:351)
> [rt.jar:1.7.0_13]
>         at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:178)
> [rt.jar:1.7.0_13]
>         at
>
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
> [rt.jar:1.7.0_13]
>         at
>
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
> [rt.jar:1.7.0_13]
>         ... 3 more
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/ActiveMq-InOut-save-exchange-body-tp5741975p5742113.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Reply via email to