⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jms5.html

📁 j2eePDF格式的电子书
💻 HTML
📖 第 1 页 / 共 4 页
字号:
The output of the program looks like this:</p><a name="wp81519"> </a><p class="pBodyRelative"><code class="cCode">Destination name is jms/Queue, type is queue<br />To end program, type Q or q, then &lt;return&gt;<br />Reading message: This is message 1<br />Reading message: This is message 2<br />Reading message: This is message 3</code></p><a name="wp86262"> </a><div class="pSmartList1"><li>Type <code class="cCode">Q</code> or <code class="cCode">q</code> to stop the program.</li></div></ol></div><a name="wp81600"> </a><h3 class="pHeading2">Running JMS Client Programs on Multiple Systems</h3><a name="wp81601"> </a><p class="pBody">JMS client programs can communicate with each other when they are running on different systems in a network. The systems must be visible to each other by name--the UNIX host name or the Microsoft Windows computer name--and must both be running the J2EE server. You do not have to install the tutorial examples on both systems; you can use the examples installed on one system if you can access its file system from the other system.</p><a name="wp97068"> </a><p class="pBody">Suppose that you want to run the <code class="cCode">SimpleProducer</code> program on one system, <code class="cCode">mars</code>, and the <code class="cCode">SimpleSynchConsumer</code> program on another system, <code class="cCode">earth</code>. Before you can do so, you need to perform these tasks:</p><div class="pSmartList1"><ul class="pSmartList1"><a name="wp96321"> </a><div class="pSmartList1"><li>Create two new administered objects</li></div><a name="wp96322"> </a><div class="pSmartList1"><li>Edit the source code</li></div><a name="wp96323"> </a><div class="pSmartList1"><li>Recompile the source code and update the client JAR files</li></div></ul></div><hr><a name="wp97074"> </a><p class="pNote">Note: A limitation in the JMS provider in the J2EE Application Server may cause a runtime failure to create a connection to systems that use the Dynamic Host Configuration Protocol (DHCP) to obtain an IP address. You can, however, create a connection <em class="cEmphasis">from</em> a system that uses DHCP <em class="cEmphasis">to</em> a system that does not use DHCP. In the examples in this tutorial, <code class="cCode">mars</code> can be a system that uses DHCP, and <code class="cCode">earth</code> can be a system that does not use DHCP.</p><hr><a name="wp96339"> </a><p class="pBody">Before you begin, start the server on both systems:</p><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp96353"> </a><div class="pSmartList1"><li>Start the Application Server on <code class="cCode">earth</code> and log in to the Admin Console.</li></div><a name="wp96340"> </a><div class="pSmartList1"><li>Start the Application Server on <code class="cCode">mars</code> and log in to the Admin Console.</li></div></ol></div><a name="wp96341"> </a><h4 class="pHeading3">Creating Administered Objects for Multiple Systems</h4><a name="wp96359"> </a><p class="pBody">To run these programs, you need to do the following:</p><div class="pSmartList1"><ul class="pSmartList1"><a name="wp96550"> </a><div class="pSmartList1"><li>Create a new connection factory on both <code class="cCode">earth</code> and <code class="cCode">mars</code></li></div><a name="wp96552"> </a><div class="pSmartList1"><li>Create a destination resource and physical destination on both <code class="cCode">earth</code> and <code class="cCode">mars</code></li></div></ul></div><a name="wp96549"> </a><p class="pBody">Create a new connection factory on <code class="cCode">earth</code> as follows:</p><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp96360"> </a><div class="pSmartList1"><li>In the Admin Console, expand the Java Message Service node, then click Connection Factories.</li></div><a name="wp96361"> </a><div class="pSmartList1"><li>Click New. The Create JMS Connection Factory screen appears.</li></div><a name="wp96362"> </a><div class="pSmartList1"><li>In the JNDI Name field, type <code class="cCode">jms/EarthQueueConnectionFactory</code>.</li></div><a name="wp96363"> </a><div class="pSmartList1"><li>Choose<code class="cCode"> javax.jms.QueueConnectionFactory</code> from the Type menu.</li></div><a name="wp96364"> </a><div class="pSmartList1"><li>Select the Enabled checkbox.</li></div><a name="wp96365"> </a><div class="pSmartList1"><li>Click OK.</li></div></ol></div><a name="wp96382"> </a><p class="pBody">Create a new connection factory with the same name on <code class="cCode">mars</code> as follows:</p><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp96383"> </a><div class="pSmartList1"><li>In the Admin Console, expand the Java Message Service node, then click Connection Factories.</li></div><a name="wp96384"> </a><div class="pSmartList1"><li>Click New. The Create JMS Connection Factory screen appears.</li></div><a name="wp96385"> </a><div class="pSmartList1"><li>In the JNDI Name field, type <code class="cCode">jms/EarthQueueConnectionFactory</code>.</li></div><a name="wp96386"> </a><div class="pSmartList1"><li>Choose<code class="cCode"> javax.jms.QueueConnectionFactory</code> from the Type menu.</li></div><a name="wp96387"> </a><div class="pSmartList1"><li>Select the Enabled checkbox.</li></div><a name="wp96399"> </a><div class="pSmartList1"><li>Click Add in the Additional Properties area. A Name/Value line appears.</li></div><a name="wp96400"> </a><div class="pSmartList1"><li>In the Name field, type <code class="cCode">MessageServiceAddressList</code>.</li></div><a name="wp96401"> </a><div class="pSmartList1"><li>In the Value field, type the name of the remote system (whatever the real name of <code class="cCode">earth</code> is). If the JMS service on the remote system uses a port number other than the default (7676), specify the port number also, using the syntax <code class="cVariable">sys-name</code><code class="cCode">:</code><code class="cVariable">port-number</code>.</li></div><a name="wp96499"> </a><div class="pSmartList1"><li>Click OK.</li></div></ol></div><a name="wp96053"> </a><p class="pBody">If you have been working on either <code class="cCode">earth</code> or <code class="cCode">mars</code> already, you have the queue on one system. On the system that does not have the queue, perform the following steps:</p><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp97117"> </a><div class="pSmartList1"><li>Use the Admin Console to create a physical destination named <code class="cCode">PhysicalQueue</code>, just as you did in <a  href="JMS5.html#wp80290">Creating JMS Administered Objects</a>.</li></div><a name="wp97106"> </a><div class="pSmartList1"><li>Use the Admin Console to create a destination resource named <code class="cCode">jms/Queue</code> and set its <code class="cCode">Name</code> property to the value <code class="cCode">PhysicalQueue</code>.</li></div></ol></div><a name="wp97028"> </a><h4 class="pHeading3">Running the Programs</h4><a name="wp96578"> </a><p class="pBody">These steps assume that you have the tutorial installed on only one of the two systems you are using.</p><a name="wp97160"> </a><p class="pBody">To edit, update, and run the programs, perform the following steps on the system where you first ran them:</p><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp81621"> </a><div class="pSmartList1"><li>In both <code class="cCode">SimpleProducer.java</code> and <code class="cCode">SimpleSynchConsumer.java</code>, change the line that looks up the connection factory so that it refers to the new connection factory:</li></div><a name="wp81622"> </a><p class="pBodyRelative"><code class="cCode">connectionFactory = (ConnectionFactory)<br />&nbsp;&nbsp;jndiContext.lookup(&quot;jms/EarthQueueConnectionFactory&quot;);</code></p><a name="wp81624"> </a><div class="pSmartList1"><li>Recompile the programs:</li></div><a name="wp86591"> </a><p class="pBodyRelative"><code class="cCode">asant build</code></p><a name="wp92466"> </a><div class="pSmartList1"><li>In <code class="cCode">deploytool</code>, choose Tools<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>Update Module Files to add the recompiled source files to the <code class="cCode">SimpleProducer.jar</code> and <code class="cCode">SimpleSynchConsumer.jar</code> files.</li></div><a name="wp97159"> </a><div class="pSmartList1"><li>Save the changed JAR files.</li></div><a name="wp86590"> </a><div class="pSmartList1"><li>Run <code class="cCode">SimpleProducer</code> on <code class="cCode">mars</code>:</li></div><a name="wp86602"> </a><p class="pBodyRelative"><code class="cCode">appclient -client SimpleProducer.jar jms/Queue queue 3</code></p><a name="wp86600"> </a><div class="pSmartList1"><li>Run <code class="cCode">SimpleSynchConsumer</code> on <code class="cCode">earth</code>:</li></div><a name="wp86628"> </a><p class="pBodyRelative"><code class="cCode">appclient -client SimpleSynchConsumer.jar jms/Queue queue</code></p></ol></div><a name="wp86599"> </a><p class="pBody">Because both connection factories have the same name, you can run either the producer or the consumer on either system.</p><a name="wp81631"> </a><p class="pBody">For examples showing how to deploy J2EE applications on two different systems, see <a  href="JMSJ2EEex4.html#wp83233">An Application Example that Consumes Messages from a Remote J2EE Server</a> and <a  href="JMSJ2EEex5.html#wp79839">An Application Example that Deploys a Message-Driven Bean on Two J2EE Servers</a>.</p><a name="wp90523"> </a><h4 class="pHeading3">Deleting the Connection Factory and Stopping the Server</h4><a name="wp90531"> </a><p class="pBody">You will need the connection factory <code class="cCode">jms/EarthQueueConnectionFactory</code> in the next chapter. However, if you wish to delete it, perform the following steps in the Admin Console:</p><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp92488"> </a><div class="pSmartList1"><li>Expand the Java Message Service node and click Connection Factories.</li></div><a name="wp97043"> </a><div class="pSmartList1"><li>Select the checkbox next to <code class="cCode">jms/EarthQueueConnectionFactory</code> and click Delete.</li></div></ol></div><a name="wp90540"> </a><p class="pBody">Remember to delete the connection factory on both systems.</p><a name="wp92493"> </a><p class="pBody">You may also use the Admin Console to delete the destinations and connection factories you created in <a  href="JMS5.html#wp80290">Creating JMS Administered Objects</a>. However, we recommend that you keep them, because they will be used in most of the examples in the next chapter. Once you have created them, they will be available whenever you restart the J2EE Application Server.</p><a name="wp90541"> </a><p class="pBody">Delete the class files for the programs as follows:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">asant clean<a name="wp90542"> </a></pre></div><a name="wp93118"> </a><p class="pBody">If you wish, you can manually delete the client JAR files.</p><a name="wp90543"> </a><p class="pBody">You can stop the J2EE Application Server as well, but you will need it to run the sample programs in the next section.</p>    </blockquote>   <img src="images/blueline.gif" width="550" height="8" ALIGN="BOTTOM" NATURALSIZEFLAG="3" ALT="Divider">    <table width="550" summary="layout" id="SummaryNotReq1">      <tr>	<td align="left" valign="center">	<font size="-1">	<a href="http://java.sun.com/j2ee/1.4/download.html#tutorial" target="_blank">Download</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/faq.html" target="_blank">FAQ</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/history.html" target="_blank">History</a>	</td>        <td align="center" valign="center"><a accesskey="p" href="JMS4.html"><img id="LongDescNotReq1" src="images/PrevArrow.gif" width="26" height="26" border="0" alt="Prev" /></a><a accesskey="c" href="J2EETutorialFront.html"><img id="LongDescNotReq1" src="images/UpArrow.gif" width="26" height="26" border="0" alt="Home" /></a><a accesskey="n" href="JMS6.html"><img id="LongDescNotReq3" src="images/NextArrow.gif" width="26" height="26" border="0" alt="Next" /></a><a accesskey="i" href="J2EETutorialIX.html"></a>        </td>	<td align="right" valign="center">	<font size="-1">	<a href="http://java.sun.com/j2ee/1.4/docs/api/index.html" target="_blank">API</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/search.html" target="_blank">Search</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/sendusmail.html" target="_blank">Feedback</a></font>	</font>	</td>      </tr>    </table>    <img src="images/blueline.gif" width="550" height="8" ALIGN="BOTTOM" NATURALSIZEFLAG="3" ALT="Divider"><p><font size="-1">All of the material in <em>The J2EE(TM) 1.4 Tutorial</em> is <a href="J2EETutorialFront2.html">copyright</a>-protected and may not be published in other workswithout express written permission from Sun Microsystems.</font>  </body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -