Question

I have a JMS queue with multiple consumers. I am trying with following camel route,

<camel:camelContext id="camel-server">
        <camel:package>com.camlin.consumer</camel:package>

        <camel:route id="one">
            <camel:from uri="jms:queue:request" />
            <camel:choice>
                <camel:when>
                    <camel:simple>${header.type} == '1'</camel:simple>
                    <camel:to uri="bean:consumerBean?method=receive1" />
                </camel:when>
            </camel:choice>
        </camel:route>

        <camel:route id="two">
            <camel:from uri="jms:queue:request" />
            <camel:choice>
                <camel:when>
                    <camel:simple>${header.type} == '2'</camel:simple>
                    <camel:to uri="bean:consumerBean?method=receive2" />
                </camel:when>
            </camel:choice>
        </camel:route>

    </camel:camelContext>

Messages are sent as,

producer.sendBodyAndHeader("Hello from Producer-1", "type", "1");
producer.sendBodyAndHeader("Hello from Producer-2", "type", "2");

Only first message is consumed. The second message never reaches to consumerBean as per the route. Q1. Any missing configuration here?

I want to have multiple routes, because I need to add/remove routes dynamically. So having a single route with multiple choice is not suitable here.

Q2. When camel inspects a message by header whether it is removed from the queue? So that it is not available to other route? UPDATE: Refer http://fusesource.com/docs/router/2.5/eip/MsgEnd-Selective.html. The filters work by consuming messages. So selector is only the option.

Was it helpful?

Solution

If you want all your routes (consumers) to receive all messages, then you need to subscribe to a topic. A message on a queue can only be consumed once. A message on a topic is delivered to all subscribed consumers.

If you want to use queues you can use JMS selectors. However, the selector is an endpoint option, which you have not set in your code snippet.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top