0

I have a camel route to consume a message from a JMS topic. When the route starts, and there is no message in the topic, I want to raise an exception and stop the process.

I'm using the JmsComponent from Apache Camel that use the DefaultMessageListenerContainer from Spring and is defined as transactional. The current behavior is that the route starts but it keeps waiting for a message indefinitely.

Is there any solution to check if the message exists and simply stop the route when absent?

1 Answers1

0

You need to define a time limit for which you wait for the message, and conclude that things have gone wrong.

Then, you use an aggregator with a completion timeout of (say) 30 seconds.

This way, if you go longer than 30 seconds without receiving a message on that topic then you can take whatever action you like.

from("mq:topic:xyz")
    .aggregate(constant(true), new TakeLastAggregationStrategy())
    .completionTimeout(30000)
    .to("direct:raiseException")
vikingsteve
  • 38,481
  • 23
  • 112
  • 156
  • Thanks for your reply! I was testing your solution but the route never reach the aggregate. It remains waiting for a message, in the from step. Any other idea? – Camel Dev Feb 23 '15 at 10:47
  • Ah, ok. We use this to monitor disconnection in a simple heartbeat mechanism. But we always rely on getting at least one message first. Thereafter, a break in the message stream of 30 seconds will trigger an exception via the code above. – vikingsteve Feb 23 '15 at 11:03