Hi,

The HornetQ codebase was donated to the Apache ActiveMQ project, and the HornetQ community joined to build a next-generation messaging broker. ActiveMQ Artemis includes many new features, and also retains protocol compatibility with the HornetQ broker. WildFly 10 includes this new exciting project as its JMS broker, and due to the protocol compatibility, it fully replaces the HornetQ project. So as part of this simple demo we will see how we can connect to the ActiveMQ broker present inside the WildFLy10 via Standalone java based client code using standard JMS APIs.

Find more about “Apache ActiveMQ Artemis” in http://hornetq.blogspot.in/2015/06/hornetq-apache-donation-and-apache.html
AND
http://activemq.apache.org/artemis/

This article is basically clone of http://middlewaremagic.com/jboss/?p=2724 with just few WildFly 10.x specific changes related to WildFly JMS configuration, However the client code will remain same.

In this example we will be learning the following things:

1. How to create a simple JMS Queue in WildFly 10.x
2. How to create a user in ApplicationRealm and assign it to “guest” role.
3. How to create the InitialContext on the standalone client side.
4. What all jars are needed on the client side in order to lookup the JNDI resources deployed on WildFly.
5. Some common issues which you might encounter while running sample java code are explained in the other article: http://middlewaremagic.com/jboss/?p=2724

Creating A Simple JMS Queue on WildFly 10 side

Step-1). Start the WildFly 10 “full” profile (which has messaging) as following:

   $ cd /PATH/TO/wildfly-10.0.0.CR3-SNAPSHOT/bin
   $ ./standalone.sh -c standalone-full.xml

Step-2). Create a simple JMS user on WildFly 10 side and this user must belong to “guest” role. Please see the “messaging subsystem” configuration of “standalone-full.xml” to know more about “guest” role.
username: jmsuser
password: jmsuser@123
user role: guest
Realm: ApplicationRealm

   $ cd /PATH/TO/wildfly-10.0.0.CR3-SNAPSHOT/bin
   $ ./add-user.sh 

What type of user do you wish to add? 
 a) Management User (mgmt-users.properties) 
 b) Application User (application-users.properties)
(a): b

Enter the details of the new user to add.
Using realm 'ApplicationRealm' as discovered from the existing property files.
Username : jmsuser
User 'jmsuser' already exists and is enabled, would you like to... 
 a) Update the existing user password and roles 
 b) Disable the existing user 
 c) Type a new username
(a): a
Password recommendations are listed below. To modify these restrictions edit the add-user.properties configuration file.
 - The password should be different from the username
 - The password should not be one of the following restricted values {root, admin, administrator}
 - The password should contain at least 8 characters, 1 alphabetic character(s), 1 digit(s), 1 non-alphanumeric symbol(s)
Password : 
Re-enter Password : 
What groups do you want this user to belong to? (Please enter a comma separated list, or leave blank for none)[guest]: guest
Updated user 'jmsuser' to file '/Users/jsensharma/NotBackedUp/Installed/wildfly-10.0.0.CR3-SNAPSHOT/standalone/configuration/application-users.properties'
Updated user 'jmsuser' to file '/Users/jsensharma/NotBackedUp/Installed/wildfly-10.0.0.CR3-SNAPSHOT/domain/configuration/application-users.properties'
Updated user 'jmsuser' with groups guest to file '/Users/jsensharma/NotBackedUp/Installed/wildfly-10.0.0.CR3-SNAPSHOT/standalone/configuration/application-roles.properties'
Updated user 'jmsuser' with groups guest to file '/Users/jsensharma/NotBackedUp/Installed/wildfly-10.0.0.CR3-SNAPSHOT/domain/configuration/application-roles.properties'
Is this new user going to be used for one AS process to connect to another AS process? 
e.g. for a slave host controller connecting to the master or for a Remoting connection for server to server EJB calls.
yes/no? yes
To represent the user add the following to the server-identities definition <secret value="am1zdXNlckAxMjM=" />

Step-3). Creating a simple JMS Queue using the WildFly CLI command line utility. NOTE the JNDI name should contain “java:/jboss/exported” prefix or else the JMS queue will can not be looked up remotely.

   $ cd /PATH/TO/wildfly-10.0.0.CR3-SNAPSHOT/bin
   $ ./jboss-cli.sh -c
   
   [standalone@localhost:9990 /] /subsystem=messaging-activemq/server=default/jms-queue=TestQ/:add(entries=["java:/jboss/exported/jms/queue/TestQ"])
     {"outcome" => "success"}
     
   [standalone@localhost:9990 /] :reload
     {
       "outcome" => "success",
       "result" => undefined
     }

