我在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
我通过创建一个模拟EXT.OUT队列来测试流程的其余部分,该队列只生成XML并返回它。
我想知道如何指定它以等待在上面的步骤#4和#5之间发送到EXT.IN队列的响应?
非常感谢任何帮助。谢谢!
答案 0 :(得分:0)
使用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!