Dzmitry
Dzmitry

Reputation: 87

Camel routing not working as expected

I try to create a very simple route between one rabbit queue and another one. Message should go with no processing from one queue to the second. But for unknown reason the message is redirected to the first queue again and again instead of going to the second one.

@Component
public class CamelRouter extends SpringRouteBuilder {
    @Override
    public void configure() {
        from("rabbitmq://localhost/test-in?autoAck=false&autoDelete=false&durable=true&exchangeType=fanout&queue=test-in&username=guest&password=xxx")
        .log(LoggingLevel.ERROR, "Output of message from Queue: ${in.body}")
        .to("rabbitmq://localhost/test-out?autoAck=false&autoDelete=false&durable=true&exchangeType=fanout&queue=test-out&username=guest&password=xxx");
    }
}

The logs are following:

09:04:18.564 [thread] WARN  route1                                     - Output of message from Queue: test
09:04:18.700 [thread] WARN  route1                                     - Output of message from Queue: test
09:04:18.835 [thread] WARN  route1                                     - Output of message from Queue: test
09:04:18.968 [thread] WARN  route1                                     - Output of message from Queue: test
09:04:19.104 [thread] WARN  route1                                     - Output of message from Queue: test
09:04:19.238 [thread] WARN  route1                                     - Output of message from Queue: test

What is wrong is this camel configuration? It's as simple as possible in my opinion.

Upvotes: 2

Views: 2068

Answers (2)

stringy05
stringy05

Reputation: 7067

Instead of removing the headers, it's better to use the out message on the exchange as shown below. In this particular example the rabbitmq prefix is probably ok, however if you try this approach with other components (imap is a great example) it wont work for all sorts of strange reasons.

    from("rabbitmq://localhost/test-in?autoAck=false&autoDelete=false&durable=true&exchangeType=fanout&queue=test-in&username=guest&password=xxx")
        .log(LoggingLevel.ERROR, "Output of message from Queue: ${in.body}")
        .process(new Processor() {

            @Override
            public void process(Exchange exchange) throws Exception {
                exchange.getOut().setBody(exchange.getIn().getBody());                  
            }
        })
        .to("rabbitmq://localhost/test-out?autoAck=false&autoDelete=false&durable=true&exchangeType=fanout&queue=test-out&username=guest&password=xxx");

Upvotes: 2

cslysy
cslysy

Reputation: 830

Please try this:

@Component
public class CamelRouter extends SpringRouteBuilder {
    @Override
    public void configure() {
        from("rabbitmq://localhost/test-in?autoAck=false&autoDelete=false&durable=true&exchangeType=fanout&queue=test-in&username=guest&password=xxx")
        .removeHeaders("rabbitmq.*")
        .log(LoggingLevel.ERROR, "Output of message from Queue: ${in.body}")
        .to("rabbitmq://localhost/test-out?autoAck=false&autoDelete=false&durable=true&exchangeType=fanout&queue=test-out&username=guest&password=xxx");
    }
}

Camel supports overriding some setting like the queue from the message header (and RabbitMq component does this), so we need to remove them in order to avoid sending the message back to the source queue. Complete list of rabitmq headers can be found there. I guess that "rabbitmq.REPLY_TO" header is the problematic ones.

Upvotes: 0

Related Questions