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

发布于 2024-10-02 16:16:39 字数 1014 浏览 0 评论 0原文

我可以通过使用 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 操作,但我没有找到任何可以帮助我的东西。

您能给我一些提示吗?我可以寻找什么?

谢谢你, 奥斯卡

编辑:只是想让你知道:我不想消耗队列,我想要与浏览器类似的行为,在浏览器中我可以读取消息而不将它们从队列中删除。

I am able to query for queues by invoking a GET_DESTINATIONS operation using JMX. With that I will receive the queue info (attributes).
I would like now to query the messages that are stored in this queue, is that possible? Could someone give me some direction?

I have already tried using this code

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

But for some reason O can't access the same queue as using JMX. I didn't made any research on that because I want to use JMX as the access standard.

I am still trying to find any JMX operation that could help me, but I am not finding anything that could help me.

Could you please give me some hints what can I look for?

thank you,
Oscar

Edit: just to let you know: I don't want to consume the queues, I want a similar behavior to the Browser, in which I can read the messages without removing them from the queue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

拥有 2024-10-09 16:16:39
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();

此代码将为您提供消息,然后只需迭代它,您就可以获得有关消息及其内容的信息

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

This code will give you the messages, then just iterate through it and you can get get infos about the message and its content

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文