The generated XML snippet in the “standalone-full.xml” file will look like following:

        <subsystem xmlns="urn:jboss:domain:messaging-activemq:1.0">
            <server name="default">
                <security-setting name="#">
                    <role name="guest" delete-non-durable-queue="true" create-non-durable-queue="true" consume="true" send="true"/>
                </security-setting>
                <address-setting name="#" message-counter-history-day-limit="10" page-size-bytes="2097152" max-size-bytes="10485760" expiry-address="jms.queue.ExpiryQueue" dead-letter-address="jms.queue.DLQ"/>
                <http-connector name="http-connector" endpoint="http-acceptor" socket-binding="http"/>
                <http-connector name="http-connector-throughput" endpoint="http-acceptor-throughput" socket-binding="http">
                    <param name="batch-delay" value="50"/>
                </http-connector>
                <in-vm-connector name="in-vm" server-id="0"/>
                <http-acceptor name="http-acceptor" http-listener="default"/>
                <http-acceptor name="http-acceptor-throughput" http-listener="default">
                    <param name="batch-delay" value="50"/>
                    <param name="direct-deliver" value="false"/>
                </http-acceptor>
                <in-vm-acceptor name="in-vm" server-id="0"/>
                <jms-queue name="ExpiryQueue" entries="java:/jms/queue/ExpiryQueue"/>
                <jms-queue name="DLQ" entries="java:/jms/queue/DLQ"/>

                <!-- Newly added JMS Queue is Here -->
                <jms-queue name="TestQ" entries="java:/jboss/exported/jms/queue/TestQ"/>

                <connection-factory name="InVmConnectionFactory" entries="java:/ConnectionFactory" connectors="in-vm"/>
                <connection-factory name="RemoteConnectionFactory" entries="java:jboss/exported/jms/RemoteConnectionFactory" connectors="http-connector"/>
                <pooled-connection-factory name="activemq-ra" transaction="xa" entries="java:/JmsXA java:jboss/DefaultJMSConnectionFactory" connectors="in-vm"/>
            </server>
        </subsystem>

NOTE: The “java:/jboss/exported” JNDI prefix is needed in the JNDI name here to ensure that a remote client (a client running outside of that JVM where the JNDI name is bound) can do the lookup.

Writing WildFly JMS Client

Step-4). Create a directory somewhere in your filesystem to place the project WildFly kms client project.

  $ mkdir WildFly10_JMS_Client
  $ mkdir -p WildFly10_JMS_Client/src/client

Step-5). Lets write the “WildFlyJmsQueueSender.java” program which will send some jms messages to the JMS Queue “TestQ” deployed on WildFly and Lets place it inside the “WildFly10_JMS_Client/src/client” as following:

package client;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.util.Properties;

//jms stuff
import javax.jms.JMSException;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.io.IOException;

public class WildFlyJmsQueueSender {
  public final static String JMS_CONNECTION_FACTORY_JNDI="jms/RemoteConnectionFactory";
  public final static String JMS_QUEUE_JNDI="jms/queue/TestQ";
  public final static String JMS_USERNAME="jmsuser";       //  The role for this user is "guest" in ApplicationRealm
  public final static String JMS_PASSWORD="jmsuser@123";  
  public final static String WILDFLY_REMOTING_URL="http-remoting://localhost:8080";

  private QueueConnectionFactory qconFactory;
  private QueueConnection qcon;
  private QueueSession qsession;
  private QueueSender qsender;
  private Queue queue;
  private TextMessage msg;

  public static void main(String[] args) throws Exception {
    InitialContext ic = getInitialContext();
    WildFlyJmsQueueSender queueSender = new WildFlyJmsQueueSender();
    queueSender.init(ic, JMS_QUEUE_JNDI);
    readAndSend(queueSender);
    queueSender.close();
  }

