blob: b343155e25f5f0dc8e7e4f9fce888f58c58922e3 [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><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;<link><page ri:content-title="Run Broker"></page><plain-text-link-body>running a JMS broker</plain-text-link-body></link>&#160;on your machine. Follow the&#160;<link><page ri:content-title="Installation"></page></link>&#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><structured-macro ac:macro-id="321061e7-6bae-43a1-a1c4-9e39a20e6875" ac:name="code" ac:schema-version="1"><plain-text-body>bin/activemq console
</plain-text-body></structured-macro><p><span style="color: rgb(34,34,34);">&#160;</span></p><p>This starts up ActiveMQ.</p><h2>Running</h2><p>From the<link><page ri:content-title="Unix Shell Script"></page><plain-text-link-body> command line</plain-text-link-body></link> you can run</p><structured-macro ac:macro-id="9211f762-fd59-4fd5-9945-2b7d93fba9fc" ac:name="code" ac:schema-version="1"><plain-text-body>${ACTIVEMQ_HOME}/bin/activemq producer
${ACTIVEMQ_HOME}/bin/activemq consumer</plain-text-body></structured-macro><p>&#160;</p><p>If you have <code>activemq-all</code> jar available you can achieve the same with</p><structured-macro ac:macro-id="577cd72e-bbbc-41eb-9e56-664eaae2d9d7" ac:name="code" ac:schema-version="1"><plain-text-body>java -jar activemq-all-5.x.x.jar producer
java -jar activemq-all-5.x.x.jar consumer</plain-text-body></structured-macro><p>If you run inside <link><page ri:content-title="OSGi Integration"></page><plain-text-link-body>Karaf</plain-text-link-body></link>, you can run the commands as</p><structured-macro ac:macro-id="584a446b-b8a5-457d-94cb-ab234c40cbe9" ac:name="code" ac:schema-version="1"><plain-text-body>activemq:producer
activemq:consumer</plain-text-body></structured-macro><p>&#160;</p><h2>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" href="https://github.com/apache/activemq/blob/master/activemq-console/src/main/resources/org/apache/activemq/console/command/producer.txt">producer</a> and&#160;<a shape="rect" href="https://github.com/apache/activemq/blob/master/activemq-console/src/main/resources/org/apache/activemq/console/command/consumer.txt">consumer</a> can be found in the source.</p><h2>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><structured-macro ac:macro-id="d7494493-d755-4a0f-ae85-8a372728511c" ac:name="code" ac:schema-version="1"><plain-text-body>bin/activemq producer --message "My message" --messageCount 1
</plain-text-body></structured-macro><p>To send byte message of custom length use</p><structured-macro ac:macro-id="48aaea5a-bb54-4305-acc9-b6dbfe86f6c6" ac:name="code" ac:schema-version="1"><plain-text-body>bin/activemq producer --messageSize 100 --messageCount 1
</plain-text-body></structured-macro><p>To send a text message with content obtained from an url</p><structured-macro ac:macro-id="83497bb2-e595-4dcf-bcd5-94013a04d173" ac:name="code" ac:schema-version="1"><plain-text-body>bin/activemq producer --payloadUrl&#160;http://activemq.apache.org/schema/core/activemq-core.xsd&#160;--messageCount 1</plain-text-body></structured-macro><p>To consume in transaction use</p><structured-macro ac:macro-id="3e42e2a9-0ea5-4c9d-bc31-ba8693d8e538" ac:name="code" ac:schema-version="1"><plain-text-body>bin/activemq consumer --transacted true
</plain-text-body></structured-macro><p>To use client acknowledgment use</p><structured-macro ac:macro-id="1fa0d8d2-d7a9-4a83-94e4-a2a3a44b8fc9" ac:name="code" ac:schema-version="1"><plain-text-body>bin/activemq consumer --ackMode CLIENT_ACKNOWLEDGE
</plain-text-body></structured-macro><p>To use durable topic subscribers use</p><structured-macro ac:macro-id="18291517-9115-45eb-9846-13b82c06070b" ac:name="code" ac:schema-version="1"><plain-text-body>bin/activemq consumer --durable true --clientId example --destination topic://TEST
</plain-text-body></structured-macro><h2>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><structured-macro ac:macro-id="155e534a-74c1-4258-8ea9-f5631997a987" ac:name="code" ac:schema-version="1"><plain-text-body>ant producer
ant consumer</plain-text-body></structured-macro><h2>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>See Also</h2><ul><li><link><page ri:content-title="Web Samples"></page></link></li><li><link><page ri:content-title="Web Console"></page></link></li><li><link><page ri:content-title="JMX"></page></link></li></ul></div>