Search code examples
javajmswebsphereibm-mq

How i can get list with names of all queues in remote websphere application server?


I connect to remote was with AdminClient and get list of queues with some code:

...
AdminClient client = new AdminClientFactory.createAdminClient(props);
Set<ObjectName> s = client.queryNames(new ObjectName("WebSphere:*"),null);
if (!s.isEmpty()){
     Iterator i = s.iterator();
     while (i.hasNext){
          ObjectName on = i.next();
          String type = on.getKeyProperty("type");
          if ("SIBQueuePoint".eqquals(type)){
               System.out.println(on.getKeyProperty("name");)
          }
     }
}

This list me queues with JMS provider "Default Messaging provider". But also, i have some queues with "Websphere MQ messaging provider", which not exist in this list.

How i can get list with all queues from all JMS providers?


Solution

  • Srry for late. As i promise, here is the script in python language.

    All you have to do is to replace your scope and your resource file.

    import sys, java, java.io, java.lang
    
    lineSeparator = java.lang.System.getProperty('line.separator')
    
    def listMQQCF(scope):
        scopeID = AdminConfig.getid(scope)
        scopeName = scope[scope.rfind(":")+1:scope.rfind("/")]
        wmqQCFList = AdminConfig.list('MQQueueConnectionFactory', scopeID).split(lineSeparator)
        MQQCFListHeader = "\n#==== MQQueueConnectionFactoryList " + scopeName + " ===="
        MQQCFListHeader = MQQCFListHeader + "\n#[name, jndiName, ,description, queueManager, transportType, host, port, channel, ConmaxConn, ConminCon, SessionmaxConn, SessionminConn]\n"  
        MQQCFList = "MQQueueConnectionFactoryList = [\\\n"
        if (len(wmqQCFList) > 0):
            for wmqQCF in wmqQCFList:
                wmqQCFName = wmqQCF[wmqQCF.rfind("/")+1:wmqQCF.find("|")]
                if (scopeName == wmqQCFName):
                    name = AdminConfig.showAttribute(wmqQCF, 'name')
                    jndiName = AdminConfig.showAttribute(wmqQCF, 'jndiName')
                    description = AdminConfig.showAttribute(wmqQCF, 'description')
                    if (description == None): description = ""
                    queueManager = AdminConfig.showAttribute(wmqQCF, 'queueManager')                
                    transportType = AdminConfig.showAttribute(wmqQCF, 'transportType')
                    host = AdminConfig.showAttribute(wmqQCF, 'host')
                    port = AdminConfig.showAttribute(wmqQCF, 'port')
                    channel = AdminConfig.showAttribute(wmqQCF, 'channel')
                    connPool = AdminConfig.showAttribute(wmqQCF, 'connectionPool')
                    sessionPool = AdminConfig.showAttribute(wmqQCF, 'sessionPool')
                    connTimeout = AdminConfig.showAttribute(connPool, "connectionTimeout")
                    maxConn = AdminConfig.showAttribute(connPool, "maxConnections")
                    minConn = AdminConfig.showAttribute(connPool, "minConnections")
                    reapTime = AdminConfig.showAttribute(connPool, "reapTime")
                    unusedTimeout =  AdminConfig.showAttribute(connPool, "unusedTimeout")
                    agedTimeout = AdminConfig.showAttribute(connPool, "agedTimeout")
                    sesconnTimeout = AdminConfig.showAttribute(sessionPool, "connectionTimeout")
                    sesmaxConn = AdminConfig.showAttribute(sessionPool, "maxConnections")
                    sesminConn = AdminConfig.showAttribute(sessionPool, "minConnections")
                    sesreapTime = AdminConfig.showAttribute(sessionPool, "reapTime")
                    sesunusedTimeout =  AdminConfig.showAttribute(sessionPool, "unusedTimeout")
                    sesagedTimeout = AdminConfig.showAttribute(sessionPool, "agedTimeout")
                    MQQCFList = MQQCFList + "['" + name + "','" + jndiName + "','" + description + "','" +  queueManager + "','" + transportType + "','" + host + "','" + port + "','" + channel + "','" + maxConn + "','" + minConn + "','" + sesmaxConn + "','" + sesminConn + "'],\\\n"
        if (MQQCFList[len(MQQCFList)-3] == ","):
            MQQCFList = MQQCFList[0:len(MQQCFList)-3] + "]\n"
        else:
            MQQCFList = MQQCFList[0:len(MQQCFList)-2] + "]\n"
        return MQQCFListHeader + MQQCFList
    
    def listMQQueue(scope):
        scopeID = AdminConfig.getid(scope)
        scopeName = scope[scope.rfind(":")+1:scope.rfind("/")]
        objdmgr = AdminControl.queryNames('WebSphere:type=Server,name=dmgr,*')
        version = objdmgr[objdmgr.find("version")+8:]
        wmqQueueList = AdminConfig.list('MQQueue', scopeID).split(lineSeparator)
        MQQueueListHeader = "\n#==== MQQueueList " + scopeName + "  ====\n#[name, jndiName, description, baseQueueName, baseQMgrName, persistence, priority, targetClient, messageBody]\n"
        MQQueueList = "MQQueueList = [\\\n"
        if (len(wmqQueueList) > 0) :
            for wmqQueue in wmqQueueList:
                wmqQueueName = wmqQueue[wmqQueue.rfind("/")+1:wmqQueue.find("|")]
                if (scopeName == wmqQueueName):
                    name = AdminConfig.showAttribute(wmqQueue, 'name')
                    jndiName = AdminConfig.showAttribute(wmqQueue, 'jndiName')
                    description = AdminConfig.showAttribute(wmqQueue, 'description')
                    if (description == None):   description = ""
                    baseQueueName = AdminConfig.showAttribute(wmqQueue, 'baseQueueName')
                    baseQMgrName = AdminConfig.showAttribute(wmqQueue, 'baseQueueManagerName')
                    if (baseQMgrName == None):  baseQMgrName = ""
                    persistence = AdminConfig.showAttribute(wmqQueue, 'persistence')    
                    priority = AdminConfig.showAttribute(wmqQueue, 'priority')
                    targetClient = AdminConfig.showAttribute(wmqQueue, 'targetClient')
                    if (version =='8'):
                        messageBody = AdminConfig.showAttribute(wmqQueue, 'messageBody')
                    else:
                        messageBody = ""                
                    MQQueueList = MQQueueList + "['" + name + "','" + jndiName + "','" + description + "','" + baseQueueName + "','" + baseQMgrName + "','" + persistence + "','" + priority + "','" + targetClient + "','" + messageBody + "'],\\\n"               
                #endif
        if (MQQueueList[len(MQQueueList)-3] == ","):
            MQQueueList = MQQueueList[0:len(MQQueueList)-3] + "]\n"
        else:
            MQQueueList = MQQueueList[0:len(MQQueueList)-2] + "]\n"
        return MQQueueListHeader + MQQueueList
    
    
    #===============================================
    #MAIN
    #===============================================    
    
    filename='resources.txt'
    scope='/Cell:CellName/ServerCluster:ClusterName/'
    
    
    objItemFileOutputStream = java.io.FileOutputStream(fileName, 1)
    scopeID = AdminConfig.getid(scope)
    if ( scopeID <> ""):
        list = listRes(objType, scope)
        objItemFileOutputStream.write(list)
    else:
        print "\n" + scope + "\t Failed: Incorrect scopes!\n"
    objItemFileOutputStream.close()
    

    Good Luck!