  public void init(Context ctx, String queueName) throws NamingException, JMSException {
    qconFactory = (QueueConnectionFactory) ctx.lookup(JMS_CONNECTION_FACTORY_JNDI);
    
    //  If you won't pass jms credential here then you will get 
    // [javax.jms.JMSSecurityException: HQ119031: Unable to validate user: null]    
    qcon = qconFactory.createQueueConnection(this.JMS_USERNAME, this.JMS_PASSWORD);   
    
    qsession = qcon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    queue = (Queue) ctx.lookup(queueName);
    qsender = qsession.createSender(queue);
    msg = qsession.createTextMessage();
    qcon.start();
  }

  public void send(String message,int counter) throws JMSException {
    msg.setText(message);
    msg.setIntProperty("counter", counter);
    qsender.send(msg);
  }

  public void close() throws JMSException {
    qsender.close();
    qsession.close();
    qcon.close();
  }

  private static void readAndSend(WildFlyJmsQueueSender wildFlyJmsQueueSender) throws IOException, JMSException {
    String line="Test Message Body with counter = ";
    for(int i=0;i<10;i++) {
          wildFlyJmsQueueSender.send(line+i,i);
          System.out.println("JMS Message Sent: "+line+i+"\n");
       }
  }

  private static InitialContext getInitialContext() throws NamingException {
     InitialContext context=null;
     try {
           Properties props = new Properties();
           props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
           props.put(Context.PROVIDER_URL, WILDFLY_REMOTING_URL);   // NOTICE: "http-remoting" and port "8080"
           props.put(Context.SECURITY_PRINCIPAL, JMS_USERNAME);
           props.put(Context.SECURITY_CREDENTIALS, JMS_PASSWORD);
           //props.put("jboss.naming.client.ejb.context", true);
           context = new InitialContext(props);	
	       System.out.println("\n\tGot initial Context: "+context);		
      } catch (Exception e) {
           e.printStackTrace();
      }
    return context;
  }
}

Step-6). Lets write the “WildFlyJmsQueueReceive.java” program which will consume messages from the JMS Queue deployed in WildFly and Lets place it inside the “WildFly10_JMS_Client/src/client” as following:

package client;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.util.Properties;

//jms stuff
import javax.jms.JMSException;
import javax.jms.MessageListener;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueReceiver;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.Message;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.io.IOException;

public class WildFlyJmsQueueReceive  implements MessageListener {
  public final static String JMS_CONNECTION_FACTORY_JNDI="jms/RemoteConnectionFactory";
  public final static String JMS_QUEUE_JNDI="jms/queue/TestQ";
  public final static String JMS_USERNAME="jmsuser";       //  The role for this user is "guest" in ApplicationRealm
  public final static String JMS_PASSWORD="jmsuser@123";  
  public final static String WILDFLY_REMOTING_URL="http-remoting://localhost:8080";


  private QueueConnectionFactory qconFactory;
  private QueueConnection qcon;
  private QueueSession qsession;
  private QueueReceiver qReceiver;
  private Queue queue;
  private TextMessage msg;
  private boolean quit = false;

  public static void main(String[] args) throws Exception {
    InitialContext ic = getInitialContext();
    WildFlyJmsQueueReceive wildflyJmsQueueReceive = new WildFlyJmsQueueReceive();
    wildflyJmsQueueReceive.init(ic, JMS_QUEUE_JNDI);
    System.out.println("JMS Ready To Receive Messages (To quit, send a \"quit\" message from QueueSender.class).");
    // Waiting until a "quit" message has been received.
    synchronized(wildflyJmsQueueReceive) {
         while (! wildflyJmsQueueReceive.quit) {
             try {
                   wildflyJmsQueueReceive.wait();
             }
             catch (InterruptedException ie) {
                   ie.printStackTrace();
             }
         }
     }
     wildflyJmsQueueReceive.close();
  }
  
  public void init(Context ctx, String queueName) throws NamingException, JMSException {
    qconFactory = (QueueConnectionFactory) ctx.lookup(JMS_CONNECTION_FACTORY_JNDI);

    //  If you won't pass jms credential here then you will get 
    // [javax.jms.JMSSecurityException: HQ119031: Unable to validate user: null]    
    qcon = qconFactory.createQueueConnection(this.JMS_USERNAME, this.JMS_PASSWORD);   
    
    qsession = qcon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    queue = (Queue) ctx.lookup(queueName);
    qReceiver = qsession.createReceiver(queue);
    qReceiver.setMessageListener(this);
    qcon.start();
  }

  public void onMessage(Message msg) {
     try {
           String msgText;
           if (msg instanceof TextMessage) {
              msgText = ((TextMessage)msg).getText();
           } else {
              msgText = msg.toString();
           }
           System.out.println("\n<Msg_Receiver> "+ msgText );
           if (msgText.equalsIgnoreCase("quit")) {
             synchronized(this) {
             	 quit = true;
             	 this.notifyAll(); // Notify main thread to quit
             }
           }
      } catch (JMSException jmse) {
          jmse.printStackTrace();
     }
  }

  public void close() throws JMSException {
    qReceiver.close();
    qsession.close();
    qcon.close();
  }
  
  private static InitialContext getInitialContext() throws NamingException {
     InitialContext context=null;
     try {
           Properties props = new Properties();
           props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
           props.put(Context.PROVIDER_URL, WILDFLY_REMOTING_URL);   // NOTICE: "http-remoting" and port "8080"
           props.put(Context.SECURITY_PRINCIPAL, JMS_USERNAME);
           props.put(Context.SECURITY_CREDENTIALS, JMS_PASSWORD);
           //props.put("jboss.naming.client.ejb.context", true);
           context = new InitialContext(props);	
	   System.out.println("\n\tGot initial Context: "+context);		
      } catch (Exception e) {
           e.printStackTrace();
      }
    return context;
  }
}

Step-7). In order to run the above program easily we are going to use ANT, However users can also run the above programs manually by adding the “$JBOSS_HOME/bin/client/jboss-client.jar” in the class path of the client. Here we will be writing the following ind of “build.xml” file inside the “WildFly10_JMS_Client” as following:

<project name="WildFly_Jms_Client" default="runSender">
<property name="jboss.home" value="/Users/jsensharma/NotBackedUp/Installed/wildfly-10.0.0.CR3-SNAPSHOT" />
<property name="jboss.module.dir" value="${jboss.home}/modules" />
<property name="basedir" value="." />
<property name="tmp.dir" value="tmp" />
<property name="src.dir" value="src" />
<property name="output.dir" value="build" />
<property name="client.jar.name" value="wildfly_jms_client.jar" />

        <!-- Client Needs the following Jar to be present in the CLASSPATH including -->
        <path id="jboss.new.client.classpath">
           <fileset dir="${jboss.home}/bin/client">
               <include name="jboss-client.jar" />
           </fileset>  
        </path>

        <target name="runSender">
           <delete dir="${tmp.dir}" />
           <mkdir dir="${tmp.dir}" />
           <javac srcdir="${src.dir}/client" destdir="${tmp.dir}" includes="WildFlyJmsQueueSender.java" classpathref="jboss.new.client.classpath"/> 
           <copy file="${src.dir}/client/WildFlyJmsQueueSender.java" todir="${tmp.dir}/client"/>        
           <jar jarfile="${output.dir}/${client.jar.name}" basedir="${tmp.dir}" compress="true" />
           <delete dir="${tmp.dir}"/>
           <java classname="client.WildFlyJmsQueueSender" fork="true" classpathref="jboss.new.client.classpath">
               <classpath>
                  <pathelement location="${output.dir}/${client.jar.name}"/>
               </classpath>
           </java>
        </target>     

        <target name="runReceive">
           <delete dir="${tmp.dir}" />
           <mkdir dir="${tmp.dir}" />
           <javac srcdir="${src.dir}/client" destdir="${tmp.dir}" includes="WildFlyJmsQueueReceive.java" classpathref="jboss.new.client.classpath"/> 
           <copy file="${src.dir}/client/WildFlyJmsQueueReceive.java" todir="${tmp.dir}/client"/>        
           <jar jarfile="${output.dir}/${client.jar.name}" basedir="${tmp.dir}" compress="true" />
           <delete dir="${tmp.dir}"/>
           <java classname="client.WildFlyJmsQueueReceive" fork="true" classpathref="jboss.new.client.classpath">
               <classpath>
                  <pathelement location="${output.dir}/${client.jar.name}"/>
               </classpath>
           </java>
        </target>             
</project>

Running the WildFly 10 JMS client

Step-8). We can run the above ANT based kms client project simply by setting the ANT_HOME, JAVA_HOME and PATH as following :

For Unix Based OS:

