blob: 3245673861b5d03e1aa02cf9e03f12ee2aaa3eee [file] [log] [blame]
<div class="wiki-content maincontent"><h1 id="OSGiIntegration-Introduction">Introduction</h1><p>This article will provide more details on how to use ActiveMQ in <a shape="rect" class="external-link" href="http://karaf.apache.org/">Apache Karaf</a>, small OSGi based runtime. Apache Karaf was previously know as <em>ServiceMix kernel</em>, so informations found here are applicable to <a shape="rect" class="external-link" href="http://servicemix.apache.org/home.html">Apache ServiceMix Enterprise Service Bus</a> as well.</p><div class="confluence-information-macro confluence-information-macro-note"><span class="aui-icon aui-icon-small aui-iconfont-warning confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>Procedures described in this article were tested using Apache karaf 2.3.0</p></div></div><h1 id="OSGiIntegration-Installation">Installation</h1><p>ActiveMQ provides Karaf features which will help you integrate and use the broker in OSGi environment. For starters you need to add the features URL to Karaf. For version 5.9.0 you can do it like this:</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;">karaf@root&gt; features:chooseurl activemq 5.9.0
</pre>
</div></div><p>After that you should see newly added features</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;">karaf@root&gt; features:list
State Version Name Repository
[uninstalled] [5.9.0 ] activemq-broker activemq-5.9.0
[uninstalled] [5.9.0 ] activemq-http activemq-5.9.0
[uninstalled] [5.9.0 ] activemq-camel activemq-5.9.0
[uninstalled] [5.9.0 ] activemq-web-console activemq-5.9.0
</pre>
</div></div><p>Installing and running the broker is as simple as installing <code>activemq-broker</code> feature, like</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;">karaf@root&gt; features:install activemq-broker
</pre>
</div></div><p>This will install and start the full broker (including the web console), just as if you started the standalone distribution.</p><h1 id="OSGiIntegration-BrokerConfiguration">Broker Configuration</h1><p>Broker is configured using OSGi Config Admin mechanism and could be easily managed in <a shape="rect" class="external-link" href="http://karaf.apache.org/manual/latest-2.3.x/users-guide/configuration.html">Karaf</a>. Configuration can be done by modifying <code>${KARAF_BASE}/etc/org.apache.activemq.server-default.cfg</code> file or respective config admin property. An example of the file looks like</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;">broker-name=amq-broker
data=${karaf.data}/${broker-name}
config=${karaf.base}/etc/activemq.xml</pre>
</div></div><p>Mandatory properties are listed in the following table</p><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p>Property Name</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Property Description</p></th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>broker-name</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Name of the broker</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>config</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Location of the XML configuration file</p></td></tr></tbody></table></div><p>You can also use this file to set other properties which will replace placeholders in XML configuration file, as the <code>${data</code>} property is used in this example.</p><p>Default XML configuration file is located in the <code>${KARAF_BASE}/etc/activemq.xml</code> by default.</p><h1 id="OSGiIntegration-WebConsole">Web Console</h1><p>Web Console is installed by default and can be reached at <a shape="rect" class="external-link" href="http://localhost:8181/activemqweb/" rel="nofollow">http://localhost:8181/activemqweb/</a></p><p>The configuration for the console is done in a similar fashion to the broker itself. Configuration is located in <code>${KARAF_BASE}/etc/org.apache.activemq.webconsole.cfg</code> and by default looks like</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;">webconsole.jms.url=tcp://localhost:61616
webconsole.jmx.url=service:jmx:rmi:///jndi/rmi://localhost:1099/karaf-root
webconsole.jmx.user=karaf
webconsole.jmx.password=karaf</pre>
</div></div><p><strong>Optional:</strong> In order to use the ActiveMQ console with a broker configured with authentication, it is necessary to configure the username/password for JMS connection as well.</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;">webconsole.jms.user=system
webconsole.jms.password=manager
</pre>
</div></div><h1 id="OSGiIntegration-Commands">Commands</h1><p>After these simple steps you have all necessary libraries installed in the container. Also, now you have specific commands on your disposal that you can use to manage your broker:</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;"> browse Display selected messages in a specified destination
bstat Displays useful broker statistics
list Lists all available brokers in the specified JMX context
purge Delete selected destination's messages that matches the message selector
query Display selected broker component's attributes and statistics
dstat Performs a predefined query that displays useful tabular statistics regarding the specified destination type&#160;</pre>
</div></div><div class="confluence-information-macro confluence-information-macro-tip"><p class="title">Help on commands</p><span class="aui-icon aui-icon-small aui-iconfont-approve confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>To obtain some detailed help on a given command, 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:[command] --help
</pre>
</div></div></div></div><h2 id="OSGiIntegration-Brokerquerying">Broker querying</h2><p>Several commands are available to query the broker. To address local brokers, you need to use the <code>--jmxlocal</code> parameter.</p><p>The following command displays available brokers:</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;">karaf@root&gt; activemq:list --jmxlocal
BrokerName = mybroker
</pre>
</div></div><p>To have more detailed informations, 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;">karaf@root&gt; activemq:query --jmxlocal
</pre>
</div></div><p>It will display informations about the connectors, list of queues, etc...</p><p>You can also browse or purge queues using the <code>activemq:browse</code> and <code>activemq:purge</code> commands.</p></div>