2
votes

I have a problem where I want to let Camel-RabbitMq consume from my own defined queues. Writing and reading from queues via Camel routes works but only via camels own defined queues. I cannot seem to point Camel to my defined queues on RabbitMQ.

Essential information

I'm running camel version & camel-rabbitmq V3.3.0 via Spring boot V2.3.0.RELEASE. I have 2 services running on my localhost:

  • on localhost:5672 a RabbitMq v3.8.3 instance
  • on localhost:15672 a RabbitMq management instance

I run these instances via a simple docker-compose file:

version: '3'
services:
  rabbitmq:
    image: "rabbitmq:3.8.3"
    ports:
      - "5672:5672"
  rabbitmq-management:
    image: "rabbitmq:3-management"
    ports:
      - "15672:15672"

On there I have created 1 exchange and 1 queue via the admin panel:

  • main_exchange
  • in_queue

Main_exchange and in_queue are binded to each other via routing key "in_queue_routing_key" routing key.

Problem

Now when I try to connect to read from this in_queue via a camel route:

from("rabbitmq:main_exchange?addresses=localhost:5672" +
            "&passive=true"+
            "&autoDelete=false" +
            "&declare=false" +
            "&queue=in_queue" +
            "&routingKey=in_queue_routing_key")
    .log("received from queue")
.to("file:done");

When I publish a message to the in_queue via the main exchange, nothing happens. The Camel route does not pick up the message.

I tried following possible solutions:

  • Setting passive to true, so RabbitMq doesn't make the queue itself.

    Passive queues depend on the queue already to be available at RabbitMQ.

  • Setting declare to false, so RabbitMq does not declare the exchange and queue itself.

    If the option is true, camel declare the exchange and queue name and bind them together. If the option is false, camel won’t declare the exchange and queue name on the server.

  • Writing to the queue worked, But this didn't show up in the self defined "in-queue" via admin console:

Code example:

from("file:test")
    .log("add to route")
.to("rabbitmq:main_exchange?addresses=localhost:5672" +
            "&passive=true"+
            "&autoDelete=false" +
            "&declare=false" +
            "&queue=in_queue" +
            "&routingKey=in_queue_routing_key");

But the consumer route did pick up after restarting the consumer route (the one above this code example).

So it looks like the Camel-RabbitMq route defines it's queue elsewhere. How can I define that the Camel route consumes on my own defined queues and not on his own?

Sources:

2

2 Answers

2
votes

It looks like I found the mistake, Rabbitmq has a management + instance image and NOT a standalone management image. This resulted in running 2 instances of RabbitMQ, one that I was polling and looking at and the second one where the operations happen resulting in me not finding anything but the application still working.

This is my docker-compose file now:

version: '3'
services:
  rabbitmq-with-management:
    image: "rabbitmq:3-management"
    ports:
      - "5672:5672"
      - "15672:15672"

Everything works as expected now.

1
votes

This answer had a similar problem and the exact match of properties was the problem.

So if your connection string does not exactly match the properties of the predefined queue, Camel "does not find" it and creates an own instead. Differences can be hidden in default values of the Camel consumer.

In the mentioned answer the difference was the autoDelete flag. It seems to be true by default in Camel and when it is false on your Rabbit queue there is no match.

They had to add &autoDelete=false to the connection string to match the predefined queue.

Perhaps you also have a "property matching problem" with the predefined queue.