如何从Java连接到Websphere MQ队列的消费者数量 [英] How to get number of consumers connected to Websphere MQ queue from Java

查看:375
本文介绍了如何从Java连接到Websphere MQ队列的消费者数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Java获取特定Websphere MQ队列的使用者数量?我需要知道是否有人在将消息放入队列之前消费这些消息。

I am trying to get the number of consumers of a particular Websphere MQ queue from Java? I need to know whether someone is going to consume the messages before placing them on the queue.

推荐答案

首先,值得注意的是提出的设计是一个非常非常糟糕的设计。其结果是将异步消息传递回同步消息传递。这将消息生成者与消费者联系起来,引入位置和解决方案依赖关系,打破群集,破坏WMQ的负载分配和平衡,将网络拓扑嵌入到应用程序中,并使整个系统变得脆弱。在故意击败除实际队列/出队操作之外的所有最佳功能之后,请不要责怪WMQ无法正常工作。

First, it is worth noting that the design proposed is a very, VERY bad design. The effect is to turn async messaging back into synchronous messaging. This couples message producers to consumers, introduces location and resolution dependencies, breaks clustering, defeats WMQ's load distribution and balancing, embeds network topology into the application, and makes the whole system brittle. Please do not blame WMQ for not working correctly after intentionally defeating all its best features except the actual queue/dequeue operations.

但是,要更直接地回答您的问题,请使用 getOpenInputCount 队列对象的方法,以获取打开的输入句柄的数量。方法如下:

However, to answer your question more directly, use the getOpenInputCount method of the queue object to obtain the number of open input handles. Here's how:

MQQueue outQ = qMgr.accessQueue(qName,
                                openOptions,
                                null,           // default q manager
                                null,           // no dynamic q name
                                null);          // no alternate user id

int inCount = outQ.getOpenInputCount(); 

请注意,您只能查询本地队列上的输入句柄。如果队列托管在QMgr 其他上,而不是连接邮件发件人的队列,则此方法将不起作用。当然,正常情况下,消息发送方和接收方将驻留在不同的QMgrs上。但是,由于您没有提及很多关于设计的内容,因此我假设出于此答案的目的,来自消息生产者和消费者的连接附加到相同的QMgr。如果情况并非如此,我们需要就PCF进行讨论,甚至对设计提出更强烈的警告。

Note that you can only inquire the input handles on a local queue. If the queue is hosted on a QMgr other than the one where the message sender is connected, this method will not work. Of course it is the normal case that the message sender and receiver would reside on different QMgrs. However since you do not mention much about the design, I'll assume for purposes of this answer that connections from the message producer and consumer attach to the same QMgr. If that's not the case, we need to have a discussion about PCF and even stronger warnings about the design.

这篇关于如何从Java连接到Websphere MQ队列的消费者数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