Does Apache Camel support activemq wildcards?

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

According to activemq documentation, it supports wildcards .

I use a camel as a messaging bus. You can see below named queues

aaa.processQueue bbb.processQueue ccc.processQueue 

Configuring a camel route to view the activemq:*.processQueue ?

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

+5
source share
3 answers

Yes. This should be doable since Camel uses the OpenWire / JMS client.

Your options:

  • from("activemq:*.processQueue")
  • from("activemq:aaa.processQueue,bbb.processQueue,ccc.processQueue")
  • Several routes with a logical approach:

     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.. 

    Thus, you can easily enable / disable routes, as well as assign more consumers to one, given that you need more priorities on aaa.processQueue messages than others.

+5
source

They have an example on github of a route builder 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(); } }; } 

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

0
source

Source: https://habr.com/ru/post/1200447/


All Articles