Using the JMS JCA Wizard

ProcedureCreate a Reference to the Destination Object

Creating a reference to the destination object allows a message to be sent to the destination object in the Java code. For this exercise, the destination object is Queue2.

  1. In the NetBeans IDE, open the Message-Driven Bean file you created in To Create the JCA Message-Driven Bean.

    The file is located in the Enterprise Beans node of the JMSJCASample project.

  2. Drag-and-drop the Queue icon from the Palette panel on the right to any place in Java editor, as shown below.

    Figure 14 JCA Message Bean Sample — Queue

    JCA Message Bean Sample — Queue

    The Create JMS Destination dialog box appears.

  3. For this exercise, enter the following information into the fields:

    • JNDI Name = jms/Queue2 (You can select this value by clicking the ellipsis button and expanding the tree.)

    • Variable Name = queue2

    Figure 15 Create JMS Destination

    Create Destination

  4. Click OK.

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

    The code fragment inside the queueToQueue(...) method should be similar to the example shown below:


    private void queueToQueue(Message message, javax.jms.Session jmsSession) 
               throws java.lang.Exception {
        if (message instanceof javax.jms.TextMessage)  {
            String oldContent = ((javax.jms.TextMessage) message).getText();
            javax.jms.TextMessage newMessage = jmsSession.createTextMessage("Hello " 
                   + oldContent);
            jmsSession.createProducer(queue2).send(newMessage);
        }
    }

    Note –

    The above code has been wrapped to fit onto the page.


  6. Save the changes.