blob: d26705e40f725af6b5d958922da1555413821974 [file] [log] [blame]
<div class="wiki-content maincontent"><p><strong>This article applies to versions of ActiveMQ prior to 5.4.0. If you use version 5.4.0 or newer proceed to the <a shape="rect" href="osgi-integration.html">following article</a>.</strong></p>
<h1 id="OldOSGiIntegration-Introduction">Introduction</h1>
<p>All ActiveMQ modules are packaged as OSGi bundles and can be used in any OSGi container. This article will provide more details on how to use ActiveMQ in <a shape="rect" class="external-link" href="http://felix.apache.org/site/apache-felix-karaf.html">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>
<h1 id="OldOSGiIntegration-ActiveMQ">ActiveMQ</h1>
<p>ActiveMQ comes as a feature in ServiceMix (Karaf). So instead of installing all necessary bundles one by one, you can simply install it using a single command. But first of all, you need to setup ServiceMix features 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;">
smx@root:/&gt; features/addUrl mvn:org.apache.servicemix/apache-servicemix/4.0.0/xml/features
</pre>
</div></div>
<p>Now you can install ActiveMQ 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;">
smx@root:/&gt; features/install activemq
</pre>
</div></div>
<p>This command will install all necessary ActiveMQ bundles and if you type</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;">
smx@root:/&gt; osgi/list
</pre>
</div></div>
<p>you should see something 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;">
[ 50] [Active ] [ ] [ 60] geronimo-jta_1.1_spec (1.1.1)
[ 51] [Active ] [ ] [ 60] geronimo-j2ee-connector_1.5_spec (2.0.0)
[ 52] [Active ] [ ] [ 60] Apache ServiceMix Bundles: howl-1.0.1-1 (1.0.1.1_1)
[ 53] [Active ] [ ] [ 60] Geronimo TxManager :: Transaction (2.2.0.r634076)
[ 54] [Active ] [ ] [ 60] Spring Transaction (2.5.6)
[ 55] [Active ] [Started] [ 60] Apache ServiceMix Transaction (1.0.0)
[ 56] [Active ] [ ] [ 60] Geronimo TxManager :: Connector (2.2.0.r634076)
[ 57] [Active ] [ ] [ 60] geronimo-jms_1.1_spec (1.1.1)
[ 58] [Active ] [ ] [ 60] Apache ServiceMix Bundles: jencks-2.1 (2.1.0.1)
[ 59] [Active ] [ ] [ 60] geronimo-j2ee-management_1.1_spec (1.0.1)
[ 60] [Active ] [ ] [ 60] Apache Commons Pool Bundle (1.4)
[ 61] [Active ] [ ] [ 60] xbean-spring (3.5)
[ 62] [Active ] [ ] [ 60] activemq-core (5.2.0)
[ 63] [Active ] [ ] [ 60] activemq-ra (5.2.0)
[ 64] [Active ] [ ] [ 60] activemq-console (5.2.0)
[ 65] [Active ] [ ] [ 60] activemq-pool (5.2.0)
[ 66] [Active ] [Started] [ 60] Apache ServiceMix Features :: ActiveMQ Commands (4.0.0)
</pre>
</div></div>
<p>Once installed, this feature offers a special set of commands which enables you easily use the broker. </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>This feature comes pre-installed with the ServiceMix ESB so previous steps are not necessary.</p></div></div>
<p>The following example shows how to create and destroy the broker using the <code>create-broker</code> and <code>destroy-broker</code> commands.</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;">
smx@root:/&gt; activemq/create-broker
Creating file: /Users/dejanb/workspace/apache-servicemix-kernel-1.1.0/deploy/localhost-broker.xml
Default ActiveMQ Broker (localhost) configuration file created at: /Users/dejanb/workspace/apache-servicemix-kernel-1.1.0/deploy/localhost-broker.xml
Please review the configuration and modify to suite your needs.
smx@root:/&gt; activemq/destroy-broker
Default ActiveMQ Broker (localhost) configuration file created at: /Users/dejanb/workspace/apache-servicemix-kernel-1.1.0/deploy/localhost-broker.xml removed.
</pre>
</div></div>
<p>For more information on ActiveMQ feature take a look at the <a shape="rect" class="external-link" href="http://servicemix.apache.org/SMX4/activemq-integration.html">ServiceMix ActiveMQ integration guide </a></p>
<h1 id="OldOSGiIntegration-Webconsole">Web console</h1>
<p><a shape="rect" href="web-console.html">Web console</a> is included in ActiveMQ distribution and you'll probably want to have it to monitor your broker. First of all you'll have to install the <code>web</code> feature, so that you have a web container ready to deploy our web application. To do that you should first add the ServiceMix features url, like we did above (if you didn't already). Now, you can just 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;">
smx@root:/&gt; features/install web
</pre>
</div></div>
<p>to grab all necessary bundles. If you type</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;">
smx@root:/&gt; osgi/list
</pre>
</div></div>
<p>you'll see all installed bundles (such 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;">
[ 43] [Active ] [ ] [ 60] Apache ServiceMix Bundles: jetty-6.1.14 (6.1.14.1)
[ 44] [Active ] [ ] [ 60] OPS4J Pax Web - Jsp Support (0.5.2)
[ 45] [Active ] [ ] [ 60] OPS4J Pax Web - Web Container (0.5.2)
[ 46] [Active ] [ ] [ 60] OPS4J Pax Web Extender - WAR (0.5.0)
[ 47] [Active ] [ ] [ 60] OPS4J Pax Web Extender - Whiteboard (0.5.0)
[ 48] [Active ] [ ] [ 60] OPS4J Pax Url - war:, war-i: (0.3.3)
[ 49] [Active ] [Started] [ 60] Apache ServiceMix WAR Deployer (4.0.0)
</pre>
</div></div>
<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>This feature comes pre-installed with the ServiceMix ESB so previous steps are not necessary.</p></div></div>
<p>The important thing is that we need to use proper versions of Pax web bundles to make all this work, and those are:</p>
<ul><li>pax-web-bundle version 0.6.0</li><li>pax-web-jsp version 0.6.0</li><li>pax-web-ex-war version 0.5.1</li><li>pax-web-ex-whiteboard version 0.5.1</li></ul>
<p>So if you have older bundles, like it is the case in our example, you'll need to unistall them and install new ones. To uninstall old bundles, simply look at their id and execute</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;">
smx@root:/&gt; osgi/uninstall [id]
</pre>
</div></div>
<p>In this example it would be</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;">
smx@root:/&gt; osgi/uninstall 44
smx@root:/&gt; osgi/uninstall 45
smx@root:/&gt; osgi/uninstall 46
smx@root:/&gt; osgi/uninstall 47
</pre>
</div></div>
<p>Now install new ones</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;">
smx@root:/&gt; osgi/install mvn:org.ops4j.pax.web/pax-web-bundle/0.6.0
smx@root:/&gt; osgi/install mvn:org.ops4j.pax.web/pax-web-jsp/0.6.0
smx@root:/&gt; osgi/install mvn:org.ops4j.pax.web-extender/pax-web-ex-war/0.5.1
smx@root:/&gt; osgi/install mvn:org.ops4j.pax.web-extender/pax-web-ex-whiteboard/0.5.1
</pre>
</div></div>
<p>After successful installation, you should start your newly added bundles. You can do that by executing </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;">
smx@root:/&gt; osgi/start [id]
</pre>
</div></div>
<p>It's best to restart your container at this point and afterwards we're finally ready to deploy our war. To do that we'll use the Pax Web War Extender. The following example will use the latest <code>5.3-SNAPSHOT</code> build and deploy it in the OSGi runtime</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;">
smx@root:/&gt; osgi/install war:mvn:org.apache.activemq/activemq-web-console/5.3-SNAPSHOT/war?Webapp-Context=activemqweb
</pre>
</div></div>
<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>You have to use the latest 5.3-SNAPSHOT web console, since this doesn't work right with previous versions.</p></div></div>
<p>Also, if you have problems installing the war with the previous method, download it manually from <a shape="rect" class="external-link" href="https://repository.apache.org/content/repositories/snapshots/org/apache/activemq/activemq-web-console/5.3-SNAPSHOT/">https://repository.apache.org/content/repositories/snapshots/org/apache/activemq/activemq-web-console/5.3-SNAPSHOT/</a> and install using</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;">
smx@root:/&gt; osgi/install war:file:///path_to_the_war/activemq-web-console-5.3-SNAPSHOT.war?Webapp-Context=activemqweb
</pre>
</div></div>
<p>Unfortunately the command</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;">
osgi/install \
war:mvn:https://repository.apache.org/content/repositories/snapshots@snapshots!org.apache.activemq/activemq-web-console/5.3-SNAPSHOT/war?Webapp-Context=activemqweb
</pre>
</div></div>
<p>does not work with pax web war extender 0.5.1, but you try it if you're using the newer one.</p>
<p>If you execute</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;">
smx@root:/&gt; osgi/list
</pre>
</div></div>
<p>you'll see the newly added bundle here.</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;">
[ 84] [Resolved ] [ ] [ 60] mvn_org.apache.activemq_activemq-web-console_5.3-SNAPSHOT_war (0)
</pre>
</div></div>
<p>It's time t start it now</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;">
smx@root:/&gt; osgi/start 84
</pre>
</div></div>
<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> Use the id of your bundle</p></div></div>
<p>The important thing to note here is that by default, web console will start an embedded broker and monitor it. So if you have a broker already running it will fail to start.</p>
<p>Note that we have used <code>activemqweb</code> as a <code>WebApp-Context</code> while deploying the war, so the console will be available at <a shape="rect" class="external-link" href="http://localhost:8080/activemqweb" rel="nofollow">http://localhost:8080/activemqweb</a>. Visit this URL and administer your embedded broker.</p>
<p>There a big chance that you don't want to monitor an embedded broker, but the broker you have started separately (in the OSGi runtime or elsewhere). To configure your web console to do that, you have to do the following. First, exit your OSGi runtime. Now you can edit the <code>etc/system.properties</code> file and add some configuration details. The following configuration snippet</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.type=properties
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>should work fine with default broker started in the Karaf (ServiceMix). Adapt it to your specific needs.</p>
<p>Now if you run the runtime (and the console bundle), you'll notice that the console will not start the broker and will try to use one defined with the system properties.</p>
<p>Visit <a shape="rect" class="external-link" href="http://localhost:8080/activemqweb" rel="nofollow">http://localhost:8080/activemqweb</a> and enjoy.</p></div>