Using the JMS JCA Wizard

ProcedureTo Send a JMS TextMessage

This topic provides instructions on sending a JMS message to a destination (Queue2). For purposes of these instructions, the message content to Queue2 will be "Hello " concatenated with the message content received from the "onMessage()" method from Queue1(refer to the previous topic for more information about receiving JMS messages).

  1. Go to the Glassfish admin console and create an Admin Object Resource for Queue2, similar to the steps for Queue1.

    1. Go to "Resources->Connectors->Admin Object Resources-> and click New.

    2. Enter the following fields:

      • JNDI Name = jms/Queue2

      • Resource Type = javax.jms.Queue

      • Resource Adapter = sun-jms-adapter

    3. Click Next.

    4. Enter the physical destination name of the resource as Queue2.

    5. Click Finish.

  2. Go back to the NetBeans IDE.

  3. After the JMS message is received inside the MDB file of the onMessage() method, send a message to Queue2. To send a message, do the following:

    1. Obtain a JMS Session instance.

    2. Create a new JMS message, object, or message producer.

    3. Drag-and-drop the Session icon from the palette window (located on the right side) to the inside of onMessage() method as shown in the figure below:

      Figure 1–13 JCA Message Bean Sample — Session

      Message Bean Sample

      The JCA Wizard dialog box will be displayed.

    4. Enter information for the following fields:

      • Method Name = queueToQueue

      • Resource JNDI Name = jms/tx/jmq1

      Figure 1–14 JCA Adapter Declaration

      Adapter Declaration

    5. Click Finish.

      Several Java code fragments will be generated as a result, in particular the queueToQueue(...) method, which can be implemented to process the incoming message.

  4. Create a reference to the Queue2 destination object.

    This allows a message to be sent to the destination object in the Java code.

  5. Drag-and-drop the Queue icon from the palette window (located on the right side) to any place in Java editor as shown below:

    Figure 1–15 JCA Message Bean Sample — Queue

    JCA Message Bean Sample — Queue

    The Create JMS Destination dialog box will display.

  6. Enter the required information into the following fields:

    • JNDI name = jms/Queue2 (You can select this value using the browse button, instead of typing)

    • Variable Name = queue2

    Figure 1–16 Create JMS Destination

    Create Destination

  7. Click OK.

  8. Write the actual code to create a new JMS message and send it to Queue2.

    The code fragment inside the queueToQueue(...) method will look like the example shown below:

    Figure 1–17 Sample code

    sample code

  9. Save the modifications made.