Dhananjay
Dhananjay

Reputation: 3975

Does Apache Camel supports activemq wildcard consumers?

I need a way to consume messages from multiple activemq jms queues.

As per activemq documentation, it supports wildcard consumers

I am using camel as a messaging bus.Is it possible to look at below named queues

aaa.processQueue
bbb.processQueue
ccc.processQueue

By configuring camel route to look at activemq:*.processQueue endpoint?

Also let me know, if there is more cleaner alternative for this.

Upvotes: 5

Views: 1845

Answers (2)

joecoder
joecoder

Reputation: 335

They have an example on their github of a routebuilder using wildcards:

protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        public void configure() throws Exception {
            // use wildcard to consume from all sports
            from("activemq:queue:sport.>")
                .to("log:received?showHeaders=true")
                .choice()
                    // the JMSDestination contains from which queue the message was consumed from
                    .when(header("JMSDestination").isEqualTo("queue://sport.pl.chelsea"))
                        .to("mock:chelsea")
                    // we can use a reg exp to match any message from 1st division
                    .when(header("JMSDestination").regex("queue://sport.1st.*"))
                        .to("mock:1st")
                    .otherwise()
                        .to("mock:other")
                .end();
        }
    };
}

Ref: https://github.com/apache/camel/blob/master/components/camel-jms/src/test/java/org/apache/camel/component/jms/activemq/ActiveMQConsumeWildcardQueuesTest.java

Upvotes: 0

Petter Nordlander
Petter Nordlander

Reputation: 22279

Yes. It should be doable as Camel is using the OpenWire/JMS client.

Your options are:

  1. from("activemq:*.processQueue")
  2. from("activemq:aaa.processQueue,bbb.processQueue,ccc.processQueue")
  3. Multiple routes with a sub route for logic:

    from("activemq:aaa.processQueue").to("direct:doProcess");
    from("activemq:bbb.processQueue").to("direct:doProcess");
    from("activemq:ccc.processQueue").to("direct:doProcess");
    
    from("direct:doProcess").whatever..
    

    This way, you can easily turn on/off routes as well as assigning more consumers to one, given you need to have more priority on aaa.processQueue messages than the rest.

Upvotes: 6

Related Questions