Discussion

509
Views
DomenicoGiffone_GCS Member since 2014 3 posts
PEGA
Posted: 8 months ago
Last activity: 8 months 4 weeks ago

JBoss EAP 7.1 Sample MDB testing application

Sometimes, whilst configuring MDB integration with external brokers, there is the need to quickly test the configuration put in place by sending and receiving sample messages on the configured destinations.

The attached sample java project, loosely based on JBoss quickstart examples, can be used for this purpose.

The motivation is to simplify testing of MDBs deployment descriptors and corresponding server configuration.

The project is made of a EAR containing two modules:

  1. WAR
  2. JAR

WAR Module

The module contains a simple Servlet org.sample.jms.SampleJMSServlet meant to send test JMS Messages to the following two distinct destinations listed below.
The web.xml deployment descriptor contains additional "resource-ref" entries for JMS Connection Factories required for sending messages to aforementioned destinations.

Bindings to names defined in web.xml are provided in container specific deployment descriptor jboss-web.xml.

Remote Queue

The queue is defined as a resource-env-ref with a logical name "jms/queue/RemoteSampleQueue" in web.xml deployment descriptor.
The logical name is mapped to the container specific JNDI name in the jboss-web.xml deployment descriptor.

Local Queue

The queue is defined as a resource-env-ref with a logical name jms/queue/LocalSampleQueue in web.xml deployment descriptor.
The logical name is mapped to the container specific JNDI name in the jboss-web.xml deployment descriptor.

JAR Module

The same logic applies to the JAR module where the jboss.ejb3.xml container specific deployment descriptor provides MDB / destination bindings.
A "resource-adapter-binding" element specifies the remote connection factory needed to bind the MDB on the remote destination.

Sample JBoss EAP 7.1 configuration

The doc directory contains a sample JBoss EAP 7.1 standalone-full.xml configuration file with local and remote destination used in this sample.
The remote destination is provided by an Apache ActiveMQ Artemis1.5.5 remote broker running on <localhost:61616>

For the sample to work properly a remote broker version compatible with the Integrated Artemis Resource Adapter shipped with JBoss is strictly required
Omitting to do so could lead to unreliable results or failures.

The configuration steps applied are those reported in RedHat Official Documentation and in corresponding JBoss wiki pages

While the steps are few and almost simple there are few subtleties to take into account:

Property based ActiveMQ JNDI name configuration of destinations

Given that ActiveMQ doesn't provide a JNDI Server, JNDI names are defined in the scope of the client context. This means that we need to provide as many properties as our remote destinations in the JBoss configuration file.

Please refer to following code snippet for an example:

 <subsystem xmlns="urn:jboss:domain:naming:2.0">
    <bindings>
        <external-context name="java:global/remoteContext" module="org.apache.activemq.artemis" class="javax.naming.InitialContext" cache="false">
            <environment>
                <property name="java.naming.factory.initial" value="org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"/>
                <property name="java.naming.provider.url" value="tcp://localhost:61616"/>
                 <!-- Define a TestQueue queue with JNDI name of `queue/TestQueue` -->
                <property name="queue.queue/TestQueue" value="TestQueue"/>
            </environment>
        </external-context>
        <!-- Map former TestQueue, defined in the external context, to the local JNDI tree  -->
       <lookup name="java:/jms/queue/RemoteTestQueue" lookup="java:global/remoteContext/queue/TestQueue"/>
    </bindings>
    <remote-naming/>
</subsystem>

Mapping Remote Destinations to local JNDI tree

The previous code snippet shows how the lookup element is used to map the TestQueue destination in the local context.

Running the Sample

  • Download JBoss EAP 7.1.0 Zip File from RedHat Site and extract it to a location of your choice
  • Download Apache ActiveMQ Artemis 1.5.5. Zip File and extract it to a location of your choice.
  • Create a broker instance following the product documentation
  • Adjust any disk quota that may prevent message sending by updating the "configuration/core/max-disk-usage" element in $ACTIVEMQ_HOME/bin/<BROKER_INSTANCE>/etc/broker.xml configuration file
  • Launch the broker just created:
   administrator@localhost:~apache-artemis-1.5.5/bin/sample/bin$ ./artemis-service start  
   Starting artemis-service   
   artemis-service is now running (29751)
  • Update the standalone-full.xml JBoss config file in $JBOSS_HOME/standalone/configuration directory using the sample configuration file provided.
    The sample configuration expect a broker instance running on localhost:61616
    Adjust it to map the details of the broker launched at previous step
  • Launch JBoss using the full configuration file:
   administrator@localhost:~jboss-eap-7.1/bin$ ./standalone.sh -c standalone-full.xml
  • Deploy the mdb-sample.ear file available in the doc folder or build it from source and deploy it to JBoss using the following command:
