activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From build...@apache.org
Subject svn commit: r939838 - in /websites/production/activemq/content: cache/main.pageCache rest.html
Date Wed, 11 Feb 2015 18:20:57 GMT
Author: buildbot
Date: Wed Feb 11 18:20:57 2015
New Revision: 939838

Log:
Production update by buildbot for activemq

Modified:
    websites/production/activemq/content/cache/main.pageCache
    websites/production/activemq/content/rest.html

Modified: websites/production/activemq/content/cache/main.pageCache
==============================================================================
Binary files - no diff available.

Modified: websites/production/activemq/content/rest.html
==============================================================================
--- websites/production/activemq/content/rest.html (original)
+++ websites/production/activemq/content/rest.html Wed Feb 11 18:20:57 2015
@@ -81,7 +81,7 @@
   <tbody>
         <tr>
         <td valign="top" width="100%">
-<div class="wiki-content maincontent"><p>ActiveMQ implements a RESTful API to
messaging which allows any web capable device to publish or consume messages using a regular
HTTP POST or GET.</p><p>If you are interested in messaging directly from web browsers
you might wanna check out our <a shape="rect" href="ajax.html">Ajax</a> or <a
shape="rect" href="websockets.html">WebSockets</a> support or try <a shape="rect"
href="web-samples.html">running the REST examples</a></p><h2 id="REST-MappingofRESTtoJMS">Mapping
of REST to JMS</h2><p>To publish a message use a HTTP POST. To consume a message
use HTTP DELETE or GET.</p><p>ActiveMQ has a Servlet that takes care of the integration
between HTTP and the ActiveMQ dispatcher.</p><p><span style="color: rgb(255,153,0);">NOTE:
The example below requires servlet mapping on the URL. For posting without mapping, see examples
further down.</span></p><p>You can map a URI to the servlet and then use
the relative part of the URI as the topic or queue n
 ame. e.g. you could HTTP POST to</p><div class="code panel pdl" style="border-width:
1px;"><div class="codeContent panelContent pdl">
+<div class="wiki-content maincontent"><p>ActiveMQ implements a RESTful API to
messaging which allows any web capable device to publish or consume messages using a regular
HTTP POST or GET.</p><p>If you are interested in messaging directly from web browsers
you might wanna check out our <a shape="rect" href="ajax.html">Ajax</a> or <a
shape="rect" href="websockets.html">WebSockets</a> support or try <a shape="rect"
href="web-samples.html">running the REST examples</a></p><h2 id="REST-MappingofRESTtoJMS">Mapping
of REST to JMS</h2><p>To publish a message use a HTTP POST. To consume a message
use HTTP DELETE or GET.</p><p>ActiveMQ has a Servlet that takes care of the integration
between HTTP and the ActiveMQ dispatcher.</p><p><span style="color: rgb(255,153,0);">NOTE:
The example below requires servlet mapping on the URL. For posting without the servlet mapping,
see examples further down.</span></p><p>You can map a URI to the servlet
and then use the relative part of the URI as the topi
 c or queue name. e.g. you could HTTP POST to</p><div class="code panel pdl" style="border-width:
1px;"><div class="codeContent panelContent pdl">
 <script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[http://www.acme.com/orders/input
 ]]></script>
 </div></div><p>which would publish the contents of the HTTP POST to the
orders.input queue on JMS.&#160;</p><p>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</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
@@ -99,7 +99,13 @@
      &lt;param-value&gt;false&lt;/param-value&gt;
   &lt;/init-param&gt;
 &lt;/servlet&gt;]]></script>
-</div></div><h3 id="REST-Timeouts">Timeouts</h3><p>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.</p><p>Couple this with HTTP 1.1 keep-alive sockets and
pipeline processing we can have efficient access to JMS over HTTP.</p><p>Obviously
if your client is Java then using ActiveMQ's JMS API is the fastest and most efficient way
to work with the message broker; however, if you are not using Java or prefer the simplicity
of HTTP then it should be fairly efficient, especially if your HTTP client supports keep-alive
sockets and pipeline processing.</p><h3 id="REST-Consuming">Consuming</h3><p>When
consuming messages using the REST API, you have to keep session alive between GET requests,
or you'll create a separate consumer for every request and due to prefetch limit your succeeding
call will hang.</p><p>For example, y
 ou can use <code>wget</code> to consume messages, like this:</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent
pdl">
+</div></div><h4 class="p1" id="REST-AlternateProducingSyntax"><span
class="s1">Alternate Producing Syntax</span></h4><p class="p1"><span
class="s1">An alternative syntax for posting is supported, using the destination URL-encoded
parameter; here are some examples:</span>&#160;</p><div class="code panel
pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[#
Send to queue orders.input:
+curl -XPOST -d &quot;body=message&quot; http://admin:admin@localhost:8161/api/message?destination=queue://orders.input
+ 
+# Send to topic orders.input:
+curl -XPOST -d &quot;body=message&quot; http://admin:admin@localhost:8161/api/message?destination=topic://orders.input]]></script>
+</div></div><h3 id="REST-Timeouts">Timeouts</h3><p>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.</p><p>Couple this with HTTP 1.1 keep-alive sockets and
pipeline processing we can have efficient access to JMS over HTTP.</p><p>Obviously
if your client is Java then using ActiveMQ's JMS API is the fastest and most efficient way
to work with the message broker; however, if you are not using Java or prefer the simplicity
of HTTP then it should be fairly efficient, especially if your HTTP client supports keep-alive
sockets and pipeline processing.</p><h4 class="p1" id="REST-Consuming"><span
style="font-size: 16.0px;line-height: 1.5625;">Consuming</span></h4><p>When
consuming messages using the REST API, you have to keep session alive between GET requests,
or you'll create a separate consumer for every request and due
  to prefetch limit your succeeding call will hang.</p><p>For example, you can
use <code>wget</code> to consume messages, like this:</p><div class="code
panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
 <script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[wget
--user admin --password admin --save-cookies cookies.txt --load-cookies cookies.txt --keep-session-cookies
 http://localhost:8161/api/message/TEST1?type=queue
 ]]></script>
 </div></div><p>Also, if you plan to have multiple consumer using REST,
