Skip to content

Latest commit

 

History

History
190 lines (140 loc) · 7.92 KB

README.adoc

File metadata and controls

190 lines (140 loc) · 7.92 KB

remote-helloworld-mdb: Helloworld Using an MDB (Message-Driven Bean) and a Remote Artemis broker

The remote-helloworld-mdb quickstart demonstrates the use of JMS and EJB Message-Driven Bean in {productName} with a remote broker.

What is it?

The remote-helloworld-mdb quickstart demonstrates the use of JMS and EJB Message-Driven Bean in {productNameFull} with a remote Apache Artemis broker.

This project uses two JMS resources on a remote broker:

  • A queue named HELLOWORLDMDBQueue bound in JNDI as java:/queue/HELLOWORLDMDBQueue

  • A topic named HELLOWORLDMDBTopic bound in JNDI as java:/topic/HELLOWORLDMDBTopic

Building and running the quickstart application with a {productName} server distribution

Run the Apache Artemis broker locally

You can run Apache Artemis broker locally using docker or podman:

$ docker run --rm --name artemis -e AMQ_USER=admin -e AMQ_PASSWORD=admin -p8161:8161 -p61616:61616 -e AMQ_DATA_DIR=/home/jboss/data quay.io/artemiscloud/activemq-artemis-broker-kubernetes

You can access the console of Apache Artemis at the URL: http://localhost:8161/console with admin/admin to authenticate.

Configure the {productName} Server

You configure the JMS connection factory to the remote broker by running JBoss CLI commands. For your convenience, this quickstart batches the commands into a configure-remote-broker.cli script provided in the root directory of this quickstart.

  1. Before you begin, make sure you do the following:

  2. Review the configure-remote-broker.cli file in the root of this quickstart directory. This script adds the test queue to the messaging-activemq 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 {jbossHomeName} with the path to your server:

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

    "outcome" => "success",
    "response-headers" => {"process-state" => "reload-required"}
  5. Stop the {productName} server.

Review the Modified Server Configuration

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

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

<remote-connector name="artemis" socket-binding="remote-artemis"/>
<pooled-connection-factory name="RemoteConnectionFactory" entries="java:jboss/RemoteConnectionFactory java:jboss/exported/jms/RemoteConnectionFactory" connectors="artemis" user="admin" password="admin" enable-amq1-prefix="false"/>

Access the Application

The application will be running at the following URL: http://localhost:8080/{artifactId}/.

Investigate the Server Console Output

Look at the {productName} console or Server log and you should see log messages like the following:

INFO  [class org.jboss.as.quickstarts.mdb.HelloWorldQueueMDB] (Thread-9 (ActiveMQ-client-global-threads-1189700957)) Received Message from queue: This is message 1
INFO  [class org.jboss.as.quickstarts.mdb.HelloWorldQueueMDB] (Thread-6 (ActiveMQ-client-global-threads-1189700957)) Received Message from queue: This is message 2
INFO  [class org.jboss.as.quickstarts.mdb.HelloWorldQueueMDB] (Thread-7 (ActiveMQ-client-global-threads-1189700957)) Received Message from queue: This is message 3
INFO  [class org.jboss.as.quickstarts.mdb.HelloWorldQueueMDB] (Thread-5 (ActiveMQ-client-global-threads-1189700957)) Received Message from queue: This is message 4
INFO  [class org.jboss.as.quickstarts.mdb.HelloWorldQueueMDB] (Thread-4 (ActiveMQ-client-global-threads-1189700957)) Received Message from queue: This is message 5

This script removes the remote broker connection from the messaging-activemq subsystem and restore the default internal broker. You should see the following result when you run the script:

"outcome" => "success",
"response-headers" => {
    "operation-requires-reload" => true,
    "process-state" => "reload-required"
}
Note

The Arquillian integration tests expect a running Apache Artemis broker, so make sure you have started the broker before you begin.

Building and running the quickstart application with OpenShift

Deploy a Apache Artemis instance on OpenShift

$ oc run artemis --env AMQ_USER=admin --env AMQ_PASSWORD=admin --image=quay.io/artemiscloud/activemq-artemis-broker-kubernetes  --port=61616 --expose=true

This will create a broker instance named artemis on OpenShift that can be accessed on the port 61616 on the service artemis with the account admin/admin.

Clean Up

The broker instance can be deleted from OpenShift by running the command:

$ oc delete service artemis
service "artemis" deleted
$ oc delete pod artemis
pod "artemis" deleted