Processing Acknowledgments with CAMEL?
-
21-12-2019 - |
Question
I have clients sending request thru different ways like web request, http request , soap request or thru some other channel.
In Camel i receive it from respective endpoints to jms queue. From queue processor picks up the message. Now processor needs to send the acknowledgemnt to clients based on their preference(which they have sent in incoming request).Preference can be they would like receive acknowledgement thru webservice or jms or filesystem anything.
I think it can be done with http://camel.apache.org/request-reply.html bit somehow i am not able to proceed further. Basically i am not sure how should i process the acknowledgement from processor to respective clients using CAMEL inbuilt capabilities. Any direction would be help?
UPDATE:- Client preference is stored in incoming request message from client. You can also assume its stored somewhere in system (db or property file)
Solution
I think it is the return address pattern that you are describing - https://camel.apache.org/return-address.html
There is some sample code in a junit test case here - http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsInOnlyWithReplyToAsHeaderTest.java?view=markup
EDIT: Adding some sample code from the link above to explain it better:
So lets say we have the following endpoints defined below, we have a
from("direct:start")
,
from("activemq:queue:foo")
and
from("activemq:queue:bar?disableReplyTo=true")
In our actual test we call this code:
template.sendBodyAndHeader("direct:start", "World", "JMSReplyTo", "queue:bar");
This sends a message to the direct:start
endpoint with the body containing "World" and a header called JMSReplyTo
with the value "queue:bar". Because we have specified this JMSReplyTo
header, once the route is finished it will call whatever endpoint is defined in the headers value, in this case it will call the "queue:bar" endpoint.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start")
// must enable preserveMessageQos to force Camel to use the JMSReplyTo header
.to("activemq:queue:foo?preserveMessageQos=true")
.to("mock:done");
from("activemq:queue:foo")
.to("log:foo?showAll=true", "mock:foo")
.transform(body().prepend("Bye "));
// we should disable reply to to avoid sending the message back to our self
// after we have consumed it
from("activemq:queue:bar?disableReplyTo=true")
.to("log:bar?showAll=true", "mock:bar");
}
};
}
So how does this fit in with your use case? Well what will happen is the client, or some code you have written will specify the JMSReplyTo
header with an endpoint that relates to how the response will be sent. So if they want the reply to be placed on a queue, then the JMSReplyTo
header's value will be the specified queues endpoint.