blob: 2191c9aa89642343dc0df5ede6c665bbd165ab2a [file] [log] [blame]
<div class="wiki-content maincontent"><p>Since version<strong> 5.12.0</strong>, Apache ActiveMQ comes with the new tool that can be used to produce and consume messages from the broker.</p><h2 id="Version5Examples-Prerequisites"><span style="color: rgb(34,34,34);">Prerequisites</span></h2><p><span style="color: rgb(34,34,34);">&#160;</span></p><p>Before running the examples you should try&#160;<a shape="rect" href="run-broker.html">running a JMS broker</a>&#160;on your machine. Follow the&#160;<a shape="rect" href="installation.html">Installation</a>&#160;instructions to use a binary distribution of ActiveMQ. To run the broker in a command shell, type:</p><p><span style="color: rgb(34,34,34);">&#160;</span></p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">bin/activemq console
</pre>
</div></div><p><span style="color: rgb(34,34,34);">&#160;</span></p><p>This starts up ActiveMQ.</p><h2 id="Version5Examples-Running">Running</h2><p>From the<a shape="rect" href="unix-shell-script.html"> command line</a> you can run</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">${ACTIVEMQ_HOME}/bin/activemq producer
${ACTIVEMQ_HOME}/bin/activemq consumer</pre>
</div></div><p>&#160;</p><p>If you have <code>activemq-all</code> jar available you can achieve the same with</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">java -jar activemq-all-5.x.x.jar producer
java -jar activemq-all-5.x.x.jar consumer</pre>
</div></div><p>If you run inside <a shape="rect" href="osgi-integration.html">Karaf</a>, you can run the commands as</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">activemq:producer
activemq:consumer</pre>
</div></div><p>&#160;</p><h2 id="Version5Examples-Options">Options</h2><p>For all options on the commands, run them with <code>--help</code>&#160;parameter. The up to date, options for&#160;<a shape="rect" class="external-link" href="https://github.com/apache/activemq/blob/master/activemq-console/src/main/resources/org/apache/activemq/console/command/producer.txt" rel="nofollow">producer</a> and&#160;<a shape="rect" class="external-link" href="https://github.com/apache/activemq/blob/master/activemq-console/src/main/resources/org/apache/activemq/console/command/consumer.txt" rel="nofollow">consumer</a> can be found in the source.</p><h2 id="Version5Examples-Examples">Examples</h2><p>Here are a couple of examples of more advanced features.</p><p>To send a text message with custom text use</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">bin/activemq producer --message "My message" --messageCount 1
</pre>
</div></div><p>To send byte message of custom length use</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">bin/activemq producer --messageSize 100 --messageCount 1
</pre>
</div></div><p>To send a text message with content obtained from an url</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">bin/activemq producer --payloadUrl&#160;http://activemq.apache.org/schema/core/activemq-core.xsd&#160;--messageCount 1</pre>
</div></div><p>To consume in transaction use</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">bin/activemq consumer --transacted true
</pre>
</div></div><p>To use client acknowledgment use</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">bin/activemq consumer --ackMode CLIENT_ACKNOWLEDGE
</pre>
</div></div><p>To use durable topic subscribers use</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">bin/activemq consumer --durable true --clientId example --destination topic://TEST
</pre>
</div></div><h2 id="Version5Examples-Oldexamples">Old examples</h2><p>In older versions of ActiveMQ, the corresponding examples were located in <code>examples/</code> or&#160;<code>examples/openwire/swissarmy/</code> directories, where you can do the similar tasks with an ant script.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">ant producer
ant consumer</pre>
</div></div><h2 id="Version5Examples-Otherexamples">Other examples</h2><p>In <code>examples/</code> directory (depending on the version) you can find more examples of using the broker with variety of protocols (mqtt, amqp, ...) and clients (Java, Ruby, JavaScript, ...), so it's the good place to start learning. Also, <code>examples/conf/</code> directory contains a lot of different configuration examples that you can use as a starting point for your deployment.</p><h2 id="Version5Examples-SeeAlso">See Also</h2><ul><li><a shape="rect" href="web-samples.html">Web Samples</a></li><li><a shape="rect" href="web-console.html">Web Console</a></li><li><a shape="rect" href="jmx.html">JMX</a></li></ul></div>