Apache Camel消息交换不等待响应

时间:2018-06-26 05:22:48

标签: apache-camel activemq

我有以下代码用于将消息发布到activeMQ并通过交换读取响应。但是代码似乎是在瞬间返回而不是等待响应。您能否指出以下Scala代码有什么问题?

def sendAndReceiveExtractionDetails(request:String, header: String) : String = {
    val exchange: DefaultExchange = new DefaultExchange(camel, ExchangePattern.InOut)
    exchange.getIn.setBody(request)
    exchange.getIn.setHeader("meshId", header)
    producer.send("activemq:queue:extractor-jobs?requestTimeout=1400000", exchange)
    val out: apache.camel.Message = exchange.getOut()
    out.getBody().toString
}

3 个答案:

答案 0 :(得分:0)

似乎忽略了您设置的ExchangePattern。您是否尝试过在JMS URI上将其设置为activemq:queue:...&exchangePattern=InOut

我不确定您是否还需要在消息上定义JMSReplyTo标头,还是在exchangePattern为InOut时自动完成标头。

答案 1 :(得分:0)

在生产者上使用const bar = (baz) => { console.log(baz); }; const foo = (args) => { const { url, options, header, body, auth = 1 } = args; // Do stuff with url, options, header, body and auth... bar({ ...args, auth }); }; foo({ url: 'www.google.com', options: {}, header: {}, body: 'Hi there!' }); foo({ url: 'www.google.com', options: {}, header: {}, body: 'Hi there!', auth: false });的{​​{1}}方法

答案 2 :(得分:0)

以下代码对我有用:

  def sendAndReceiveExtractionDetails(request:String, header: String) : String = {
    camel.createProducerTemplate()
      .sendBody("activemq:queue:extractor-jobs?requestTimeout=1400000", ExchangePattern.InOut, request).toString
  }