$ export ANT_HOME=/PATH/TO/apache_ant_1.9.2
$ export JAVA_HOME=/PATH/TO/jdk1.8.0_60
$ export PATH=$JAVA_HOME/bin:$ANT_HOME/bin:$PATH
$ cd /PATH/TO/WildFly10_JMS_Client


<strong>For Windows Based OS</strong>
$ set ANT_HOME=C:\PATH\TO\apache_ant_1.9.2
$ set JAVA_HOME=C:\PATH\TO\jdk1.8.0_60
$ set PATH=%JAVA_HOME%\bin;%ANT_HOME%\bin;%PATH%
$ cd C:\WildFly10_JMS_Client

Step-9). In the same above command prompt, Lets run the “WildFlyJmsQueueSender.java” program which will send to messages to the “TestQ” present on WildFly 8 as following :

$ ant runSender

Buildfile: /Users/jsensharma/NotBackedUp/MM_Tests/WildFly/WildFly10_JMS_Client/build.xml

runSender:
    [mkdir] Created dir: /Users/jsensharma/NotBackedUp/MM_Tests/WildFly/WildFly10_JMS_Client/tmp
    [javac] /Users/jsensharma/NotBackedUp/MM_Tests/WildFly/WildFly10_JMS_Client/build.xml:20: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
    [javac] Compiling 1 source file to /Users/jsensharma/NotBackedUp/MM_Tests/WildFly/WildFly10_JMS_Client/tmp
     [copy] Copying 1 file to /Users/jsensharma/NotBackedUp/MM_Tests/WildFly/WildFly10_JMS_Client/tmp/client
      [jar] Building jar: /Users/jsensharma/NotBackedUp/MM_Tests/WildFly/WildFly10_JMS_Client/build/wildfly_jms_client.jar
   [delete] Deleting directory /Users/jsensharma/NotBackedUp/MM_Tests/WildFly/WildFly10_JMS_Client/tmp
      Nov 08, 2015 4:15:53 PM org.xnio.Xnio <clinit>
      INFO: XNIO version 3.3.2.Final
      Nov 08, 2015 4:15:53 PM org.xnio.nio.NioXnio <clinit>
      INFO: XNIO NIO Implementation Version 3.3.2.Final
      
      	Got initial Context: javax.naming.InitialContext@5e7f2a19
      Nov 08, 2015 4:15:53 PM org.jboss.remoting3.EndpointImpl <clinit>
      INFO: JBoss Remoting version 4.0.14.Final
      Nov 08, 2015 4:15:54 PM org.jboss.ejb.client.remoting.VersionReceiver handleMessage
      INFO: EJBCLIENT000017: Received server version 2 and marshalling strategies [river]
      Nov 08, 2015 4:15:54 PM org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver associate
      INFO: EJBCLIENT000013: Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@785ae27e, receiver=Remoting connection EJB receiver [connection=Remoting connection <5720171f>,channel=jboss.ejb,nodename=banl13bca644a-3]} on channel Channel ID dfdae415 (outbound) of Remoting connection 13c57d7d to localhost/127.0.0.1:8080
      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.
      Nov 08, 2015 4:15:54 PM org.jboss.ejb.client.EJBClient <clinit>
      INFO: JBoss EJB Client version 2.1.2.Final
      JMS Message Sent: Test Message Body with counter = 0
      
      JMS Message Sent: Test Message Body with counter = 1
      
      JMS Message Sent: Test Message Body with counter = 2
      
      JMS Message Sent: Test Message Body with counter = 3
      
      JMS Message Sent: Test Message Body with counter = 4
      
      JMS Message Sent: Test Message Body with counter = 5
      
      JMS Message Sent: Test Message Body with counter = 6
      
      JMS Message Sent: Test Message Body with counter = 7
      
      JMS Message Sent: Test Message Body with counter = 8
      
      JMS Message Sent: Test Message Body with counter = 9
      

BUILD SUCCESSFUL
Total time: 2 seconds

Step-10). In the same above command prompt, Lets run the “WildFlyJmsQueueReceive.java” program which will receive the jms messages which are present in the “TestQ” present on WildFly 8 as following :

$ ant runReceive
Buildfile: /Users/jsensharma/NotBackedUp/MM_Tests/WildFly/WildFly10_JMS_Client/build.xml

