Configure JMS resources required by an application.
| Resources | |
|---|---|
| Files: |
/home/student/AD248/labs/messaging-resources
|
| Application URL: |
http://localhost:9990
|
http://localhost:8080/messaging-client
| |
Outcomes
You should be able to create a JMS connection factory and a queue, and deploy applications that make use of them.
This guided exercise makes use of the following two test applications:
The messaging-client.war web application connects to the connection factory with JNDI address java:/jms/CustomCF and publishes messages to the queue with JNDI address java:/jms/queue/JB248TestQueue.
The application accepts text from the user to use as message properties and the message body.
The helloworld-mdb.jar application uses a message-driven bean (MDB) that connects to the same connection factory and consumes messages from the same queue as the client application.
The application shows the message properties and body in the JBoss EAP server log.
You deploy both applications to a standalone server instance.
Before beginning the guided exercise, run the following command to verify that the exercise files exist and that JBoss EAP is installed.
[student@workstation ~]$ lab start messaging-resources
Instructions
Start a JBoss EAP standalone server instance by using the standalone-full.xml configuration.
Start a JBoss EAP instance by using the /home/student/AD248/labs/messaging-resources/standalone directory as the base directory.
[student@workstation ~]$cd /opt/jboss-eap-7.4/bin[student@workstation bin]$./standalone.sh --server-config=standalone-full.xml \ -Djboss.server.base.dir=/home/student/AD248/labs/messaging-resources/standalone/
Wait for the server to finish starting before proceeding. Leave this terminal running the JBoss EAP standalone server instance.
Create the connection factory and queue by using the JNDI name expected by the applications.
In a new terminal window, start the management CLI.
[student@workstation ~]$cd /opt/jboss-eap-7.4/bin[student@workstation bin]./jboss-cli.sh --connect[standalone@localhost:9990 /]
Create a pooled-connection-factory that refers to the default in-vm ActiveMQ connector.
Assign the JNDI name java:/jms/CustomCF to the factory.
[standalone@localhost:9990 /]cd /subsystem=messaging-activemq/server=default[standalone@localhost:9990 server=default]./pooled-connection-factory=\ custom:add(connectors=[in-vm], entries=[java:/jms/CustomCF]){"outcome" => "success"}
Leave this terminal window open with the management CLI connected.
Create a queue called TestQueue with java:/jms/queue/AD248TestQueue as an assigned JNDI name.
[standalone@localhost:9990 server=default]$ ./jms-queue=TestQueue:add\
(entries=["java:/jms/queue/AD248TestQueue"])
{"outcome" => "success"}Observe that the new queue has not received any messages.
[standalone@localhost:9990 server=default]./jms-queue=TestQueue\ :read-resource(include-runtime=true){ "outcome" => "success", "result" => { ...output omitted... "message-count" =>0L, "messages-added" =>0L, ...output omitted... } }
Deploy and use the test application to produce messages.
Use the management CLI to deploy the mdb-client.war application.
[standalone@localhost:9990 server=default]$ deploy \
/home/student/AD248/labs/messaging-resources/mdb-client.war
[standalone@localhost:9990 server=default]The deployment can succeed even if you made an error in the previous steps. For example, the JMS resources might use different JNDI names from the application.
In a new terminal window, send an HTTP request to the server to create a new JMS message.
[student@workstation ~]$ curl --data "count=1" --data "label=first" \
--data "message=test message body" http://localhost:8080/mdb-client/queue
...output omitted...In the terminal where the management CLI is connected, verify that the messages were queued by viewing the messages-added value.
Additionally, the message-count indicates that there are two messages waiting in the queue.
[standalone@localhost:9990 server=default]./jms-queue=TestQueue\ :read-resource(include-runtime=true){ "outcome" => "success", "result" => { ...output omitted... "message-count" =>1L, "messages-added" =>1L, ...output omitted... } }
Inspect the headers and properties for messages published but not yet consumed.
Notice that the message's Copy and Labels attributes match what came from the publisher test application.
The message body is not visible with the list-messages operation.
[standalone@localhost:9990 server=default]./jms-queue=TestQueue:list-messages{ "outcome" => "success", "result" => [{ ...output omitted... "address" => "jms.queue.TestQueue", ...output omitted..."Copy" => 1,"Label" => "first",...output omitted... }] }
Deploy the message consumer test application and verify that it consumes the queued messages.
Use the management CLI to deploy the helloworld-mdb.jar application.
[standalone@localhost:9990 bin]$ deploy \
/home/student/AD248/labs/messaging-resources/helloworld-mdb.jarThe consumer test application includes an MDB that immediately starts consuming and logging messages. In the terminal window running JBoss EAP, verify that the log entries are similar to the following:
...output omitted...
... INFO [class ...HelloWorldQueueMDB] ... Received Message from queue: test message body
... INFO [class ...HelloWorldQueueMDB] ... Message Properties: Copy #1 [first]
... INFO [class ...HelloWorldQueueMDB] ... Message Body: test message bodyIn the terminal where the management CLI is connected, verify that messages-added is still one, but message-count is back down to zero.
[standalone@localhost:9990 server=default]./jms-queue=TestQueue\ :read-resource(include-runtime=true){ "outcome" => "success", "result" => { ...output omitted... "message-count" =>0L, "messages-added" =>1L, ...output omitted... } }
Publish a message and verify that the running consumer immediately reads it.
In the curl terminal window, send another HTTP request to the server.
[student@workstation ~]$ curl --data "count=1" --data "label=second" \
--data "message=test message body" http://localhost:8080/mdb-client/queue
...output omitted...In the terminal window running JBoss EAP, verify that the log entries are similar to the following:
...output omitted...
... INFO [class ...HelloWorldQueueMDB] ... Received Message from queue: test message body
... INFO [class ...HelloWorldQueueMDB] ... Message Properties: Copy #1 [second]
... INFO [class ...HelloWorldQueueMDB] ... Message Body: test message bodyIn the management CLI terminal window, verify that messages-added incremented and that message-count is still zero.
[standalone@localhost:9990 server=default]./jms-queue=TestQueue\ :read-resource(include-runtime=true){ "outcome" => "success", "result" => { ...output omitted... "message-count" =>0L, "messages-added" =>2L, ...output omitted... } }
Shut down the server and close the management CLI connection.
In the management CLI terminal window, stop the JBoss EAP standalone server instance.
[standalone@localhost:9990 server=default] /:shutdown
{
"outcome" => "success",
"result" => undefined
}Exit the JBoss EAP management CLI client.
[standalone@localhost:9990 server=default]$ exitClose the terminal windows.