Red Hat

Developer Materials

helloworld-jms: Helloworld JMS Example

What is it?

The helloworld-jms quickstart demonstrates the use of external JMS clients with Red Hat JBoss Enterprise Application Platform.

It contains the following:

  1. A message producer that sends messages to a JMS destination deployed to a JBoss EAP server.

  2. A message consumer that receives message from a JMS destination deployed to a JBoss EAP server.

System requirements

The application this project produces is designed to be run on Red Hat JBoss Enterprise Application Platform 7 or later.

All you need to build this project is Java 8.0 (Java SDK 1.8) or later and Maven 3.1.1 or later. See Configure Maven for JBoss EAP 7 to make sure you are configured correctly for testing the quickstarts.

Use of EAP7_HOME

In the following instructions, replace EAP7_HOME with the actual path to your JBoss EAP installation. The installation path is described in detail here: Use of EAP7_HOME and JBOSS_HOME Variables.

Add an Application User

This quickstart uses secured management interfaces and requires that you create the following application user to access the running application.

UserName Realm Password Roles
quickstartUser ApplicationRealm quickstartPwd1! guest

To add the application user, open a command prompt and type the following command:

    For Linux:   EAP7_HOME/bin/add-user.sh -a -u 'quickstartUser' -p 'quickstartPwd1!' -g 'guest'
    For Windows: EAP7_HOME\bin\add-user.bat  -a -u 'quickstartUser' -p 'quickstartPwd1!' -g 'guest'

If you prefer, you can use the add-user utility interactively. For an example of how to use the add-user utility, see the instructions located here: Add an Application User.

Configure the JBoss EAP Server

You configure the JMS test queue by running JBoss CLI commands. For your convenience, this quickstart batches the commands into a configure-jms.cli script provided in the root directory of this quickstart.

  1. Before you begin, back up your server configuration file
    • If it is running, stop the JBoss EAP server.
    • Backup the file: EAP7_HOME/standalone/configuration/standalone-full.xml
    • After you have completed testing this quickstart, you can replace this file to restore the server to its original configuration.
  2. Start the JBoss EAP server by typing the following:

     For Linux:  EAP7_HOME/bin/standalone.sh -c standalone-full.xml
     For Windows:  EAP7_HOME\bin\standalone.bat -c standalone-full.xml
    
  3. Review the configure-jms.cli file in the root of this quickstart directory. This script adds the test queue to the messaging subsystem in the server configuration file.

  4. Open a new command prompt, navigate to the root directory of this quickstart, and run the following command, replacing EAP7_HOME with the path to your server:

     For Linux: EAP7_HOME/bin/jboss-cli.sh --connect --file=configure-jms.cli 
     For Windows: EAP7_HOME\bin\jboss-cli.bat --connect --file=configure-jms.cli  You should see the following result when you run the script:
    
     The batch executed successfully.
     {
         "outcome" => "success",
         "result" => undefined
     }
    
  5. Stop the JBoss EAP server.

Review the Modified Server Configuration

After stopping the server, open the EAP7_HOME/standalone/configuration/standalone-full.xml file and review the changes.

The following testQueue jms-queue was configured in the default server configuration of the messaging-activemq subsystem.

  <jms-queue name="testQueue" entries="queue/test java:jboss/exported/jms/queue/test"/>

Start the JBoss EAP Server with the Full Profile

  1. Open a command prompt and navigate to the root of the JBoss EAP directory.
  2. The following shows the command line to start the server with the full profile:

     For Linux:   EAP7_HOME/bin/standalone.sh -c standalone-full.xml
     For Windows: EAP7_HOME\bin\standalone.bat -c standalone-full.xml
    

Build and Execute the Quickstart

To run the quickstart from the command line:

  1. Make sure you have started the JBoss EAP server. See the instructions in the previous section.

  2. Open a command prompt and navigate to the root of the helloworld-jms quickstart directory:

     cd PATH_TO_QUICKSTARTS/helloworld-jms
    
  3. Type the following command to compile and execute the quickstart:

     mvn clean compile exec:java
    

NOTE: If you execute this command multiple times, you may see the following warning and exception, followed by a stacktrace. This is caused by a bug in Artemis that has been fixed, but not yet released. For details, see https://issues.apache.org/jira/browse/ARTEMIS-158. You can ignore this warning.

WARN: AMQ212007: connector.create or connectorFactory.createConnector should never throw an exception, implementation is badly behaved, but we will deal with it anyway.
java.lang.IllegalArgumentException: port out of range:-1

Investigate the Console Output

If the Maven command is successful, with the default configuration you will see output similar to this:

timestamp org.jboss.as.quickstarts.jms.HelloWorldJMSClient main
INFO: Attempting to acquire connection factory "jms/RemoteConnectionFactory"
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
timestamp org.jboss.as.quickstarts.jms.HelloWorldJMSClient main
INFO: Found connection factory "jms/RemoteConnectionFactory" in JNDI
timestamp org.jboss.as.quickstarts.jms.HelloWorldJMSClient main
INFO: Attempting to acquire destination "jms/queue/test"
timestamp org.jboss.as.quickstarts.jms.HelloWorldJMSClient main
INFO: Found destination "jms/queue/test" in JNDI
timestamp AM org.jboss.as.quickstarts.jms.HelloWorldJMSClient main
INFO: Sending 1 messages with content: Hello, World!
timestamp org.jboss.as.quickstarts.jms.HelloWorldJMSClient main
INFO: Received message with content Hello, World!

