Skip to content

Latest commit

 

History

History
978 lines (817 loc) · 40.1 KB

README.adoc

File metadata and controls

978 lines (817 loc) · 40.1 KB

helloworld-jms: Helloworld JMS Example

The helloworld-jms quickstart demonstrates the use of external JMS clients with WildFly.

What is it?

The helloworld-jms quickstart demonstrates the use of external JMS clients with WildFly Application Server.

It contains the following:

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

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

System Requirements

The application this project produces is designed to be run on WildFly Application Server 34 or later.

All you need to build this project is Java 11.0 (Java SDK 11) or later and Maven 3.6.0 or later. See Configure Maven to Build and Deploy the Quickstarts to make sure you are configured correctly for testing the quickstarts.

Use of the WILDFLY_HOME and QUICKSTART_HOME Variables

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

When you see the replaceable variable QUICKSTART_HOME, replace it with the path to the root directory of all of the quickstarts.

Add the Authorized Application User

This quickstart uses secured application 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 terminal and type the following command:

$ WILDFLY_HOME/bin/add-user.sh -a -u 'quickstartUser' -p 'quickstartPwd1!' -g 'guest'
Note
For Windows, use the WILDFLY_HOME\bin\add-user.bat script.

Back Up the WildFly Standalone Server Configuration

Before you begin, back up your server configuration file.

  1. If it is running, stop the WildFly server.

  2. Back up the WILDFLY_HOME/standalone/configuration/standalone-full.xml file.

After you have completed testing this quickstart, you can replace this file to restore the server to its original configuration.

Start the WildFly Standalone Server

  1. Open a terminal and navigate to the root of the WildFly directory.

  2. Start the WildFly server with the full profile by typing the following command.

    $ WILDFLY_HOME/bin/standalone.sh -c standalone-full.xml
    Note
    For Windows, use the WILDFLY_HOME\bin\standalone.bat script.

Configure the 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, make sure you do the following:

  2. Review the configure-jms.cli file in the src/main/scripts/ folder of this quickstart directory. This script adds the test queue to the messaging subsystem in the server configuration file.

  3. Open a new terminal, navigate to the root directory of this quickstart, and run the following command, replacing WILDFLY_HOME with the path to your server:

    $ WILDFLY_HOME/bin/jboss-cli.sh --connect --file=configure-jms.cli
    Note
    For Windows, use the WILDFLY_HOME\bin\jboss-cli.bat script.
  4. You should see the following result when you run the script:

    The batch executed successfully
  5. Stop the WildFly server.

Review the Modified Server Configuration

After stopping the server, open the WILDFLY_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"/>

Run the Integration Tests

This quickstart includes integration tests, which are located under the src/test/ directory. The integration tests verify that the quickstart runs correctly when deployed on the server.

Follow these steps to run the integration tests.

  1. Make sure WildFly server is started.

  2. Make sure the quickstart is deployed.

  3. Type the following command to run the verify goal with the integration-testing profile activated.

    $ mvn verify -Pintegration-testing 

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 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 integration test using the system properties.

Property

Default value

Description

username

quickstartUser

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.

password

quickstartPwd1!

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

connection.factory

jms/RemoteConnectionFactory

The name of the JMS ConnectionFactory you want to use.

destination

jms/queue/test

The name of the JMS Destination you want to use.

message.count

1

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

message.content

"Hello, World!"

The content of the JMS TextMessage.

java.naming.provider.url

"http-remoting://127.0.0.1:8080"

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

Restore the WildFly Standalone Server Configuration

You can restore the original server configuration using either of the following methods.

Restore the WildFly Standalone Server Configuration by Running the JBoss CLI Script

  1. Start the WildFly server as described above.

  2. Open a new terminal, navigate to the root directory of this quickstart, and run the following command, replacing WILDFLY_HOME with the path to your server:

    $ WILDFLY_HOME/bin/jboss-cli.sh --connect --file=remove-jms.cli
    Note
    For Windows, use the WILDFLY_HOME\bin\jboss-cli.bat script.

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

Building and running the quickstart application with provisioned WildFly server

Instead of using a standard WildFly server distribution, you can alternatively provision a WildFly server to deploy and run the quickstart, by activating the Maven profile named provisioned-server when building the quickstart:

$ mvn clean install -Pprovisioned-server

The provisioned WildFly server, with the quickstart deployed, can then be found in the target/server directory, and its usage is similar to a standard server distribution, with the simplification that there is never the need to specify the server configuration to be started.

The quickstart user should be added before running the provisioned server:

$ target/server/bin/add-user.sh -a -u 'quickstartUser' -p 'quickstartPwd1!' -g 'guest'
Note

For Windows, use the WILDFLY_HOME\bin\add-user.bat script.

The server provisioning functionality is provided by the WildFly Maven Plugin, and you may find its configuration in the quickstart pom.xml:

        <profile>
            <id>provisioned-server</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.wildfly.plugins</groupId>
                        <artifactId>wildfly-maven-plugin</artifactId>
                        <configuration>
                            <discover-provisioning-info>
                                <version>${version.server}</version>
                            </discover-provisioning-info>
                            <!--
                                Rename the output war to ROOT.war before adding it to the server, so that the
                                application is deployed in the root web context.
                            -->
                            <name>ROOT.war</name>
                            <add-ons>...</add-ons>
                        </configuration>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>package</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    ...
                </plugins>
            </build>
        </profile>

The plugin uses WildFly Glow to discover the feature packs and layers required to run the application, and provisions a server containing those layers.

If you get an error or the server is missing some functionality which cannot be auto-discovered, you can download the WildFly Glow CLI and run the following command to see more information about what add-ons are available:

wildfly-glow show-add-ons
Note

Since the plugin configuration above deploys quickstart on root web context of the provisioned server, the URL to access the application should not have the /helloworld-jms path segment after HOST:PORT.

Run the Integration Tests with a provisioned server

The integration tests included with this quickstart, which verify that the quickstart runs correctly, may also be run with a provisioned server.

Follow these steps to run the integration tests.

  1. Make sure the server is provisioned.

    $ mvn clean install -Pprovisioned-server
  2. Add the quickstart user:

    $ target/server/bin/add-user.sh -a -u 'quickstartUser' -p 'quickstartPwd1!' -g 'guest'
  3. Start the WildFly provisioned server, this time using the WildFly Maven Plugin, which is recommended for testing due to simpler automation. The path to the provisioned server should be specified using the jbossHome system property.

    $ mvn wildfly:start -DjbossHome=target/server 
  4. Type the following command to run the verify goal with the integration-testing profile activated, and specifying the quickstart’s URL using the server.host system property, which for a provisioned server by default is http://localhost:8080.

    $ mvn verify -Pintegration-testing -Dserver.host=http://localhost:8080 
  5. Shutdown the WildFly provisioned server, this time using the WildFly Maven Plugin too.

    $ mvn wildfly:shutdown

WildFly for OpenShift Incompatibility

This quickstart is not compatible with WildFly for OpenShift.