我在JMS項目的工作,我們使用的是消息驅動Bean(@MessageDriven)與服務器JBoss的是7.我們正在增加在會議的工作爲我們添加JmsProducer & JmsConsumer。現在我們要獲取當前隊列的狀態(如當前隊列計數,等待計數,順序,優先級)。這些所有細節都在JmsProducer中設置。如何在EJB 3.0中獲取JBoss AS 7中的隊列詳細信息?
我們試圖讓這些細節與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)。
我試了很多方法,但枚舉總是空(儘管會話/隊列正在運行在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();
任何可能的方式/方法/理念將是有益的。提前致謝。
我獨立,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-與-的JBoss-AS-7
https://docs.jboss.org/author/display/AS71/Messaging+configuration