OpenMQ和JMX - 是否可以查询消息?

我可以通过使用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操作,但我找不到任何可以帮助我的东西。 能不能给我一些提示我能找到什么? 谢谢, 奥斯卡 编辑:只是为了让你知道:我不想使用队列,我想要一个与浏览器类似的行为,我可以在其中读取消息而不从队列中删除它们。     
已邀请:
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();
此代码将为您提供消息,然后只需遍历它,您就可以获得有关消息及其内容的信息     

要回复问题请先登录注册