skip to Main Content

I have this scenario:

ADDRESS1:
   -ADDRESS1.QUEUE1
   -ADDRESS1.QUEUE2

ADDRESS2:
   -ADDRESS2.QUEUE1
   -ADDRESS2.QUEUE2

Two addresses with multiple anycast queues. I need to route messages to a specify queue into the address.

Example:

Messages on ADDRESS1::ADDRESS1.QUEUE1 goes to -> ADDRESS2::ADDRESS2.QUEUE1 
Messages on ADDRESS1::ADDRESS1.QUEUE2 goes to -> ADDRESS2::ADDRESS2.QUEUE2

This is my code:

CamelContext context = new DefaultCamelContext();
    ConnectionFactory factory = new ActiveMQConnectionFactory("admin", "admin", "tcp://0.0.0.0:61616");

    context.addComponent("artemis", JmsComponent.jmsComponentAutoAcknowledge(factory));

    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("artemis:ADDRESS1::ADDRESS1.QUEUE1")
            .log("${body}")
            .to("artemis:ADDRESS2::ADDRESS2.QUEUE1");
        }
    });

    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("artemis:ADDRESS1::ADDRESS1.QUEUE2")
            .log("${body}")
            .to("artemis:ADDRESS2::ADDRESS2.QUEUE2");
        }
    });

With this code I’m able only to consume messages from a specific queue. But “.to” doesn’t work.
Is there any way to do that?

I need to do that because I have many applications that are consumers, so I want to use address to separate the queues “by application”.

Like this:

APP1
   QUEUE1
   QUEUE2
   QUEUE3

Thanks in advance.

2

Answers


  1. Chosen as BEST ANSWER

    I think I found a solution, but I don't know if is the best one.

    I added filters on my destination queues:

        ADDRESS2:
           -ADDRESS2.QUEUE1 - Filter -> DESTIONATION = 'QUEUE1' 
           -ADDRESS2.QUEUE2 - Filter -> DESTIONATION = 'QUEUE2'
    

    And when I route the message with camel, I set a Header with a value, and .to() I set only the Address name:

        context.addRoutes(new RouteBuilder() {
    
            @Override
            public void configure() throws Exception {
                from("artemis:ADDRESS1::ADDRESS1.QUEUE1")
                .log("${body}")
                .setHeader("DESTINATION", constant("QUEUE1"))
                .to("artemis:ADDRESS2");
            }
        });
    
        context.addRoutes(new RouteBuilder() {
    
            @Override
            public void configure() throws Exception {
                from("artemis:ADDRESS1::ADDRESS1.QUEUE1")
                .log("${body}")
                .setHeader("DESTINATION", constant("QUEUE2"))
                .to("artemis:ADDRESS2");
            }
        });
    

    This works, but as I said, I don't know if is the best approach.


  2. Try to disable the “replyTo” on producer endpoints:

    .to("artemis:ADDRESS2::ADDRESS2.QUEUE1?disableReplyTo=true")
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search