Optional Properties

The example provides for a certain amount of customization for the mvn:exec plug-in using the system properties.

  • username

    This username is used for both the JMS connection and the JNDI look-up. Instructions to set up the quickstart application user can be found here: Add an Application User.

    Default: quickstartUser

  • password

    This password is used for both the JMS connection and the JNDI look-up. Instructions to set up the quickstart application user can be found here: Add an Application User

    Default: quickstartPwd1!

  • connection.factory

    The name of the JMS ConnectionFactory you want to use.

    Default: jms/RemoteConnectionFactory

  • destination

    The name of the JMS Destination you want to use.

    Default: jms/queue/test

  • message.count

    The number of JMS messages you want to produce and consume.

    Default: 1

  • message.content

    The content of the JMS TextMessage.

    Default: "Hello, World!"

  • java.naming.provider.url

    This property allows configuration of the JNDI directory used to lookup the JMS destination. This is useful when the client resides on another host. 
    

    Default: "localhost"

Remove the JMS Configuration

You can remove the JMS configuration by running the remove-jms.cli script provided in the root directory of this quickstart or by manually restoring the back-up copy the configuration file.

Remove the JMS Configuration by Running the JBoss CLI Script

  1. Start the JBoss EAP server by typing the following:

     For Linux:  EAP7_HOME/bin/standalone.sh -c standalone-full.xml
     For Windows:  EAP7_HOME\bin\standalone.bat -c standalone-full.xml
    
  2. Open a new command prompt, navigate to the root directory of this quickstart, and run the following command, replacing EAP7_HOME with the path to your server:

     For Linux: EAP7_HOME/bin/jboss-cli.sh --connect --file=remove-jms.cli 
     For Windows: EAP7_HOME\bin\jboss-cli.bat --connect --file=remove-jms.cli  This script removes the `test` queue from the `messaging` subsystem in the server configuration. You should see the following result when you run the script:
    
     The batch executed successfully.
     {
         "outcome" => "success",
         "result" => undefined
     }
    

Remove the JMS Configuration Manually

  1. If it is running, stop the JBoss EAP server.
  2. Replace the EAP7_HOME/standalone/configuration/standalone-full.xml file with the back-up copy of the file.

Run the Quickstart in Red Hat JBoss Developer Studio or Eclipse

You can also start the server and deploy the quickstarts or run the Arquillian tests from Eclipse using JBoss tools. For general information about how to import a quickstart, add a JBoss EAP server, and build and deploy a quickstart, see Use JBoss Developer Studio or Eclipse to Run the Quickstarts

This quickstart consists of multiple projects, so it deploys and runs differently in JBoss Developer Studio than the other quickstarts.

  1. Be sure to Add an Application User as described above.
  2. Configure and start the JBoss EAP server in Red Hat JBoss Developer Studio:
    • Define a server runtime environment that uses the standalone-full.xml configuration file.
    • Start the server defined in the previous step.
  3. Outside of JBoss Developer Studio, configure the JMS test queue by running the JBoss CLI commands as described above under Configure the JBoss EAP Server.
  4. In JBoss Developer Studio, right-click on the jboss-helloworld-jms project and choose Run As –> Java Application. In the Select Java Application window, choose HellowWorldJMSClient - org.jboss.as.quickstarts.jms and click OK. The client output displays in the Console window. The output messages appear in the Console window.
  5. Be sure to Remove the JMS Configuration when you have completed testing this quickstart.

Debug the Application

If you want to debug the source code of any library in the project, run the following command to pull the source into your local repository. The IDE should then detect it.

    mvn dependency:sources

Recent Changelog

  • Mar 29, 2016(Sande Gilda):JBEAP 3982 Update multiple quickstart README files with new CLI script output results
  • Oct 26, 2015(Sande Gilda):JBEAP 1351 Clarify JBDS instructions for ejb security interceptors and helloworld jms
  • Oct 15, 2015(Sande Gilda):JBEAP 1436 JBEAP 1446 Include consistent configuration steps in JBDS instructions for ejb security ejb security interceptors helloworld jms helloworld mdp propertysubstitution logging mail picketlink sts servlet security and shopping cart README files
  • Aug 28, 2015(Sande Gilda):JBEAP 890 Add note about possible warning and exception when running helloworld jms multiple times
  • Aug 21, 2015(Sande Gilda):JBEAP 813 Fix helloworld jms runtime issue and update README output
  • Aug 20, 2015(Sande Gilda):JBEAP 577 Replace links to shared resources for JBoss EAP 7 material
  • Aug 4, 2015(Sande Gilda):JBEAP 578 Update Maven version in README files
  • Aug 3, 2015(Sande Gilda):JBEAP 564 Clarify Maven instructions
  • Jul 23, 2015(Sande Gilda):Replace CONFIGURE_MAVEN link with CONFIGURE_MAVEN_JBOSS_EAP7 link
  • Jun 25, 2015(Sande Gilda):JDF 835 Replace JBoss AS JBoss EAP. Replace Arquillian jbossas with wildfly. Replace plugin with plug in
Avg:
Your Rating:
×