我能够通过使用JMX调用GET_DESTINATIONS操作来查询队列。这样,我将收到队列信息(属性)。我现在想查询存储在此队列中的消息,可以吗?谁能给我指个方向?
我已经尝试过使用下面的代码
ConnectionFactory connectionFactory = new
com.sun.messaging.QueueConnectionFactory();
Connection connection = connectionFactory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue myQueue = session.createQueue(string);
QueueBrowser browser = session.createBrowser(myQueue);
Enumeration msgs = browser.getEnumeration();
if (!msgs.hasMoreElements()) {
System.out.println("No messages in queue");
} else {
while (msgs.hasMoreElements()) {
Message tempMsg = (Message) msgs.nextElement();
System.out.println("Message: " + tempMsg);
}
}
connection.close();但是由于某些原因,O不能访问与使用JMX相同的队列。我没有对此做任何研究,因为我想使用JMX作为访问标准。
我仍然在努力寻找任何可以帮助我的JMX操作,但是我没有找到任何可以帮助我的东西。
你能给我一些提示吗?我该找些什么?
谢谢你,奥斯卡
编辑:只想让您知道:我不想使用队列,我想要一个类似于浏览器的行为,在这种行为中,我可以读取消息,而不需要从队列中删除它们。
发布于 2010-12-14 17:54:10
QueueBrowser browser = null;
try{
Queue myQueue = session.createQueue(getName());
//Create the browser and session to be able to iterate
browser = session.createBrowser(myQueue);
Enumeration msgs = browser.getEnumeration();这段代码将为您提供消息,然后只需迭代它,您就可以获得有关该消息及其内容的信息
https://stackoverflow.com/questions/4193084
复制相似问题