Reputation: 6292
I am working on a client/server request/reply system using Camel.
The client and server communicate using two JMS queues: request queue and response queue.
The server side has a camel route which consumes the JMS message from the request queue and process message concurrently. The response is sent back to the client using the response queue.
The client side sends a message to the JMS queue and wait for the response. I have two questions:
The client side is actually a library that will be used by other application. I want to use Camel on the client side as well but don't know how to use Camel as a "function" i.e. At some point in my have code, I need to do "send this object to this camel route". How can I do this?
Is there a standard way for camel to handle the request/reply using two queues?
Thank you very much.
Upvotes: 1
Views: 746
Reputation: 22279
Use the ProducerTemplate from the CamelContext. It requires you to keep a camel context around in the client somewhere.
You can do stuff like: producerTemplate.requestBody(myPayload,"jms:queue:whatever");
Camel can handle request reply using several different ways. Using an explicit reply queue (no temporary queues, which are used by default), you can either use exclusive mode, which is faster: jms:queue:request.queue?replyTo=client1.replies&replyToType=Exclusive
but requires a unique queue per client. The other alternative is a shared queue for all clients. The URI looks like this: activemq:queue:request.queue?replyTo=shared.replies
. Please note: a shared reply queue will use JMS selectors to pick messages for each client, and that will cost you performance and round trip latency.
Upvotes: 1
Reputation: 63
For question 1, you can use the camel producer template option which can invoke a camel route. Answer for question 2 is yes, you can refer to http://camel.apache.org/request-reply.html
Upvotes: 0