1 Reply Latest reply on Oct 16, 2015 3:42 PM by Justin Bertram

    How to get queue details in JBoss AS 7 with EJB 3.0?

    S BH Newbie

      I am working in JMS project where we are using Message Driven beans (@MessageDriven) with Server is JBoss 7. We are adding jobs in sessions for that we added JmsProducer & JmsConsumer. Now we want to get status of current queue(like current queue count, waiting count, order, priority). These all details are set in JmsProducer.

       

      We tried to get these details with CLI scripts and with JBoss Admin Console. Cli method works as shown below.

      Queue used is HornetQ.

       

        "address" => [

           ("subsystem" => "messaging"),

           ("hornetq-server" => "default"),

           ("jms-queue" => "transmit_postprocessing")

      ],

      "outcome" => "success",

      "result" => {

           "consumer-count" => 1,

           "dead-letter-address" => "jms.queue.DLQ",

           "delivering-count" => 0,

           "durable" => true,

           "entries" => ["java:jboss/queue/transmit_postprocessing"],

           "expiry-address" => "jms.queue.ExpiryQueue",

           "message-count" => 0L,

           "messages-added" => 4L,

           "paused" => false,

           "queue-address" => "jms.queue.transmit_postprocessing",

           "scheduled-count" => 0L,

           "selector" => undefined,

           "temporary" => false

      }

      JmsProducer : (Working)

       

      Context context = new InitialContext();

      ConnectionFactory connectionFactory = (ConnectionFactory)context.lookup("java:/ConnectionFactory");

      Connection connection = connectionFactory.createConnection();

      Session jmsSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

      Destination destination = (Destination) context.lookup("java:jboss/queue/preprocessing");

      MessageProducer messageProducer = jmsSession.createProducer(destination);

      ObjectMessage objectMessage = jmsSession.createObjectMessage();

               for (String key: payload.keySet()) {

                  String value = payload.get(key).toString();

                  objectMessage.setStringProperty(key, value);

               }

       

      Is there any other way to get queue details in JmsConsumer?

      Our previous code for consumer is not working now(may bo due to JBoss version chnage to 7).

      I tried so many ways but the Enumeration is always null(though sessions/queue are running on JBoss)

      For example:

       

      ConnectionFactory connectionFactory =  (ConnectionFactory)context.lookup("java:/ConnectionFactory");

      Queue queue = (Queue)context.lookup("java:jboss/queue/preprocessing");

      QueueBrowser browser = session.createBrowser(queue);

      ArrayList<QueueMessage> messages = new ArrayList<QueueMessage>();

      Enumeration e = browser.getEnumeration();

       

      Any probable way/approach/idea will be useful. Thanks in advance.

       

      My standalone-full.xml file

       

      <jms-connection-factories>

          <connection-factory name="InVmConnectionFactory">

              <connectors>

                  <connector-ref connector-name="in-vm"/>

              </connectors>

              <entries>

                  <entry name="java:/ConnectionFactory"/>

              </entries>

          </connection-factory>

          <connection-factory name="RemoteConnectionFactory">

              <connectors>

                  <connector-ref connector-name="netty"/>

              </connectors>

              <entries>

                  <entry name="RemoteConnectionFactory"/>

                  <entry name="java:jboss/exported/jms/RemoteConnectionFactory"/>

              </entries>

          </connection-factory>

          <pooled-connection-factory name="hornetq-ra">

              <transaction mode="xa"/>

              <connectors>

                  <connector-ref connector-name="in-vm"/>

              </connectors>

              <entries>

                  <entry name="java:/JmsXA"/>

              </entries>

          </pooled-connection-factory>

      </jms-connection-factories>

       

      <jms-destinations>

          <jms-queue name="testQueue">

              <entry name="queue/test"/>

              <entry name="java:jboss/exported/jms/queue/test"/>

          </jms-queue>

          <jms-queue name="preprocessing">

              <entry name="java:jboss/queue/preprocessing"/>

              <durable>true</durable>

          </jms-queue>

          <jms-queue name="processing">

              <entry name="java:jboss/queue/processing"/>

              <durable>true</durable>

          </jms-queue>

          <jms-queue name="postprocessing">

              <entry name="java:jboss/queue/postprocessing"/>

              <durable>true</durable>

          </jms-queue>

          <jms-queue name="approval_preprocessing">

              <entry name="java:jboss/queue/approval_preprocessing"/>

              <durable>true</durable>

          </jms-queue>

          <jms-queue name="approval_postprocessing">

              <entry name="java:jboss/queue/approval_postprocessing"/>

              <durable>true</durable>

          </jms-queue>

          <jms-queue name="transmit_preprocessing">

              <entry name="java:jboss/queue/transmit_preprocessing"/>

              <durable>true</durable>

          </jms-queue>

          <jms-queue name="transmit_postprocessing">

              <entry name="java:jboss/queue/transmit_postprocessing"/>

              <durable>true</durable>

          </jms-queue>

          <jms-queue name="batch">

              <entry name="java:jboss/queue/batch"/>

              <entry name="java:jboss/exported/jms/queue/batch"/>

              <durable>true</durable>

          </jms-queue>

          <jms-queue name="plmpreprocessing">

              <entry name="java:jboss/queue/plmpreprocessing"/>

              <durable>true</durable>

          </jms-queue>

          <jms-queue name="dex_delete">

              <entry name="java:jboss/queue/dex_delete"/>

              <durable>true</durable>

          </jms-queue>

          <jms-topic name="testTopic">

              <entry name="topic/test"/>

              <entry name="java:jboss/exported/jms/topic/test"/>

          </jms-topic>

      </jms-destinations>

       

      References used:

      Chapter 7. Running the Examples

      Monitoring JMS resources with JBoss AS 7

      Messaging configuration - JBoss AS 7.1 - Project Documentation Editor