📄 jmsj2eeex2.html
字号:
<a name="wp89418"> </a><div class="pSmartList1"><li>Click OK.</li></div></ol></div><a name="wp89353"> </a><h4 class="pHeading3">Packaging the Session Bean</h4><a name="wp89519"> </a><p class="pBody">To package the session bean, perform the following steps:</p><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp89526"> </a><div class="pSmartList1"><li>Choose File<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>New<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>Enterprise Bean to start the Enterprise Bean Wizard.</li></div><a name="wp89527"> </a><div class="pSmartList1"><li>In the EJB JAR screen:</li></div><div class="pSmartList2"><ol type="a" class="pSmartList2"><a name="wp89566"> </a><div class="pSmartList2"><li>Select Create New JAR Module in Application and verify that the application is <code class="cCode">ClientSessionMDBApp</code>. In the JAR Name field, type <code class="cCode">EBJAR</code>.</li></div><a name="wp89529"> </a><div class="pSmartList2"><li>Click the Edit button next to the Contents text area.</li></div><a name="wp89530"> </a><div class="pSmartList2"><li>In the dialog box, locate the <code class="cCode">build/sb/</code> directory. Select <code class="cCode">PublisherBean.class,</code> <code class="cCode">PublisherHome.class</code>, and <code class="cCode">PublisherRemote.class</code> from the Available Files tree and click Add, then OK.</li></div></ol></div><a name="wp89531"> </a><div class="pSmartList1"><li>In the General screen:</li></div><div class="pSmartList2"><ol type="a" class="pSmartList2"><a name="wp89533"> </a><div class="pSmartList2"><li>From the Enterprise Bean Class menu, choose <code class="cCode">sb.PublisherBean</code>.</li></div><a name="wp92690"> </a><div class="pSmartList2"><li>Verify that the Enterprise Bean Name is <code class="cCode">PublisherBean</code> and the Enterprise Bean Type is Stateless Session.</li></div><a name="wp89535"> </a><div class="pSmartList2"><li>In the Remote Interfaces area, choose <code class="cCode">sb.PublisherHome</code> from the Remote Home Interface menu and <code class="cCode">sb.PublisherRemote</code> from the Remote Interface menu.</li></div></ol></div></ol></div><a name="wp92693"> </a><p class="pBody">After you finish the wizard, perform the following steps:</p><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp91907"> </a><div class="pSmartList1"><li>Click the <code class="cCode">PublisherBean</code> node, then click the Msg Dest Refs tab. In the inspector pane:</li></div><div class="pSmartList2"><ol type="a" class="pSmartList2"><a name="wp91933"> </a><div class="pSmartList2"><li>Click Add. A dialog box opens.</li></div><a name="wp91908"> </a><div class="pSmartList2"><li>Type <code class="cCode">jms/TopicName</code> in the Coded Name field.</li></div><a name="wp91909"> </a><div class="pSmartList2"><li>Choose <code class="cCode">javax.jms.Topic</code> from the Destination Type menu.</li></div><a name="wp91910"> </a><div class="pSmartList2"><li>Choose Produces from the Usage menu.</li></div><a name="wp91911"> </a><div class="pSmartList2"><li>Type <code class="cCode">PhysicalTopic</code> in the Destination Name field.</li></div></ol></div><a name="wp91912"> </a><div class="pSmartList1"><li>Click the <code class="cCode">PublisherBean</code> node, then click the Resource Refs tab. In the inspector pane:</li></div><div class="pSmartList2"><ol type="a" class="pSmartList2"><a name="wp91913"> </a><div class="pSmartList2"><li>Click Add.</li></div><a name="wp91914"> </a><div class="pSmartList2"><li>Type <code class="cCode">jms/MyConnectionFactory</code> in the Coded Name field.</li></div><a name="wp91915"> </a><div class="pSmartList2"><li>Choose <code class="cCode">javax.jms.ConnectionFactory</code> from the Type menu.</li></div><a name="wp91916"> </a><div class="pSmartList2"><li>Type <code class="cCode">jms/TopicConnectionFactory</code> in the JNDI name field, and type <code class="cCode">j2ee</code> in both the User Name and Password fields.</li></div></ol></div><a name="wp91945"> </a><div class="pSmartList1"><li>Click the <code class="cCode">PublisherBean</code> node, then click the Transactions tab. In the inspector pane, select the Container-Managed radio button.</li></div><a name="wp91245"> </a><div class="pSmartList1"><li>Click the <code class="cCode">EBJAR</code> node, then click the Message Destinations tab. In the inspector pane:</li></div><div class="pSmartList2"><ol type="a" class="pSmartList2"><a name="wp89551"> </a><div class="pSmartList2"><li>Click Add.</li></div><a name="wp89552"> </a><div class="pSmartList2"><li>Type <code class="cCode">PhysicalTopic</code> in the Destination Name field. When you press Enter, this name appears in the Display Name field, and <code class="cCode">PublisherBean</code> appears in the Producers area.</li></div><a name="wp89553"> </a><div class="pSmartList2"><li>Type <code class="cCode">jms/Topic</code> in the JNDI Name field.</li></div></ol></div></ol></div><a name="wp89520"> </a><h4 class="pHeading3">Packaging the Message-Driven Bean</h4><a name="wp89639"> </a><p class="pBody">You will package the message-driven bean in the same JAR file as the session bean, for greater efficiency.</p><a name="wp89678"> </a><p class="pBody">To package the message-driven bean, perform the following steps:</p><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp89640"> </a><div class="pSmartList1"><li>Choose File<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>New<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>Enterprise Bean to start the Enterprise Bean Wizard, then click Next.</li></div><a name="wp89641"> </a><div class="pSmartList1"><li>In the EJB JAR screen:</li></div><div class="pSmartList2"><ol type="a" class="pSmartList2"><a name="wp89642"> </a><div class="pSmartList2"><li>Select the Add to Existing JAR Module radio button and verify that the module is <code class="cCode">EBJAR (ClientSessionMDBApp)</code>.</li></div><a name="wp89644"> </a><div class="pSmartList2"><li>Click the Edit button next to the Contents text area. </li></div><a name="wp89645"> </a><div class="pSmartList2"><li>In the dialog box, locate the <code class="cCode">build/mdb/</code> directory. Select <code class="cCode">MessageBean.class</code> from the Available Files tree and click Add, then OK.</li></div></ol></div><a name="wp89646"> </a><div class="pSmartList1"><li>In the General screen:</li></div><div class="pSmartList2"><ol type="a" class="pSmartList2"><a name="wp89648"> </a><div class="pSmartList2"><li>From the Enterprise Bean Class menu, choose <code class="cCode">mdb.MessageBean</code>.</li></div><a name="wp89649"> </a><div class="pSmartList2"><li>In the Enterprise Bean Name field, accept the default value, <code class="cCode">MessageBean</code>.</li></div><a name="wp92722"> </a><div class="pSmartList2"><li>Verify that the Enterprise Bean Type is Message-Driven.</li></div></ol></div><a name="wp89651"> </a><div class="pSmartList1"><li>In the Message-Driven Bean Settings screen:</li></div><div class="pSmartList2"><ol type="a" class="pSmartList2"><a name="wp91969"> </a><div class="pSmartList2"><li>For the Messaging Service, accept the default, JMS.</li></div><a name="wp91970"> </a><div class="pSmartList2"><li>Choose <code class="cCode">javax.jms.Topic</code> from the Destination Type menu.</li></div><a name="wp89658"> </a><div class="pSmartList2"><li>Choose <code class="cCode">PhysicalTopic</code> from the Target Destination Name menu.</li></div><a name="wp89659"> </a><div class="pSmartList2"><li>Select the Durable Subscription checkbox. In the Subscription Name field, type <code class="cCode">MySub</code>.</li></div><a name="wp93734"> </a><div class="pSmartList2"><li>In the Message Selector field, type the following:</li></div><a name="wp91999"> </a><p class="pBodyRelative"><code class="cCode"> NewsType = 'Sports' OR NewsType = 'Opinion'</code></p><a name="wp93510"> </a><div class="pSmartList2"><li>In the Connection Factory JNDI Name (Sun-specific Setting) field, type <code class="cCode">jms/DurableTopicConnectionFactory</code>.</li></div></ol></div></ol></div><a name="wp93207"> </a><p class="pBody">After you finish the wizard, perform the following steps:</p><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp91959"> </a><div class="pSmartList1"><li>Click the <code class="cCode">MessageBean</code> node, then click the Transactions tab. In the inspector pane, select the Container-Managed radio button.</li></div><a name="wp89662"> </a><div class="pSmartList1"><li>Click the <code class="cCode">EBJAR</code> node, then click the Message Destinations tab and select <code class="cCode">PhysicalTopic</code>. You will see that <code class="cCode">MessageBean</code> now appears in the Consumers area.</li></div></ol></div><a name="wp92743"> </a><h4 class="pHeading3">Packaging the Application Client</h4><a name="wp92744"> </a><p class="pBody">To package the application client, perform the following steps:</p><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp92745"> </a><div class="pSmartList1"><li>Choose File<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>New<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>Application Client to start the Application Client Wizard.</li></div><a name="wp92746"> </a><div class="pSmartList1"><li>In the JAR File Contents screen:</li></div><div class="pSmartList2"><ol type="a" class="pSmartList2"><a name="wp92747"> </a><div class="pSmartList2"><li>Verify that Create New AppClient Module in Application is selected and that the application is <code class="cCode">ClientSessionMDBApp</code>.</li></div><a name="wp92748"> </a><div class="pSmartList2"><li>In the AppClient Name field, type <code class="cCode">MyAppClient</code>.</li></div><a name="wp92749"> </a><div class="pSmartList2"><li>Click the Edit button next to the Contents text area.</li></div><a name="wp92750"> </a><div class="pSmartList2"><li>In the dialog box, locate the <code class="cCode">build/client/</code> directory. Select <code class="cCode">MyAppClient.class</code> from the Available Files tree and click Add, then OK.</li></div></ol></div><a name="wp92751"> </a><div class="pSmartList1"><li>In the General screen, choose <code class="cCode">client.MyAppClient</code> in the Main Class combo box.</li></div></ol></div><a name="wp92752"> </a><p class="pBody">After you finish the wizard, click the EJB Refs tab, then click Add in the inspector pane. In the dialog box:</p><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp92753"> </a><div class="pSmartList1"><li>Type <code class="cCode">ejb/remote/Publisher</code> in the Coded Name field.</li></div><a name="wp92754"> </a><div class="pSmartList1"><li>Choose Session from the EJB Type menu.</li></div><a name="wp92755"> </a><div class="pSmartList1"><li>Choose Remote from the Interfaces menu.</li></div><a name="wp92756"> </a><div class="pSmartList1"><li>Type <code class="cCode">sb.PublisherHome</code> in the Home Interface field.</li></div><a name="wp92757"> </a><div class="pSmartList1"><li>Type <code class="cCode">sb.PublisherRemote</code> in the Local/Remote Interface field.</li></div></ol></div><a name="wp92760"> </a><p class="pBody">When you return to the EJB Refs inspector pane, select the bean. In the Sun-specific Settings area, select JNDI Name and type <code class="cCode">PublisherBean</code> in the text field.</p><a name="wp89717"> </a><h4 class="pHeading3">Updating the JNDI Names</h4><a name="wp89718"> </a><p class="pBody">You need to update the JNDI name for the message-driven bean so that it specifies the destination it receives messages from, not the bean name. </p><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp89719"> </a><div class="pSmartList1"><li>Select <code class="cCode">ClientSessionMDBApp</code> and click the JNDI Names tab.</li></div><a name="wp89720"> </a><div class="pSmartList1"><li>Type <code class="cCode">jms/Topic</code> in the JNDI Name field for the <code class="cCode">MessageBean</code> component.</li></div></ol></div><a name="wp89721"> </a><p class="pBody">Verify that the JNDI names for the application components are correct. They should appear as shown in <a href="JMSJ2EEex2.html#wp89726">Table 30-1</a> and <a href="JMSJ2EEex2.html#wp92051">Table 30-2</a>.</p><div align="left"><table border="1" summary="Application Pane for ClientSessionMDBApp" id="wp89726"> <caption><a name="wp89726"> </a><div class="pTableTitle">Table 30-1 Application Pane for ClientSessionMDBApp</div></caption> <tr align="center"> <th><a name="wp92023"> </a><div class="pCellHeading">Component Type</div></th> <th><a name="wp92025"> </a><div class="pCellHeading">Component</div></th> <th><a name="wp92027"> </a><div class="pCellHeading">JNDI Name</div></th></tr> <tr align="left"> <td><a name="wp92005"> </a><div class="pCellBody">EJB</div></td> <td><a name="wp92007"> </a><div class="pCellBody">MessageBean</div></td> <td><a name="wp92009"> </a><div class="pCellBody">jms/Topic</div></td></tr> <tr align="left"> <td><a name="wp89789"> </a><div class="pCellBody">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -