是否可以在骆驼的rabbitmq组件中添加replyTo队列?

时间:2019-05-22 15:07:02

标签: rabbitmq apache-camel

我想通过RabbitMQ在Apache骆驼上实现请求-答复模式。为此,我创建了一个队列(myQueue),我将在其中发送一些消息并等待对另一个队列(repQueue)的答复。 为此,我创建了一条如下所示的路线。

from("direct:reqReply")
    .setHeader("rabbitmq.REPLY_TO", simple("repQueue"))
    .to("rabbitmq://localhost:5672/ex4?queue=myQueue&autoDelete=false");

为了提供此消息,我在另一个应用程序中有另一条路由,该路由使用来自myQueue的消息,并在按如下所示进行处理之后将消息发送到repQueue。

from("rabbitmq://localhost:5672/ex4?queue=myQueue&autoDelete=false")
    .process(new Processor() {
        public void process(Exchange ex) throws Exception {
            String val = new String((byte[]) ex.getIn().getBody());
            val = val.toUpperCase();
            ex.getIn().setBody(val);
        }
    })
    .to("rabbitmq://localhost:5672/ex4?queue=repQueue&autoDelete=false");

因此,当我向myQueue发送任何消息时,如下所示,

String resp = template.requestBody("direct:reqReply", "first message", String.class);

响应未到并收到异常org.apache.camel.ExchangeTimedOutException:在以下范围内未接收到OUT消息:20000毫秒到期,相关消息的响应消息:Camel-ID-PC-51756-1558533236655-0-2到达目的地:amq.gen-Wbb9ObprY_7Gq-eqac44ZQ。

我已经在此处检查了来源:https://github.com/apache/camel/tree/master/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq 并在RabbitMQEndpoint类中找到以下内容。

// camel-jms supports this setting but it is not currently configurable in camel-rabbitmq
    private String replyToType = ReplyToType.Temporary.name();
    // camel-jms supports this setting but it is not currently configurable in camel-rabbitmq
    private String replyTo;

我在RabbitMQProducer类中发现了以下内容

if (getEndpoint().getReplyTo() != null) {
    // specifying reply queues is not currently supported
    throw new IllegalArgumentException("Specifying replyTo " + getEndpoint().getReplyTo() + " is currently not supported.");
 } else {
  replyManager = createReplyManager();
  log.debug("Using RabbitMQReplyManager: {} to process replies from temporary queue", replyManager);
 }

因此是否可以在rabbitmq组件中添加replyTo队列(不是临时队列)?

0 个答案:

没有答案