...
ActiveMQ has a Servlet that takes care of the integration between HTTP and the ActiveMQ dispatcher.
NOTE: The example below requires servlet mapping on the URL. For posting without mapping, see examples further down.
You can map a URI to the servlet and then use the relative part of the URI as the topic or queue name. e.g. you could HTTP POST to
Code Block |
http://www.acme.com/queue/orders/input
|
which would publish the contents of the HTTP POST to the orders.input queue on JMS.
Similarly you could perform a HTTP DELETE GET on the above URL to read from the same queue. In this case we will map the MessageServlet from ActiveMQ to the URI
...
For a more cleaner mapping of a simple transfer protocol to different languages, you might wanna wish to take a look at Stomp.
Default configuration
...
Code Block |
curl -u admin:admin -d "body=message" http://localhost:8161/api/message/TEST?type=queue |
NOTE: If no type parameter is specified, the default is to create a topic. To change the default to queue, initialize the servlet with an init param in the webapps/demo/WEB-INF/web.xml
As shown below:
Code Block |
<servlet>
<servlet-name>MessageServlet</servlet-name>
<servlet-class>org.apache.activemq.web.MessageServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<init-param>
<param-name>topic</param-name>
<param-value>false</param-value>
</init-param>
</servlet>
|
Timeouts
When reading from a queue we might not have any messages. We can use a timeout query parameter to indicate how long we are prepared to wait for a message to arrive. This allows us to poll or block until a message arrives.
...