blob: 74dc0526d253bf8dc713ae34243ba2ee6282155f [file] [log] [blame]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>ActiveMQ</title>
<link rel="icon" type="image/png" href="/assets/img/favicon.png">
<link rel="stylesheet" href="/css/main.css">
<script defer src="https://use.fontawesome.com/releases/v5.0.8/js/all.js" integrity="sha384-SlE991lGASHoBfWbelyBPLsUlwY1GwNDJo3jSJO04KZ33K2bwfV9YBauFfnzvynJ" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light fixed-top">
<div class="container">
<!-- <a class="navbar-brand mr-auto" href="#"><img style="height: 50px" src="assets/img/apache-feather.png" /></a> -->
<a class="navbar-brand mr-auto" href="/"><img src="/assets/img/activemq_logo_black_small.png" style="height: 50px"/></a>
<button class="navbar-toggler ml-auto" type="button" data-toggle="collapse" data-target="#navbarContent" aria-controls="navbarContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="ml-auto collapse navbar-collapse" id="navbarContent">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link active" href="/index.html">Home</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link" id="navbarDropdownComponents" data-target="#" href="" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Components</a>
<ul class="dropdown-menu dropdown-menu-center" aria-labelledby="navbarDropdownComponents">
<div class="row">
<div class="col-12">
<ul class="multi-column-dropdown">
<li class="nav-item"><a class="dropdown-item" href="/components/classic">ActiveMQ 5</a></li>
<li class="nav-item"><a class="dropdown-item" href="/components/artemis/">ActiveMQ Artemis</a></li>
<li class="nav-item"><a class="dropdown-item" href="/components/nms">NMS Clients</a></li>
<li class="nav-item"><a class="dropdown-item" href="/components/cms">CMS Client</a></li>
</ul>
</div>
</div>
</ul>
</li>
<li class="nav-item dropdown">
<a class="nav-link" id="navbarDropdownCommunity" data-target="#" href="" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Contact</a>
<ul class="dropdown-menu dropdown-menu-center multi-column columns-1" aria-labelledby="navbarDropdownCommunity">
<div class="row">
<div class="col-12">
<ul class="multi-column-dropdown">
<li class="nav-item"><a class="dropdown-item" href="/contact#mailing">Mailing Lists</a></li>
<li class="nav-item"><a class="dropdown-item" href="/contact#chat">Chat</a></li>
<li class="nav-item"><a class="dropdown-item" href="/contact#issues">Report Issues</a></li>
<li class="nav-item"><a class="dropdown-item" href="/contact#contributing">Contributing</a></li>
<li class="nav-item"><a class="dropdown-item" href="/security-advisories.html">Security</a></li>
</ul>
</div>
</div>
</ul>
</li>
<li class="nav-item dropdown">
<a class="nav-link" id="navbarDropdownTeam" data-target="#" href="" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Apache</a>
<ul class="dropdown-menu dropdown-menu-center multi-column columns-1" aria-labelledby="navbarDropdownTeam">
<div class="row">
<div class="col-sm-12">
<ul class="multi-column-dropdown">
<li class="nav-item"><a class="dropdown-item" href="https://www.apache.org">The Apache Software Foundation</a></li>
<li class="nav-item"><a class="dropdown-item" href="https://www.apache.org/licenses/">License</a></li>
<li class="nav-item"><a class="dropdown-item" href="https://www.apache.org/foundation/sponsorship.html">Sponsorship</a></li>
<li class="nav-item"><a class="dropdown-item" href="https://www.apache.org/foundation/thanks.html">Thanks</a></li>
<li class="nav-item"><a class="dropdown-item" href="/security-advisories.html">Security</a></li>
<li class="nav-item"><a class="dropdown-item" href="https://www.apache.org/events/current-event">Events</a></li>
<li class="nav-item"><a class="dropdown-item" href="https://people.apache.org/phonebook.html?pmc=activemq">PMC & Committers</a></li>
<li class="nav-item"><a class="dropdown-item" href="/team/reports">Board Reports</a></li>
</ul>
</div>
</div>
</ul>
</li>
</ul>
</div>
</div>
</nav>
<div class="content">
<div class="page-title-activemq5">
<div class="container">
<h1>Version 5 Examples</h1>
</div>
</div>
<div class="container" >
<div class="row" style="margin-top: 30px">
<div class="col-12 activemq5">
<p><a href="using-activemq-5">Using ActiveMQ 5</a> &gt; <a href="version-5-examples">Version 5 Examples</a></p>
<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="prerequisites">Prerequisites</h2>
<p>Before running the examples you should try <a href="run-broker">running a JMS broker</a> on your machine. Follow the <a href="installation">Installation</a> instructions to use a binary distribution of ActiveMQ. To run the broker in a command shell, type:</p>
<p>bin/activemq console</p>
<p>This starts up ActiveMQ.</p>
<h2 id="running">Running</h2>
<p>From the <a href="unix-shell-script">command line</a> you can run</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>${ACTIVEMQ_HOME}/bin/activemq producer
${ACTIVEMQ_HOME}/bin/activemq consumer
</code></pre></div></div>
<p>If you have <code class="highlighter-rouge">activemq-all</code> jar available you can achieve the same with</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>java -jar activemq-all-5.x.x.jar producer
java -jar activemq-all-5.x.x.jar consumer
</code></pre></div></div>
<p>If you run inside <a href="osgi-integration">Karaf</a>, you can run the commands as</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>activemq:producer
activemq:consumer
</code></pre></div></div>
<h2 id="options">Options</h2>
<p>For all options on the commands, run them with <code class="highlighter-rouge">--help</code> parameter. The up to date, options for <a href="https://github.com/apache/activemq/blob/master/activemq-console/src/main/resources/org/apache/activemq/console/command/producer.txt">producer</a> and <a 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 id="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="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>bin/activemq producer --message "My message" --messageCount 1
</code></pre></div></div>
<p>To send byte message of custom length use</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>bin/activemq producer --messageSize 100 --messageCount 1
</code></pre></div></div>
<p>To send a text message with content obtained from an url</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>bin/activemq producer --payloadUrl http://activemq.apache.org/schema/core/activemq-core.xsd --messageCount 1
</code></pre></div></div>
<p>To consume in transaction use</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>bin/activemq consumer --transacted true
</code></pre></div></div>
<p>To use client acknowledgment use</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>bin/activemq consumer --ackMode CLIENT_ACKNOWLEDGE
</code></pre></div></div>
<p>To use durable topic subscribers use</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>bin/activemq consumer --durable true --clientId example --destination topic://TEST
</code></pre></div></div>
<h2 id="old-examples">Old examples</h2>
<p>In older versions of ActiveMQ, the corresponding examples were located in <code class="highlighter-rouge">examples/</code> or <code class="highlighter-rouge">examples/openwire/swissarmy/</code> directories, where you can do the similar tasks with an ant script.</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>ant producer
ant consumer
</code></pre></div></div>
<h2 id="other-examples">Other examples</h2>
<p>In <code class="highlighter-rouge">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 class="highlighter-rouge">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="see-also">See Also</h2>
<ul>
<li><a href="web-samples">Web Samples</a></li>
<li><a href="web-console">Web Console</a></li>
<li><a href="jmx">JMX</a></li>
</ul>
</div>
</div>
</div>
</div>
<div class="row sitemap">
<div class="col-sm-12">
<div class="container">
<div class="row">
<div class="col-sm-12">
<div class="row">
<div class="col-sm-3">
<div >
<img class="float-left" style="max-height: 100px" src="/assets/img/activemq_logo_white_vertical_small.png"/>
</div>
</div>
<div style="text-align: center; margin-bottom: 0px; margin-top: 30px; font-size: 65%" class="col-sm-6">
<p>Apache ActiveMQ, ActiveMQ, ActiveMQ Artemis, Apache, the Apache feather logo, and the Apache ActiveMQ project logo are trademarks of The Apache Software Foundation. Copyright &copy; 2019, The Apache Software Foundation. Licensed under <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License 2.0</a>.</p>
</div>
<div class="col-sm-3">
<div >
<a href="https://www.apache.org"><img class="float-right" style="margin-top: 10px; max-height: 80px" src="/assets/img/apache-logo-small.png"/></a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>