简体   繁体   English

列出Tibco EMS中的所有JMS队列

[英]Listing all JMS queues in Tibco EMS

I am writing a Java class to browse a Tibco EMS JMS server and show all queues. 我正在编写一个Java类来浏览Tibco EMS JMS服务器并显示所有队列。 I'm able to connect without issues and browse specific queues but I am looking for a way to return a list of all queues (with queue depth if possible). 我能够毫无问题地连接并浏览特定的队列,但是我正在寻找一种返回所有队列列表的方法(如果可能的话,返回队列深度)。 I'm not if there is a specific EMS API to use so I am using standard JMS. 我没有要使用的特定EMS API,因此我使用的是标准JMS。

I've tried the following code to do a reverse JNDI lookup but it is failing. 我已经尝试了以下代码来进行反向JNDI查找,但是失败了。

NamingEnumeration<?> queues = context.list("");
List<String> availableQueuesNames = new ArrayList<String>();
while (queues.hasMoreElements()) {
    NameClassPair element = (NameClassPair) queues.nextElement();
    availableQueuesNames.add(element.getName());
}

Which throws this error: 引发此错误:

javax.naming.OperationNotSupportedException: Not supported
    at com.tibco.tibjms.naming.TibjmsContext.list(TibjmsContext.java:1018)
    at com.tibco.tibjms.naming.TibjmsContext.list(TibjmsContext.java:484)
    at javax.naming.InitialContext.list(Unknown Source)

I did some digging and it seems Tibco EMS does not support looking into the JNDI like this. 我做了一些挖掘,看来Tibco EMS不支持像这样调查JNDI。 Is there another way to accomplish this? 还有另一种方法可以做到这一点吗?

Using the tibjmsServerAdministrator.java same class provided with Tibco as a guide (and the addAdmin() method), I was able to write code to list all queues: 使用与Tibco一起提供的tibjmsServerAdministrator.java相同的类作为指南(以及addAdmin()方法),我能够编写代码以列出所有队列:

Map<String, TibjmsAdmin> map = new HashMap<String, TibjmsAdmin>();
addAdmin(txtServer.getText(), txtUser.getText(), txtPassword.getText(), map);
_admin = new TibjmsAdmin[map.size()];
map.values().toArray(_admin);

QueueInfo[] info = _admin[0].getQueues(null);
for (int i = 0; i < info.length; i++) {
    String queueName = info[i].getName();
    if (!queueName.startsWith("$") && !queueName.startsWith(">")) {
        queues.add(queueName + ", 0");
    }
}

I'm not sure about Tibco details, but maybe it would work with listBindings instead of list ? 我不确定Tibco的详细信息,但也许可以用listBindings代替list

I have done the same thing in a generic way like this: 我已经以这种通用方式完成了同样的事情:

List<Queue> out = new ArrayList<>();
scanJndiForQueues(out, "");

...

private void scanJndiForQueues(List<Queue> out, String path) throws NamingException {
    InitialContext context = new InitialContext();
    Object resource = context.lookup(path);
    if (isSubContext(resource)) {
        NamingEnumeration<Binding> list = context.listBindings(path);
        while (list.hasMoreElements()) {
            Binding binding = list.nextElement();
            scanJndiForQueues(out, path + "/" + binding.getName());
        }
    } else if (resource instanceof Queue) {
        out.add((Queue) resource);
    } // else ignore Topics
}

private boolean isSubContext(Object object) {
    return javax.naming.Context.class.isAssignableFrom(object.getClass());
}

Don't know why you need to list all the EMS queues, but you can achieve this (and many other things) with the GEMS tool. 不知道为什么需要列出所有EMS队列,但是您可以使用GEMS工具来实现此目的(以及许多其他功能)。

Search for it at tibcommunity (you will need an account), or you can download the last version directly from here . tibcommunity搜索它(您需要一个帐户),或者您可以从此处直接下载最新版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM