blob: 060fe8c3cad298588e3f30c5ccf81c727cfe8dcb [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 <link><page ri:content-title="OSGi Integration"></page><link-body>following article</link-body></link>.</strong></p>
<h1>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" 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" href="http://servicemix.apache.org/home.html">Apache ServiceMix Enterprise Service Bus</a> as well.</p>
<h1>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>
<structured-macro ac:macro-id="6fdc52c5-1aa3-4658-bb8f-799b20301188" ac:name="code" ac:schema-version="1"><plain-text-body>
smx@root:/&gt; features/addUrl mvn:org.apache.servicemix/apache-servicemix/4.0.0/xml/features
</plain-text-body></structured-macro>
<p>Now you can install ActiveMQ like this</p>
<structured-macro ac:macro-id="2092b3f0-16ae-4099-a6d3-7f6ca0fbfb68" ac:name="code" ac:schema-version="1"><plain-text-body>
smx@root:/&gt; features/install activemq
</plain-text-body></structured-macro>
<p>This command will install all necessary ActiveMQ bundles and if you type</p>
<structured-macro ac:macro-id="fe06efaf-d692-4f76-8368-7531b6330bc1" ac:name="code" ac:schema-version="1"><plain-text-body>
smx@root:/&gt; osgi/list
</plain-text-body></structured-macro>
<p>you should see something like this</p>
<structured-macro ac:macro-id="0a5b1a0b-1459-4a59-8967-ac1e77c37230" ac:name="code" ac:schema-version="1"><plain-text-body>
[ 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)
</plain-text-body></structured-macro>
<p>Once installed, this feature offers a special set of commands which enables you easily use the broker. </p>
<structured-macro ac:macro-id="86a43205-f95e-43fb-9388-c063abf85c23" ac:name="note" ac:schema-version="1"><rich-text-body>
<p>This feature comes pre-installed with the ServiceMix ESB so previous steps are not necessary.</p></rich-text-body></structured-macro>
<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>
<structured-macro ac:macro-id="9a0e1f89-7f5f-4c88-8479-94324142e989" ac:name="code" ac:schema-version="1"><plain-text-body>
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.
</plain-text-body></structured-macro>
<p>For more information on ActiveMQ feature take a look at the <a shape="rect" href="http://servicemix.apache.org/SMX4/activemq-integration.html">ServiceMix ActiveMQ integration guide </a></p>
<h1>Web console</h1>
<p><link><page ri:content-title="Web console"></page></link> 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>
<structured-macro ac:macro-id="bbbf47f0-359b-46d0-b5fc-987f90c0071d" ac:name="code" ac:schema-version="1"><plain-text-body>
smx@root:/&gt; features/install web
</plain-text-body></structured-macro>
<p>to grab all necessary bundles. If you type</p>
<structured-macro ac:macro-id="6b3333fb-c80d-47b7-a595-771c3082e7a2" ac:name="code" ac:schema-version="1"><plain-text-body>
smx@root:/&gt; osgi/list
</plain-text-body></structured-macro>
<p>you'll see all installed bundles (such as)</p>
<structured-macro ac:macro-id="8e41e7b1-ae40-427b-9c67-8e0808120e6a" ac:name="code" ac:schema-version="1"><plain-text-body>
[ 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)
</plain-text-body></structured-macro>
<structured-macro ac:macro-id="576d3e51-3af9-47f4-88f1-5a5f84f31e87" ac:name="note" ac:schema-version="1"><rich-text-body>
<p>This feature comes pre-installed with the ServiceMix ESB so previous steps are not necessary.</p></rich-text-body></structured-macro>
<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>
<structured-macro ac:macro-id="a385ff2a-036e-46fe-8ba0-af93c2646e12" ac:name="code" ac:schema-version="1"><plain-text-body>
smx@root:/&gt; osgi/uninstall [id]
</plain-text-body></structured-macro>
<p>In this example it would be</p>
<structured-macro ac:macro-id="a26ee2fb-4e5e-4f19-958b-1c860835dd2f" ac:name="code" ac:schema-version="1"><plain-text-body>
smx@root:/&gt; osgi/uninstall 44
smx@root:/&gt; osgi/uninstall 45
smx@root:/&gt; osgi/uninstall 46
smx@root:/&gt; osgi/uninstall 47
</plain-text-body></structured-macro>
<p>Now install new ones</p>
<structured-macro ac:macro-id="53adde10-a181-4b93-8ac2-f1e1aed51a9d" ac:name="code" ac:schema-version="1"><plain-text-body>
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
</plain-text-body></structured-macro>
<p>After successful installation, you should start your newly added bundles. You can do that by executing </p>
<structured-macro ac:macro-id="2e36945f-3f28-40c0-8f02-434e1f6fb271" ac:name="code" ac:schema-version="1"><plain-text-body>
smx@root:/&gt; osgi/start [id]
</plain-text-body></structured-macro>
<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>
<structured-macro ac:macro-id="79aa08e5-1cf7-4687-bd4a-7beaa0ca2fc7" ac:name="code" ac:schema-version="1"><plain-text-body>
smx@root:/&gt; osgi/install war:mvn:org.apache.activemq/activemq-web-console/5.3-SNAPSHOT/war?Webapp-Context=activemqweb
</plain-text-body></structured-macro>
<structured-macro ac:macro-id="fb6ee639-050c-4d91-bc59-bd20f9a77bc4" ac:name="note" ac:schema-version="1"><rich-text-body>
<p>You have to use the latest 5.3-SNAPSHOT web console, since this doesn't work right with previous versions.</p></rich-text-body></structured-macro>
<p>Also, if you have problems installing the war with the previous method, download it manually from <a shape="rect" 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>
<structured-macro ac:macro-id="78e51787-f354-4e01-a1c0-ae02e83e31b1" ac:name="code" ac:schema-version="1"><plain-text-body>
smx@root:/&gt; osgi/install war:file:///path_to_the_war/activemq-web-console-5.3-SNAPSHOT.war?Webapp-Context=activemqweb
</plain-text-body></structured-macro>
<p>Unfortunately the command</p>
<structured-macro ac:macro-id="7bd31bb7-08a4-4eb5-8ae8-bc7c1eeb6ec0" ac:name="code" ac:schema-version="1"><plain-text-body>
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
</plain-text-body></structured-macro>
<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>
<structured-macro ac:macro-id="2f39bbd9-fb88-48d5-921a-4497d9c1fe9f" ac:name="code" ac:schema-version="1"><plain-text-body>
smx@root:/&gt; osgi/list
</plain-text-body></structured-macro>
<p>you'll see the newly added bundle here.</p>
<structured-macro ac:macro-id="05683d0c-97d2-4db0-99b4-6a016f5cbaa4" ac:name="code" ac:schema-version="1"><plain-text-body>
[ 84] [Resolved ] [ ] [ 60] mvn_org.apache.activemq_activemq-web-console_5.3-SNAPSHOT_war (0)
</plain-text-body></structured-macro>
<p>It's time t start it now</p>
<structured-macro ac:macro-id="4aa83bb4-dba0-47c2-a7a6-1a4dd98a80a9" ac:name="code" ac:schema-version="1"><plain-text-body>
smx@root:/&gt; osgi/start 84
</plain-text-body></structured-macro>
<structured-macro ac:macro-id="2129747f-bc54-446f-bf13-3a7ecd75516e" ac:name="note" ac:schema-version="1"><rich-text-body><p> Use the id of your bundle</p></rich-text-body></structured-macro>
<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" href="http://localhost:8080/activemqweb">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>
<structured-macro ac:macro-id="c2ee2fe2-7748-46ba-8ccb-34f1c15b600a" ac:name="code" ac:schema-version="1"><plain-text-body>
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
</plain-text-body></structured-macro>
<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" href="http://localhost:8080/activemqweb">http://localhost:8080/activemqweb</a> and enjoy.</p></div>