Using the JMS JCA Wizard

Initiating a Request-Reply Transaction

JMS messaging solutions need to satisfy the requirements of operating on a fire-and-forget or a store-and-forward basis. This messaging infrastructure is used to deliver each message to the intended recipient whether that recipient is active at the time of send or not. In a request-reply pattern, messages are delivered to the messaging system, which immediately acknowledges that it has taken the responsibility for delivery to the ultimate recipient. That delivery might take some time if the recipient is not active for a period or might not take place at all if the recipient never appears.

Perform the following steps to initiate a request-reply transaction:

ProcedureTo Create the EJB Module Project

  1. From the File menu, select New Project.

    The New Project dialog box appears.

  2. Select Java EE under Categories, and then select EJB Module under Projects.

  3. Click Next.

    The Name and Location window appears.

  4. Enter a unique Project Name and the location to store the project files.

  5. Click Next.

    The Server and Settings window appears.

  6. Accept the default settings for the server and click Finish.

    The new project is created.

ProcedureTo Create a Message Driven Bean

  1. Right-click the new project, and then select New -> Other.

    The New File Wizard appears.

    Figure 16 New JCA Message-Driven Bean

    Create MDB

  2. Select Java EE under Categories, and then select JCA Message-Driven Bean under File Types .

  3. Click Next.

    The Name and Location window appears.

    Figure 17 Configuring the Message-Driven Bean

    The Name MDB Field

  4. Enter a unique Class Name and a valid Package name.

  5. Click Next.

    The Choose Inbound JCA window appears.

  6. Select the JMS Adapter and click Next.

    The Edit Activation Configuration window appears.

    Figure 18 Edit Activation Configuration

    Edit Activation Configuration

  7. Set the Destination lookup to the JNDI Name of the Queue and click Finish.

    A new Message-Driven Bean is created.

  8. Drag a Queue rom the Palette panel on the right into the Java Editor.

    The Create JMS Destination dialog box appears.

    Figure 19 JMS Destination

    JMS Destination

  9. Enter a valid JNDI Name, Variable Name, and click OK.

    The Java code for the Queue instance is populated into the Java Editor. Repeat the above steps for as many Queues that are needed.

  10. Drag a Session from the Palette panel in the right into the onMessage() method in the Java Editor.

    The JMS Adapter Declaration dialog box appears.

    Figure 20 JMS Adapter Declaration

    JMS Adapter Declaration

  11. Enter a valid method name, such as RequestReply and click Finish.

    The Java code for the JMS Session is populated into the Java Editor.

  12. Drag a Request-Reply from the Palette panel on the right into the new method.

    The Create JMS Request-Reply dialog box appears.

    Figure 21 JMS Request-Reply

    JMS Request-Reply

  13. Select following values for the fields:

    • Select Method – Select the method you specified earlier on the JMS Adapter Declaration dialog box.

    • Request Message – Select message.

    • Request Destination – Select the JMS queue or topic you created for the adapter.

    • Non-transactional Connection Factory – Select a connection factory that contains “notx” in the name.

  14. Click OK.

  15. In the Request-Reply method, enter the following code beneath the first line of code:

    jmsSession.createProducer(queue2).send(replyMessage);

    Figure 22 Request-Reply Method

    Request-Reply Method

  16. Save the file.

ProcedureTo Create a JCA Message-Driven Bean for the Destination

  1. From the NetBeans Palette window, drag an instance of the JMS Session into the onMessage() method in the Java Editor.

    The JMS Adapter Declaration dialog box appears.

    Figure 23 Reply Method

    Reply Method

  2. Enter reply as the method name and click Finish.

    The Java code for the JMS Session is populated into the Java Editor.

  3. In the reply method enter the following code:

    jmsSession.createProducer(message.getJMSReplyTo()).send(message);

    Figure 24 Reply Method in the Java Editor

    Reply Method in the Java Editor

    This code sends the incoming message to the reply destination.

  4. Save the file.

  5. Build and deploy the project.