如何使用EJB 3.0获取JBoss AS 7中的队列详细信息?

时间:2015-10-16 19:19:20

标签: jboss ejb jms hornetq

我在JMS项目中工作,我们使用Message Driven bean(@MessageDriven),Server是JBoss 7.我们在会话中添加了作业,我们添加了JmsProducer& JmsConsumer。现在我们想要获取当前队列的状态(如当前队列计数,等待计数,顺序,优先级)。这些所有细节都在JmsProducer中设置。

我们尝试使用CLI脚本和JBoss管理控制台获取这些详细信息。 Cli方法的工作原理如下所示。

使用的队列是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 :(工作)

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); 
         }

有没有其他方法可以在JmsConsumer中获取队列详细信息?

我们以前的消费者代码现在不能正常工作(可能因为JBoss版本的chnage为7)。

我尝试了很多方法但是Enumeration总是为null(尽管会话/队列在JBoss上运行)

例如:

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();

任何可能的方法/方法/想法都会有用。提前谢谢。

我的standalone-full.xml文件

<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>

使用的参考文献:

http://docs.jboss.org/jbossmessaging/docs/userguide-1.2.0.GA/html/examples.html

www.mastertheboss.com/jboss-server/jboss-jms/monitoring-jms-resources-with-jboss-as-7

https://docs.jboss.org/author/display/AS71/Messaging+configuration

1 个答案:

答案 0 :(得分:0)