Case Status
Log In



Delphi Integration with the Gl…
  • RSS Feed

Last modified on 3/22/2011 1:24 PM by User.


Delphi Integration with the GlassFish v3 Application Server Part 2 - Receiving Messages


This tutorial will guide you through the creation of a simple EJB application for GlassFish v3 which uses a Message Driven Bean to receive messages from a message queue on the embedded OpenMQ broker. The Delphi ProducerTool application sends messages to the message queue.


  • NetBeans 6.8 IDE
  • GlassFish v3 (included with NetBeans 6.8)

Configure JMS resources

To create the JMS connection factory and the message queue,

  • open the GlassFish Admin Console
  • create a JMS connection factory with the JNDI name jms/HabariConnectionFactory
  • create a JMS queue with the JNDI name jms/TOOL.DEFAULT and the physical name TOOL.DEFAULT

To open the Admin Console, do the following:

  1. Confirm that the application server is running by expanding the Servers node in the Services window of the IDE. A small green arrow next to the application server node indicates the server is running.
  2. Right-click the application server node and choose View Admin Console to open the login window in your browser.
  3. Log in to the server. The default user name and password are admin and adminadmin.
  4. In the Admin Console in your browser, expand the Resources node and JMS Resources node in the left frame.
  5. Click on the Connection Factories and Destination Resources links in the left frame to check if the resources are registered with the server and if necessary modify the resources. If the resources do not exist, you can create them in the Admin Console.

You need to make sure that the JMS connection factory resource in the OpenMQServlet servlet is mapped to the correct JNDI name of the JMS connection factory resource registered with the GlassFish Application Server.

The following resources should be registered with the Sun Java System Application Server:

  • a Destination resource with the JNDI name jms/TOOL.DEFAULT and type javax.jms.Topic
  • a Connection Factory resource with the JNDI name jms/HabariConnectionFactory and type javax.jms.QueueConnectionFactory

Create a Java EE application

  • Start NetBeans IDE.
  • In the IDE, choose File > New Project (Ctrl-Shift-N).
  • In the New Project wizard, expand the Java EE category and select EJB Module. Then click Next.
  • In the Name and Location page of the wizard, do the following:
    • In the Project Name field, type HabariGlassFish3MDB.
    • Leave the Use Dedicated Folder for Storing Libraries checkbox unselected.
    • Select the Set as Main Project checkbox.
  • Click Next.
  • In the Server and Settings page of the wizard, do the following:
    • In the Server list, choose GlassFish v3
    • Leave the Java EE version unchanged.
  • Click Finish

The project is created and opened in the IDE. You should see the following components:

  • The Projects window, which contains a tree view of the components of the project, including source files, libraries that your code depends on, and so on.

Add a Message Driven Bean to the project.

  • In the IDE, choose File > New File ... (Ctrl-N).
  • In the New File wizard, choose the Web category and select Message Driven Bean. Then click Next.
  • In the Name and Location page of the wizard, do the following:
    • In the Class Name field, type OpenMQMDB.
    • Leave the Location unchanged.
    • In the Package field, type openmqmdb.
    • In the server destination field, select jms/TOOL.DEFAULT
  • Click Finish

Add code in the onMessage method

        if (message instanceof TextMessage) {
            try {
                System.out.println(((TextMessage) message).getText());
            } catch (JMSException ex) {
                Logger.getLogger(NewMessageBean.class.getName()).log(Level.SEVERE, null, ex);

Deploy the EJB

  • In the IDE, choose Run > Build Main Project (F11).
  • Check the output folder dist, the web application file HabariGlassFish3App.war should be there.

Test the installation

To test the message driven bean, start the ProducerTool application. It will send ten text messages to the broker, which will be received and displayed by the message driven bean.