我使用AdminClient连接到远程,并使用一些代码获取队列列表:
...
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");)
}
}
}
这列出了JMS提供程序“Default Messaging provider”的队列。但是,我有一些“Websphere MQ消息提供程序”的队列,这个列表中不存在。
我如何获得所有JMS提供商的所有队列列表?
答案 0 :(得分:0)
很抱歉。正如我所承诺的,这是python语言的脚本。
您所要做的就是更换范围和资源文件。
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()
祝你好运!