Avoid automatic binding with RabbitMQ and Camel

萝らか妹 提交于 2020-01-06 02:40:10

问题


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.


回答1:


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.




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/27550496/avoid-automatic-binding-with-rabbitmq-and-camel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!