Using the JMS JCA Wizard

ProcedureTo Initiate a Request-Reply

JMS messaging solutions need to satisfy 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, however, may take some time if the recipient is not active for some time or may not take place at all if the recipient never appears.

  1. From the File menu, select New Project.

    The New Project dialog box is displayed.

  2. Select the Enterprise folder, then select the EJB Module from the Projects side of the dialog box and click Next

    The New EJB Module dialog box is displayed.

  3. Enter a unique Project Name and click Next.

    The Server and Settings dialog box is displayed.

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

    The new project is created.

  5. Right-click on the project, select New -> Other.

    The New File dialog box is displayed.

    Figure 1–18 New JCA Message-Driven Bean

    Create MDB

  6. Select the Enterprise folder, then select JCA Message-Driven Bean from the File Types side of the dialog box and click Next.

    The New JCA Message-Driven Bean dialog box is displayed.

    Figure 1–19 Configuring the Message-Driven Bean

    The Name MDB Field

  7. Enter a unique Class Name, a valid Package name and click Next.

    The Choose Inbound JCA dialog box is displayed.

  8. Select the JMS Adapter (default) and click Next.

    The Edit Activation Configuration dialog box is displayed.

    Figure 1–20 Edit Activation Configuration

    Edit Activation Configuration

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

    A new Message-Driven Bean is created.

  10. From the Palette window, drag an instance of a Queue into the Java Editor.

    A Create JMS Destination dialog box is displayed.

    Figure 1–21 JMS Destination

    JMS Destination

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

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

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

    The JMS Adapter Declaration dialog box is displayed.

    Figure 1–22 JMS Adapter Declaration

    JMS Adapter Declaration

  13. Enter a valid Method Name and click Finish.

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

  14. From the Palette window, drag an instance of the Request-Reply into the method created (described in Steps 12 and 13).

    The Create JMS Request-Reply dialog box is displayed. The Select Method will already be set by default.

    Figure 1–23 JMS Request-Reply

    JMS Request-Reply

  15. Select a valid Request Destination and the jms/notx/default setting for the Non-transactional Connection Factory, click OK.

  16. In the Request-Reply method, enter the following code:

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

    Figure 1–24 Request-Reply Method

    Request-Reply Method

  17. Save file.

  18. Create a New JCA Message-Driven Bean (as described in steps 5 - 9) for the Queue Request-Reply destination (as described in step 15).

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

    The JMS Adapter Declaration dialog box is displayed.

    Figure 1–25 Reply Method

    Reply Method

  20. Enter "reply" as the Method Name and click Finish.

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

  21. In the reply method enter the following code:

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

    Figure 1–26 Reply Method in the Java Editor

    Reply Method in the Java Editor

    This code sends the incoming message to the reply destination.

  22. Save file.

  23. Build and deploy the project.