mvn clean install wildfly:deploy
  • Connect to http://localhost:8080/mdb-sample/ and launch the local and remote tests
  • Check the server log sto see the result of messages processing.
    The following messages are expected in case of successful configuration:
     ...  
     INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: JBoss EAP 7.1.0.GA (WildFly Core 3.0.10.Final-redhat-1) started in 5011ms - Started 611 of 839 services (380 services are lazy, passive or on-demand)  
     INFO  [org.apache.activemq.artemis.ra] (default-threads - 1) AMQ151000: awaiting topic/queue creation jms/queue/RemoteTestQueue  
     INFO  [org.apache.activemq.artemis.ra] (default-threads - 1) AMQ151001: Attempting to reconnect org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec(ra=org.wildfly.extension.messaging.activemq.ActiveMQResourceAdapter@99dc2c4b destination=jms/queue/RemoteTestQueue destinationType=javax.jms.Queue ack=Auto-acknowledge durable=false clientID=null user=null maxSession=15)  
     INFO  [SampleJMSServlet] (default task-3) Initializing contexts...  
     INFO  [SampleJMSServlet] (default task-3) Resolving local connection factory jms/localCF  
     INFO  [SampleJMSServlet] (default task-3) Resolving remote connection factory jms/remoteCF  
     INFO  [SampleJMSServlet] (default task-3) Resolving local destination jms/queue/LocalSampleQueue  
     INFO  [SampleJMSServlet] (default task-3) Resolving remote destination jms/queue/RemoteSampleQueue  
     INFO  [SampleJMSServlet] (default task-3) Contexts initialized!  
     INFO  [SampleJMSServlet] (default task-3) 5 messages sent to destination ActiveMQQueue[LocalSampleQueue]  
     INFO  [SampleMDB-local-1] (Thread-4 (ActiveMQ-client-global-threads)) local MDB instance 1# initialized  
     INFO  [SampleMDB-local-5] (Thread-0 (ActiveMQ-client-global-threads)) local MDB instance 5# initialized  
     INFO  [SampleMDB-local-4] (Thread-3 (ActiveMQ-client-global-threads)) local MDB instance 4# initialized  
     INFO  [SampleMDB-local-3] (Thread-1 (ActiveMQ-client-global-threads)) local MDB instance 3# initialized  
     INFO  [SampleMDB-local-2] (Thread-2 (ActiveMQ-client-global-threads)) local MDB instance 2# initialized  
     INFO  [SampleMDB-local-2] (Thread-2 (ActiveMQ-client-global-threads)) Received Message on local destination: ["This is message 3"]  
     INFO  [SampleMDB-local-3] (Thread-1 (ActiveMQ-client-global-threads)) Received Message on local destination: ["This is message 2"]  
     INFO  [SampleMDB-local-4] (Thread-3 (ActiveMQ-client-global-threads)) Received Message on local destination: ["This is message 4"]  
     INFO  [SampleMDB-local-1] (Thread-4 (ActiveMQ-client-global-threads)) Received Message on local destination: ["This is message 5"]  
     INFO  [SampleMDB-local-5] (Thread-0 (ActiveMQ-client-global-threads)) Received Message on local destination: ["This is message 1"]  
     INFO  [SampleJMSServlet] (default task-5) 5 messages sent to destination ActiveMQQueue[TestQueue]  
     INFO  [org.apache.activemq.artemis.ra] (default-threads - 1) AMQ151002: Reconnected with broker  
     INFO  [SampleMDB-remote-1] (Thread-3 (ActiveMQ-client-global-threads)) remote MDB instance 1# initialized  
     INFO  [SampleMDB-remote-2] (Thread-4 (ActiveMQ-client-global-threads)) remote MDB instance 2# initialized  
     INFO  [SampleMDB-remote-4] (Thread-1 (ActiveMQ-client-global-threads)) remote MDB instance 4# initialized  
     INFO  [SampleMDB-remote-3] (Thread-2 (ActiveMQ-client-global-threads)) remote MDB instance 3# initialized  
     INFO  [SampleMDB-remote-1] (Thread-3 (ActiveMQ-client-global-threads)) Received Message on remote destination: ["This is message 4"]  
     INFO  [SampleMDB-remote-2] (Thread-4 (ActiveMQ-client-global-threads)) Received Message on remote destination: ["This is message 3"]  
     INFO  [SampleMDB-remote-3] (Thread-2 (ActiveMQ-client-global-threads)) Received Message on remote destination: ["This is message 2"]  
     INFO  [SampleMDB-remote-4] (Thread-1 (ActiveMQ-client-global-threads)) Received Message on remote destination: ["This is message 1"]  
     INFO  [SampleMDB-remote-1] (Thread-1 (ActiveMQ-client-global-threads)) Received Message on remote destination: ["This is message 5"]  
     ...  
System Administration Developer Knowledge Share
Share this page LinkedIn