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.
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.
Drag-and-drop the Queue icon from the Palette panel on the right to any place in Java editor, as shown below.
The Create JMS Destination dialog box appears.
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
Click OK.
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); } } |
The above code has been wrapped to fit onto the page.
Save the changes.