【问题标题】:Generating SOAP response in Camel在 Camel 中生成 SOAP 响应
【发布时间】:2014-04-14 00:33:05
【问题描述】:

我在 Camel(使用 cxf)中创建了一个 Web 服务流,它公开了一个简单的 Web 服务。但是,它需要与外部系统集成,该系统将 SOAP 请求的一部分作为 XML (EXT.OUT quque) 并通过 XML (EXT.IN 队列进行响应) 如下图所示。

我无法控制外部系统的行为,但我想确保根据我从 EXT.IN 队列获得的响应生成 SOAP 响应(即来自 XML)。

到目前为止,我的流程如下:

from("cxf:bean:myCamelWSEndpoint") // #1
  .transform().simple("${in.body[0]}") // #2 get Body object
  .process(soapToXmlProcessorRef) // #3 Processor that sets the exchange.out.body to some xml snippet
  .to(ExchangePattern.InOut, "activemq:queue:EXT.OUT") // #4 sends XML to EXT.OUT queue
  .process(xmlToSoapProcessorRef) // #5 Processor that generates SOAP response object from incoming XML snippet

我通过创建一个简单地生成 XML 并返回它的模拟 EXT.OUT 队列来测试我的流程的其余逻辑。

我想知道如何指定它以等待在上述步骤 #4 和 #5 之间发送到 EXT.IN 队列的响应?

非常感谢任何帮助。谢谢!

【问题讨论】:

  • 如果您收到响应或发生超时(默认为 20 秒),该路由将在步骤 #5 中继续处理您的交换。据我了解,它已经做了你想要的。

标签: jms apache-camel activemq


【解决方案1】:

使用pollEnrich("activemq:queue:EXT.IN")。

简化的测试路线:

from("activemq:queue:EXT.OUT")
    .log("Received message from EXT.OUT and sent it to EXT.IN: ${body}")
    .setBody(constant("I was on the moon!"))
    .to("activemq:queue:EXT.IN");

from("direct:start")
    .log("Send message to EXT.OUT")
    .to("activemq:queue:EXT.OUT") // sends XML to EXT.OUT queue
    .log("Wait until message from EXT.IN is received and enrich")
    .pollEnrich("activemq:queue:EXT.IN")
    .log("Finally: ${body}");

开始路线:

final ProducerTemplate template = context.createProducerTemplate();
template.sendBody("direct:start", "Hello, World!");

输出应该如下:

[                          main] route2 INFO  Send message to EXT.OUT
[                          main] route2 INFO  Wait until message from EXT.IN is received and enrich
[read #0 - JmsConsumer[EXT.OUT]] route1 INFO  Received message from EXT.OUT and sent it to EXT.IN: Hello, World!
[                          main] route2 INFO  Finally: I was on the moon!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-08
    • 1970-01-01
    • 2023-03-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多