DKerr
DKerr

Reputation: 47

Camel CXF asynchronous request and reply

I would like to set up a Camel CXF endpont, and have the SOAP response asynchronous to much of my Camel Route. The route will have a lot of processing steps, and I do not want to have the response generated at the very end.

An example endpoint:

<cxf:cxfEndpoint id="someEndpoint"
                     address="/Service"
                     serviceClass="com.SomeImpl" />

An example route:

public class MyRouteBuilder extends RouteBuilder {
    @Override
    public void configure() throws Exception {
        from("cxf:bean:someEndpoint")
        to("bean:processingStep1")
        to("bean:replyToSOAP")  // I would like to respond to cxf:cxfEndpoint here!
        to("bean:processingStep2")
        to("bean:processingStep3")
        to("bean:processingStep4");
        // The response to cxf:cxfEndpoint actually happens here.
    }
}

I have tried many options in MyRouteBuilder to "fork" the process (i.e. bean:replyToSOAP):

  1. .multicast().parallelProcessing()
  2. In-memory Asynchronous messaging ("seda" and "vm")
  3. I have NOT tried JMS. It could be overkill for what I want to do.

I can get the route steps to process in parallel, but all steps must be completed before the response is generated.

In addition to the answer Claus gives below, I'd like to add that the placement of wireTap is important. Using:

.wireTap("bean:replyToSOAP")

will not get the desired behavior. What will is:

public class MyRouteBuilder extends RouteBuilder {
    @Override
    public void configure() throws Exception {
        from("cxf:bean:someEndpoint")
        to("bean:processingStep1")
        .wireTap("direct:furtherProcessing")
        to("bean:replyToSOAP")  // respond to cxf:cxfEndpoint here

        from("direct:furtherProcessing") // steps happen independantly of beann:replyToSOAP 
        to("bean:processingStep2")
        to("bean:processingStep3")
        to("bean:processingStep4");
    }
}

Upvotes: 1

Views: 1877

Answers (1)

Claus Ibsen
Claus Ibsen

Reputation: 55555

There is the WireTap EIP which can spin of a copy of the message to be processed independently from the current route: http://camel.apache.org/wire-tap

Upvotes: 2

Related Questions