Kumar
Kumar

Reputation: 961

How to connect HornetQ message broker with RESTful service JAX-RS Jersey

I have created a RESTful service using JAX-RS Jersey and deployed it on a tomcat 7 server.

Now I would like to use JMS. The request would be captured and directed to a message queue on a message broker and from there messages should be pushed towards the REST service and then the response would be redirected to the end user.

I am using Activemq. How can I integrate Activemq with a RESTful service?

Upvotes: 3

Views: 779

Answers (1)

Beryllium
Beryllium

Reputation: 12998

Your webservice interface needs to offer two functions: submit and poll.

  • The client calls submit which in turn sends the request as a JMS message on the incoming queue, and returns the message ID. submit returns after that.
  • The request processing runs asynchronously. For example a message driven bean (MDB) listens on the incoming queue, processes the message, and puts the result on an outgoing queue. It sets the correlation ID of the result message to the message ID of the incoming request. The correlation ID is required to connect the request and its result.
  • The client calls the poll function with the message ID (as returned by submit) as an argument: poll checks the result queue using a JMS message selector on the correlation ID. It returns "not yet completed" or the result. The client possibly needs to call poll multiple times to get the result.

Notes:

  • A JMS message selector is a filter (like a where clause in a database): It is required in this scenario to identify the result for a given request.
  • Javadoc of setJMSCorrelationID

Upvotes: 3

Related Questions