4
votes

I'd like to route a webservice request to an InOnly endpoint of a jms queue. Then route a response jms message received from a separate InOnly endpoint back to the webservice client as the response. The webservice request/response is a synchronous InOut pattern, and the sub-routes are asynchronous. What options do I have to achieve this with Camel?

The Camel route here is used to explain my question:

String uri={webserice uri}
from(uri)    
    .process(new Processor() {
        public void process(Exchange exchange) throws Exception {
            ServcieRequest req =            
            exchange.getIn().getBody(ServcieRequest.class);                 
            // One option to me is to spawn another route here to route to jms queue...         
            ProducerTemplate template = exchange.getContext().createProducerTemplate();
            template.sendBodyAndHeaders("jms:queue:INQueue", req.getPayload(), headers);
            // then need to wait ...until received jms response from the route below        

   }});


from("jms:queue:OUTQueue")
   .process(new Processor() {
       public void process(Exchange exchange) throws Exception {
           // received jms response message
           // need to update the exchange data in the above route based on jms message
           // so the final response to the webservice cilent can receive the data ...
       }});
1

1 Answers

2
votes

I think you should rely on the request reply mechanism in Camel for this task. Camel Doc, Exclusive Fixed Reply Queue

So I guess the following DSL route does pretty much what you want (if there is no other reason why you should use a InOnly pattern for the JMS part?). Make sure you tune the requestTimeout if you need (as it defaults to 20Sec timeout).

from(webserviceURI)
  .inOut().to("jms:queue:INQueue?replyTo=OUTQueue?replyToType=Exclusive");

Yes, one other thing. If you run this on several nodes, then you need one exclusive queue per node.