it's advisable to set prefetch size to 1 so all consumers have an equal chance of getting
the message. You can do that by passing a special parameter to the <code>MessageServlet</code></p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent
pdl">
@@ -113,7 +119,13 @@
         &lt;/init-param&gt;
     &lt;/servlet&gt;
 ]]></script>
-</div></div><p>in the <code>webapps/demo/WEB-INF/web.xml</code></p><h3
id="REST-Consumingwithoutsessions">Consuming without sessions</h3><p>Since
5.2.0 you can use <code>clientId</code> parameter to avoid storing actual JMS
consumer in the request session. When using this approach, you don't need to keep sessions
alive between requests, you just need to use the same <code>clientId</code> every
time.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
+</div></div><p>in the <code>webapps/demo/WEB-INF/web.xml</code></p><h4
class="p1" id="REST-AlternateConsumingSyntax"><span class="s1">Alternate Consuming
Syntax</span></h4><p class="p1"><span class="s1">As with producing,
an alternative syntax for consuming messages is also supported, using the destination URL-encoded
parameter; here are some examples:</span>&#160;</p><div class="code panel
pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[#
Send to queue orders.input:
+curl -XGET http://admin:admin@localhost:8161/api/message?destination=queue://orders.input
+ 
+# Send to topic orders.input:
+curl -XGET http://admin:admin@localhost:8161/api/message?destination=topic://orders.input]]></script>
+</div></div><h4 class="p1" id="REST-Consumingwithoutsessions"><span
style="font-size: 16.0px;line-height: 1.5625;">Consuming without sessions</span></h4><p>Since
5.2.0 you can use <code>clientId</code> parameter to avoid storing actual JMS
consumer in the request session. When using this approach, you don't need to keep sessions
alive between requests, you just need to use the same <code>clientId</code> every
time.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
 <script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[wget
--user admin --password admin http://localhost:8161/api/message/test?type=queue&amp;clientId=consumerA
 ]]></script>
 </div></div><p>Every such call will use the same JMS consumer and deliver
messages send to it by the broker.</p><p>In 5.4.1 it's also possible to unsubscribe
the client. It's done by sending a POST call with <code>clientId</code> and <code>action=unsubscribe</code>
parameters to the server, like</p><div class="code panel pdl" style="border-width:
1px;"><div class="codeContent panelContent pdl">
@@ -127,7 +139,9 @@
         &lt;param-value&gt;activemq-selector&lt;/param-value&gt;
     &lt;/context-param&gt;
 ]]></script>
-</div></div><p>For more info, take a look at <a shape="rect" class="external-link"
href="http://fisheye6.atlassian.com/browse/activemq/trunk/activemq-web-demo/src/test/java/org/apache/activemq/web/RestTest.java?r=HEAD"
rel="nofollow">RestTest</a></p><h3 id="REST-ContentTypes">Content Types</h3><p>By
default messages are sent to the consumers with <code>text/xml</code> content
type. Your REST-based application may expect JSON response instead of XML one. In that case,
you can configure the servlet to send responses back by adding something like this</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent
pdl">
+</div></div><p>For more info, take a look at <a shape="rect" class="external-link"
href="http://fisheye6.atlassian.com/browse/activemq/trunk/activemq-web-demo/src/test/java/org/apache/activemq/web/RestTest.java?r=HEAD"
rel="nofollow">RestTest</a></p><h3 id="REST-ConsumingwithOneShotConsumers">Consuming
with One Shot Consumers</h3><p>One shot consumption allows a REST call to receive
a single message and then immediately close the associated consumer.</p><p>All
of the examples so far lead to the servlet creating and holding on to consumers of the destination
across multiple HTTP requests. Without care, these consumers could easily lead to confusion
as messages are dispatched to them but then sit unused because the consuming HTTP session,
or clientId, fails to connect to continue requesting the messages. One way around that problem
is the use of one-shot consumers. &#160;Simple add the&#160;<code>?oneShot=true</code>
option and the consumer is removed once the consumption completes; a
 s follows:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
+<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[curl
-XGET http://admin:admin@localhost:8161/api/message?destination=queue://orders.input&amp;oneShot=true]]></script>
+</div></div><p>Note that interrupting the call while the consumer is waiting
for a message, the consumer may remain until the server times out the HTTP request, or until
a message finally arrives.</p><h3 id="REST-ContentTypes">Content Types</h3><p>By
default messages are sent to the consumers with <code>text/xml</code> content
type. Your REST-based application may expect JSON response instead of XML one. In that case,
you can configure the servlet to send responses back by adding something like this</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent
pdl">
 <script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[
   &lt;servlet&gt;
         &lt;servlet-name&gt;MessageServlet&lt;/servlet-name&gt;
         &lt;servlet-class&gt;org.apache.activemq.web.MessageServlet&lt;/servlet-class&gt;



Mime
View raw message