2014-10-31 06:20:28 -04:00
|
|
|
<html>
|
|
|
|
<head>
|
2014-11-19 03:44:57 -05:00
|
|
|
<title>ActiveMQ Embedded JMS Server Example</title>
|
2014-10-31 06:20:28 -04:00
|
|
|
<link rel="stylesheet" type="text/css" href="../common/common.css" />
|
|
|
|
<link rel="stylesheet" type="text/css" href="../common/prettify.css" />
|
|
|
|
<script type="text/javascript" src="../common/prettify.js"></script>
|
|
|
|
</head>
|
|
|
|
<body onload="prettyPrint()">
|
|
|
|
<h1>Embedded JMS Server Example</h1>
|
|
|
|
|
2014-11-19 03:44:57 -05:00
|
|
|
<p>This examples shows how to setup and run an embedded JMS server using ActiveMQ along with ActiveMQ configuration files.</p>
|
2014-10-31 06:20:28 -04:00
|
|
|
|
|
|
|
<h2>Example step-by-step</h2>
|
|
|
|
<p><i>To run the example, simply type <code>mvn verify</code> from this directory</i></p>
|
|
|
|
|
|
|
|
<ol>
|
2014-11-19 03:44:57 -05:00
|
|
|
<li>Create ActiveMQ core configuration files and make sure they are within your classpath. By default, ActiveMQ
|
2014-11-19 14:58:44 -05:00
|
|
|
expects the classnames to be "activemq-configuration.xml", "activemq-jms.xml", and "activemq-users.xml".</li>
|
2014-11-19 03:44:57 -05:00
|
|
|
<li>Create and start ActiveMQ JMS server</li>
|
2014-10-31 06:20:28 -04:00
|
|
|
<pre class="prettyprint">
|
|
|
|
<code>EmbeddedJMS jmsServer = new EmbeddedJMS();
|
|
|
|
jmsServer.start();</code>
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
<p>At this point the JMS server is started and any JMS clients can look up JMS resources from the JNDI to send/receive
|
|
|
|
messages from the server. To keep the example simple, we will send and receive a JMS message from the same JVM
|
|
|
|
used to run the JMS server.</p>
|
|
|
|
|
|
|
|
<li>Lookup JMS resources defined in the configuration </li>
|
|
|
|
<pre class="prettyprint">
|
|
|
|
<code>ConnectionFactory cf = (ConnectionFactory)context.lookup("/cf");
|
|
|
|
Queue queue = (Queue)context.lookup("/queue/queue1");</code>
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
<li>Send and receive a message using JMS API</li>
|
|
|
|
<p>See the <a href="../../queue/readme.html">Queue Example</a> for detailed steps to send and receive a JMS message</p>
|
|
|
|
|
|
|
|
<p>Finally, we stop the JMS server and its associated resources.</p>
|
|
|
|
|
|
|
|
<li>Stop the JMS server</li>
|
|
|
|
<pre class="prettyprint">
|
|
|
|
<code>jmsServer.stop();</code>
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
<li>Stop the JNDI server</li>
|
|
|
|
<pre class="prettyprint">
|
|
|
|
<code>naming.stop();
|
|
|
|
jndiServer.stop();</code>
|
|
|
|
</pre>
|
|
|
|
</ol>
|
|
|
|
</body>
|
|
|
|
</html>
|