📄 mdb7.html
字号:
<?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <title>deploytool Tips for Components that Send Messages</title> <link rel="StyleSheet" href="document.css" type="text/css" media="all" /> <link rel="StyleSheet" href="catalog.css" type="text/css" media="all" /> <link rel="Table of Contents" href="J2EETutorialTOC.html" /> <link rel="Previous" href="MDB6.html" /> <link rel="Next" href="EJBQL.html" /> <link rel="Index" href="J2EETutorialIX.html" /> </head> <body> <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="MDB6.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="EJBQL.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"> <blockquote><a name="wp80583"> </a><h2 class="pHeading1">deploytool Tips for Components that Send Messages</h2><a name="wp80474"> </a><p class="pBody">You set resource references and message destination references for any component that sends messages: a client, a session or entity bean, or even another message-driven bean. For examples, see Chapter <a href="JMSJ2EEex.html#wp78297">30</a>. In this application, the client is the sending component. To view this example in <code class="cCode">deploytool</code>, expand the <code class="cCode">SimpleMessageApp</code> node, then select <code class="cCode">SimpleMessageClient</code> from the tree view.</p><a name="wp79836"> </a><h3 class="pHeading2">Setting the Resource References</h3><a name="wp80488"> </a><p class="pBody">You use the Resource Refs tabbed pane to specify the connection factory references for the component.</p><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp79837"> </a><div class="pSmartList1"><li>In the tree view, select the client node.</li></div><a name="wp79838"> </a><div class="pSmartList1"><li>Select the Resource Refs tab.</li></div><a name="wp79839"> </a><div class="pSmartList1"><li>Click Add.</li></div><a name="wp79840"> </a><div class="pSmartList1"><li>In the Coded Name field, enter the name that matches the parameter of the <code class="cCode">lookup</code> method in the client's code. For example, since the <code class="cCode">lookup</code> parameter is <code class="cCode">java:comp/env/jms/MyConnectionFactory</code>, the Coded Name should be <code class="cCode">jms/MyConnectionFactory</code>.</li></div><a name="wp79841"> </a><div class="pSmartList1"><li>In the Type field, select the connection factory class that matches the destination type. The destination class in the code is <code class="cCode">javax.jms.ConnectionFactory</code>, so select that class. </li></div><a name="wp79842"> </a><div class="pSmartList1"><li>In the Authentication field, in most cases you will select Container. You would select Application if your code explicitly logs on to the messaging service.</li></div><a name="wp81354"> </a><div class="pSmartList1"><li>In the Sharable field, make sure the checkbox is selected. This choice allows the container to optimize connections.</li></div><a name="wp81358"> </a><div class="pSmartList1"><li>In the Sun-specific Settings area, enter <code class="cCode">jms/QueueConnectionFactory</code> in the JNDI Name field. Enter <code class="cCode">j2ee</code> in both the User Name and Password fields.</li></div></ol></div><a name="wp81355"> </a><h3 class="pHeading2">Setting the Message Destination References</h3><a name="wp80513"> </a><p class="pBody">For any new application, you use the Msg Dest Refs tab to specify the destination of messages. The Resource Env Refs tab provides similar information, but it is available primarily for backward compatibility.</p><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp79846"> </a><div class="pSmartList1"><li>Select the Msg Dest Refs tab.</li></div><a name="wp79847"> </a><div class="pSmartList1"><li>Click Add.</li></div><a name="wp79848"> </a><div class="pSmartList1"><li>In the Coded Name field of the dialog box that appears, type a name that matches the parameter of the <code class="cCode">lookup</code> call that locates the queue or topic. In this example, the <code class="cCode">lookup</code> parameter is <code class="cCode">java:comp/env/jms/QueueName</code>, so the Coded Name is <code class="cCode">jms/QueueName</code>.</li></div><a name="wp79849"> </a><div class="pSmartList1"><li>In the Destination Type field, select the class that matches the destination type (in this case, <code class="cCode">javax.jms.Queue</code>).</li></div><a name="wp80526"> </a><div class="pSmartList1"><li>From the Usage menu, select either Produces or ConsumesProduces, depending on whether this component sends messages or both sends and receives messages. For this example, select Produces.</li></div><a name="wp80527"> </a><div class="pSmartList1"><li>In the Destination Name field, enter the name of the destination you created (in this case, <code class="cCode">PhysicalQueue</code>).</li></div></ol></div><a name="wp80529"> </a><h3 class="pHeading2">Setting the Message Destinations</h3><a name="wp80530"> </a><p class="pBody">When you use the Msg Dest Refs tab, you also use the Message Destinations tab to link the destination to its JNDI name.</p><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp80533"> </a><div class="pSmartList1"><li>Select the Message Destinations tab.</li></div><a name="wp80540"> </a><div class="pSmartList1"><li>Click Add.</li></div><a name="wp80541"> </a><div class="pSmartList1"><li>In the Destination Name field, type the name of the destination (in this case, <code class="cCode">PhysicalQueue</code>) and press Return. The name also appears in the Display Name field. The names of the components that consume and produce messages for the destination appear in the Producers and Consumers areas.</li></div><a name="wp80545"> </a><div class="pSmartList1"><li>In the JNDI Name field, type the name of the JMS resource you created (in this case, <code class="cCode">jms/Queue</code>).</li></div></ol></div><a name="wp79850"> </a><h4 class="pHeading3">Specifying the JNDI Names</h4><a name="wp79851"> </a><p class="pBody">The JNDI name for a message-driven bean is the name of the destination resource.</p><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp81560"> </a><div class="pSmartList1"><li>In the tree view, select the application's node.</li></div><a name="wp79852"> </a><div class="pSmartList1"><li>Select the JNDI Names tab and enter the appropriate names. For example, the <code class="cCode">SimpleMessageApp</code> discussed in this chapter uses the JNDI names shown in <a href="MDB7.html#wp79859">Table 23-1</a>.<div align="left"><table border="1" summary="JNDI Names for the SimpleMessageApp Application" id="wp79859"> <caption><a name="wp79859"> </a><div class="pTableTitle">Table 23-1 JNDI Names for the SimpleMessageApp Application</div></caption> <tr align="center"> <th><a name="wp79863"> </a><div class="pCellHeading">Component or Reference Name</div></th> <th><a name="wp79865"> </a><div class="pCellHeading">JNDI Name</div></th></tr> <tr align="left"> <td><a name="wp79867"> </a><div class="pCellBody"><code class="cCode">SimpleMessageBean</code></div></td> <td><a name="wp79869"> </a><div class="pCellBody"><code class="cCode">jms/Queue</code></div></td></tr> <tr align="left"> <td><a name="wp79871"> </a><div class="pCellBody"><code class="cCode">jms/MyConnectionFactory</code></div></td> <td><a name="wp79873"> </a><div class="pCellBody"><code class="cCode">jms/QueueConnectionFactory</code></div></td></tr></table></div></li></div></ol></div><a name="wp80588"> </a><p class="pBody"></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="MDB6.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="EJBQL.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 + -