runReceive:
    [mkdir] Created dir: /Users/jsensharma/NotBackedUp/MM_Tests/WildFly/WildFly10_JMS_Client/tmp
    [javac] /Users/jsensharma/NotBackedUp/MM_Tests/WildFly/WildFly10_JMS_Client/build.xml:34: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
    [javac] Compiling 1 source file to /Users/jsensharma/NotBackedUp/MM_Tests/WildFly/WildFly10_JMS_Client/tmp
     [copy] Copying 1 file to /Users/jsensharma/NotBackedUp/MM_Tests/WildFly/WildFly10_JMS_Client/tmp/client
      [jar] Building jar: /Users/jsensharma/NotBackedUp/MM_Tests/WildFly/WildFly10_JMS_Client/build/wildfly_jms_client.jar
   [delete] Deleting directory /Users/jsensharma/NotBackedUp/MM_Tests/WildFly/WildFly10_JMS_Client/tmp
      Nov 08, 2015 4:28:23 PM org.xnio.Xnio <clinit>
      INFO: XNIO version 3.3.2.Final
      Nov 08, 2015 4:28:23 PM org.xnio.nio.NioXnio <clinit>
      INFO: XNIO NIO Implementation Version 3.3.2.Final
      Nov 08, 2015 4:28:23 PM org.jboss.remoting3.EndpointImpl <clinit>
      INFO: JBoss Remoting version 4.0.14.Final
      
      	Got initial Context: javax.naming.InitialContext@129458ea
      Nov 08, 2015 4:28:23 PM org.jboss.ejb.client.remoting.VersionReceiver handleMessage
      INFO: EJBCLIENT000017: Received server version 2 and marshalling strategies [river]
      Nov 08, 2015 4:28:23 PM org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver associate
      INFO: EJBCLIENT000013: Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@67d07b41, receiver=Remoting connection EJB receiver [connection=Remoting connection <533a0538>,channel=jboss.ejb,nodename=banl13bca644a-3]} on channel Channel ID c898038c (outbound) of Remoting connection 7a73ad16 to localhost/127.0.0.1:8080
      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.
      Nov 08, 2015 4:28:23 PM org.jboss.ejb.client.EJBClient <clinit>
      INFO: JBoss EJB Client version 2.1.2.Final
      JMS Ready To Receive Messages (To quit, send a "quit" message from QueueSender.class).
      
      <Msg_Receiver> Test Message Body with counter = 0
      
      <Msg_Receiver> Test Message Body with counter = 1
      
      <Msg_Receiver> Test Message Body with counter = 2
      
      <Msg_Receiver> Test Message Body with counter = 3
      
      <Msg_Receiver> Test Message Body with counter = 4
      
      <Msg_Receiver> Test Message Body with counter = 5
      
      <Msg_Receiver> Test Message Body with counter = 6
      
      <Msg_Receiver> Test Message Body with counter = 7
      
      <Msg_Receiver> Test Message Body with counter = 8
      
      <Msg_Receiver> Test Message Body with counter = 9

Issues which you may encounter

You might see some error/exceptions while running this demo in that case you can refer to the following article which explains some common issues which you might encounter while running this code. The following link also contains the remedies of those common exceptions.

Wildfly 8 based standalone JMS client code common issues and remedies ?
http://middlewaremagic.com/jboss/?p=2724

Monitoring JMS Queue using CLI

If we want to monitor the JMS Queue using jboss-cli.sh script then we can do it as following:

/subsystem=messaging-activemq/server=default/jms-queue=TestQ/:read-resource(recursive=true,include-runtime=true)
{
    "outcome" => "success",
    "result" => {
        "consumer-count" => 0,
        "dead-letter-address" => "jms.queue.DLQ",
        "delivering-count" => 0,
        "durable" => true,
        "entries" => ["java:/jboss/exported/jms/queue/TestQ"],
        "expiry-address" => "jms.queue.ExpiryQueue",
        "legacy-entries" => undefined,
        "message-count" => 20L,
        "messages-added" => 30L,
        "paused" => false,
        "queue-address" => "jms.queue.TestQ",
        "scheduled-count" => 0L,
        "selector" => undefined,
        "temporary" => false
    }
}

.
.
The Source code of this demo can be found at: (The code should remain same for WildFly 8/9/10)
https://github.com/jaysensharma/MiddlewareMagicDemos/tree/master/WildFly/JMS/WildFly_JMS_Client

.
.

Regards
Jay SenSharma

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.