Index Changes
This is version 10. It is not the current version, and thus it cannot be edited.
[Back to current version]   [Restore this version]

Using the JMS JCA Wizard


Receiving a JMS Text Message

This topic provides instructions for 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 the type TextMessage.

Perform the following steps to receive a JMS text message:

  • To Create an Admin Object Resource
  • To Create the EJB Module Project
  • To Create the JCA Message-Driven Bean
  • To Test the Sample Code

To Create an Admin Object Resource

For this example, the message is being received from Queue1, so you need to create the corresponding JMS Queue object resource in GlassFish.

  1. Start the GlassFish server and use a browser to connect to the Admin Console. The URL for the Admin Console is http://_HostName_:_PortNumber_}}}}. The default port number is 4848.
  2. In the left navigation bar, expand Resources and Connectors and then select Admin Object Resources.


  3. Click New. The New Admin Object Resource window appears (Step 1 of 2).
  4. Fill in the required fields.
    For the purposes of this exercise, use the following values:
    • JNDI Name = jms/Queue1
    • Resource Type = javax.jms.Queue
    • Resource Adapter = sun-jms-adapter


  5. Click Next.
  6. Enter a name for the resource. For this exercise, enter Queue1. This is the physical destination name of the resource.


  7. Click Finish.

To Create the EJB Module Project

  1. Right–click in the Projects Panel of the NetBeans IDE and select New Project.
  2. On the New Project Wizard, select Java EE under Categories, and then select EJB Module under Projects.
  3. Click Next. The Name and Location window appears.
  4. Enter the Project Name and Location fields.
    For the purposes of this exercise, enter the following values:
    • Project Name = JMSJCASample
    • Project Location = the location to store NetBeans project files


  5. Click Next. The Server and Settings window appears.
  6. In the Server and Settings window, keep the default values for all fields.
  7. Click Finish.

To Create the JCA Message-Driven Bean

  1. Right-click on the Project node, and then select New->Other.
  2. On the wizard, select Java EE under Categories, and select JCA Message-Driven Bean under File Types.
  3. Click Next. The JCA Message-Driven Bean Name and Location window appears.
  4. Enter the Name and Location fields.
    For this exercise, enter the following values:
    • Class Name = JCAMessageBeanSample
    • Package = jmsjca.sample


  5. Click Next. The Choose Inbound JCA window appears.
  6. Select JMS Adapter and click Next.
    Note - Currently only JMS Adapter can be selected in the window.
    The Edit Activation Configuration window appears.
  7. Configure the Inbound JMS connection by clicking on the ellipsis button next to the Connection URL box (as shown below). You can configure many different options for the Inbound JMS connection, such as the JNDI name of the JMS connection resource or the JNDI name of the JMS destination. You can also configure the more advanced options such as message re-delivery, selector, concurrency mode, and so on. In this simple case, you only need to modify the Connection URL and Destination options for the sample code to work.


  8. Expand the tree node all the way and select jms/tx/jmq1 (as shown below). This resource connects the embedded Sun MQ JMS server inside the GlassFish server and is created by default with the installer. The default connection URL is mq://localhost:7676.


  9. Click on the ellipsis button next to Destination box. The Connector Resource dialog box for the Destination appears.
  10. Expand the tree node all the way and select jms/Queue1 (as shown below). This is the Admin Object Resource created earlier for the Queue1 destination using the GlassFish Admin Console.


  11. Click Finish. A Java source file is created and opened in the editor view. The source file is a skeleton file with most of the boilerplate code already generated. Any JMS messages sent to the Queue1 destination are 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 be similar to the following:
public void onMessage(Message message) {
    try {
        if (message instanceof javax.jms.TextMessage) {
            logger.log(Level.INFO, "JMS message conecnt is: " + ((javax.jms.TextMessage) message).getText());
        }
    } catch (JMSException ex) {
        Logger.getLogger(JCAMessageBeanSample.class.getName()).log(Level.SEVERE, null, ex);
        return;
    }
}
  1. Click Save when you are done editing the file.

To Test the Sample Code

  1. Right-click the Project node and select Build.
  2. When the build process is complete, right-click the Project node and select Undeploy and Deploy.
  3. Use a JMS client to send a text message to Queue1 on the to JMS server (located at mq://localhost:7676, by default). The contents of the message is logged in the server log file.

Previous Next


Return to GlassFish ESB Documentation Home

JSPWiki v2.4.100
[RSS]
« Home Index Changes Prefs
This particular version was published on 08-Jun-09 16:40 PM, -0700 by CarolT