Skip Navigation Links | |
Exit Print View | |
Oracle Java CAPS JMS JCA Wizard User's Guide Java CAPS Documentation |
To Create an Admin Object Resource
To Create the EJB Module Project
To Create the JCA Message-Driven Bean
To Create an Admin Object Resource
To Define a JMS Session Instance
Initiating a Request-Reply Transaction
To Create the EJB Module Project
This topic provides instructions for sending a JMS message to a destination (Queue2). For purposes of this exercise, the message content to Queue2 is "Hello " concatenated with the message content received from the onMessage() method from Queue1. For more information about receiving JMS messages, see Receiving a JMS Text Message.
Perform the following steps to send a JMS text message:
The URL for the Admin Console is http://HostName:PortNumber. The default port number is 4848.
JNDI Name = jms/Queue2
Resource Type = javax.jms.Queue
Resource Adapter = sun-jms-adapter
This is the physical destination name of the resource.
You need to create a JMS message, object, or message producer to send a message to Queue2 once the JMS message is received inside the MDB file of the onMessage() method.
The file is located in the Enterprise Beans node of the JMSJCASample project.
Figure 12 JCA Message Bean Sample — Session
The JCA Wizard dialog box appears.
Method Name = queueToQueue
Resource JNDI Name = jms/tx/jmq1
Figure 13 JCA Adapter Declaration
Several Java code fragments is generated as a result, in particular the queueToQueue(...) method, which can be implemented to process the incoming message.
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.
The file is located in the Enterprise Beans node of the JMSJCASample project.
Figure 14 JCA Message Bean Sample — Queue
The Create JMS Destination dialog box appears.
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
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.
To test that JMS messages are being properly passed from Queue1 to Queue2, complete the following steps.