Morten Knudsen
Morten Knudsen

Reputation: 45

Avoid automatic binding with RabbitMQ and Camel

I'm trying to use RabbitMQ with Camel. I am using Camel 2.14.1.

I want to open an fanout exchange on RabbitMQ and then later bind queues to it. This seems to work fine. However, everytime I create an Exchange, it is automatically bound to queue with a system name (a number). Can't I avoid that? Here is a simple example which posts 100 messages to an Exchange. But they get delivered to an automatically created queue, I want to avoid this.

  @Override
  public void configure() throws Exception
  {
    final String testGUID = "xxxx";
    from("timer://publish?repeatCount=100&period=10&fixedRate=true").process(new Processor()
            //from("timer://publish?repeatCount=100&period=1&fixedRate=true").process(new Processor()

    {
      @Override
      public void process(Exchange _exchange) throws Exception
      {
        String message = String.valueOf(_exchange.getProperty(Exchange.TIMER_COUNTER));
        _exchange.getOut().setBody(message+testGUID);
      }
    })
            .to("rabbitmq://localhost/exchange=logs1237?autoDelete=false&username=guest&password=guest&exchangeType=fanout");

  }

Best regards, Morten Knudsen

UPDATE: It seems from looking at the source, that the triggering of the automatic queue happens if "queue" in RabbitMQEndPoint is not null. But "queue" is automatically assigned to "String.valueOf(UUID.randomUUID().toString().hashCode());" at construction.

Upvotes: 2

Views: 1962

Answers (3)

Serhat
Serhat

Reputation: 638

As Bal has already described here add "declare=false" to your RabbitMQ URI. This should solve your problem. Optionally, you can also use "skipQueueDeclare=true&skipQueueBind=true" this properties in your URI as well.

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

skipQueueDeclare: If true the producer will not declare and bind a queue. This can be used for directing messages via an existing routing key.

skipQueueBind: If true the queue will not be bound to the exchange after declaring it

You can reach out all the properties you can use in Camel for RabbitMQ here.

Upvotes: 2

From Camel 2.16.1 on, there's a new option for the rabbitmq component, skipQueueDeclare, which properly solves this issue.

Upvotes: 1

Willem Jiang
Willem Jiang

Reputation: 3291

If you don't want to bind the exchange with queue, you can setup the declare option to be false. BTW, declare option is new added since Camel 2.14.0.

Upvotes: 4

Related Questions