| Installing Upgrading Designing Configuring Deploying Monitoring Administering Troubleshooting Reference JBI Components | |
| Close Print View | |
| Designing: Using the JMS JCA Wizard |
|
Creating a Runtime Environment
Designing Business Processes in the Sun Business Process Manager
Working with TCP/IP HL7 Collaborations
Developing Sun Master Indexes (Repository)
Developing Sun Master Patient Indexes
Developing OTDs for Application Adapters
Developing OTDs for Communication Adapters
Developing OTDs for Database Adapters
Developing OTDs for Web Server Adapters
Designing with Application Adapters
Designing with Communication Adapters
Designing with Web Server Adapters
Designing with Sun JCA Adapters
Defining Constants and Variables
The JMS JCA Wizard provides tooling support for Java EE users to easily connect to JMS message servers from their Java EE applications. The wizard is written as a NetBeans IDE plugin module and provides GUI support for the JMS JCA inbound configuration, and code fragment generation through a drag-and-drop code palette. The wizard leverages the EJB 3.0 and JCA 1.5 APIs to simplify the user experience. The runtime components are Glassfish and the JMS JCA Adapter. Glassfish is the open source Java EE application server and the JMS JCA Adapter is the open source JCA 1.5 compliant resource adapter. The advantage of using the JMS JCA Adapter is that it allows you to connect to a different vendor's message server transparently, such as WebSphere JMS, Weblogic JMS, jBoss JMS, and Sun MQ. For more information regarding these components, go to Glassfish Project and JMS JCA Project. All relevant components required by the JMS JCA Wizard are packaged in the Open ESB installer, which includes the NetBeans IDE, the JMS JCA Wizard plugin module, Glassfish , JMS JCA Adapter in addition to other Open ESB components. You can download the latest Open ESB installer from Open ESB Download.
This topic provides instructions on building a Message-Driven Bean (MDB) that will monitor a designated queue on a JMS destination (of the JMS Server) in order to receive JMS messages. Upon receipt of the a JMS message, the MDB will print out the content of the message, if it is of type TextMessage.

The New Admin Object Resource window appears (Step 1 of 2).
JNDI Name = jms/Queue1
Resource Type = javax.jms.Queue
Resource Adapter = sun-jms-adapter
You will be directed to step 2 of the process.
Name = Queue1

The Name and Location window will be displayed.
Project Name = JMSJCASample
Project Location = a directory on your filesystem
The Server and Settings window will be displayed.

The JCA Message-Driven Bean Name and Location window will appear.
Class Name = JCAMessageBeanSample
Package = jmsjca.sample
The Choose Inbound JCA window is displayed.
Note - Currently only JMS Adapter can be selected in the window.
The Edit Activation Configuration window is displayed.
You can configure many different options for the Inbound JMS connection. Things such as the JNDI name of the JMS connection resource to use or the JNDI name of the JMS destination. You can also configure the more advanced options such as message re-delivery, selector, concurrency mode, etc. In this simple case, only the Connection URL and Destination options for our sample code to work.

This resource connects the embedded Sun MQ JMS server inside the Glassfish AppServer and is created by default with the installer. The default connection url is mq://localhost:7676

The Connector Resource dialog box for the Destination is displayed.
This is the Admin Object Resource created earlier for the Queue1 destination using the Glassfish admin console.

A Java source file will be created and opened in the editor view. The source file is a skeleton file with most of the boiler-plate code already generated, as shown below.
Any JMS messages sent to the Queue1 destination will be passed to the onMessage(...) method in this Java file. The login can be processed inside the onMessage() method as needed. Because the purpose of this task is to simply print out the message content of the JMS message (if the message is of type javax.jms.TextMessage), the implementation code would look something like the following:

The contents of the TextMessage will be logged in the Glassfish AppServer's server.log file.
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).
JNDI Name = jms/Queue2
Resource Type = javax.jms.Queue
Resource Adapter = sun-jms-adapter
The JCA Wizard dialog box will be displayed.
Method Name = queueToQueue
Resource JNDI Name = jms/tx/jmq1

Several Java code fragments will be generated as a result, in particular the queueToQueue(...) method, which can be implemented to process the incoming message.
This allows a message to be sent to the destination object in the Java code.
The Create JMS Destination dialog box will display.
JNDI name = jms/Queue2 (You can select this value using the browse button, instead of typing)
Variable Name = queue2

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

To test that JMS messages are being properly passed from Queue1 to Queue2complete the following steps.
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.
The New Project dialog box is displayed.
The New EJB Module dialog box is displayed.
The Server and Settings dialog box is displayed.
The new project is created.
The New File dialog box is displayed.

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

The Choose Inbound JCA dialog box is displayed.
The Edit Activation Configuration dialog box is displayed.

A new Message-Driven Bean is created.
A Create JMS Destination dialog box is displayed.

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.
The JMS Adapter Declaration dialog box is displayed.

The java code for the JMS Session is populated into the Java Editor.
The Create JMS Request-Reply dialog box is displayed. The Select Method will already be set by default.

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

The JMS Adapter Declaration dialog box is displayed.

The java code for the JMS Session is populated into the Java Editor.
jmsSession.createProducer(message.getJMSReplyTo()).send(message);
This code sends the incoming message to the reply destination.