从 UFT 连接到 IBM MQ
Connecting to IBM MQ from UFT
我一直在尝试从 UFT 读取消息并将消息写入 MQ。我正在使用 dotnet 工厂实例。当我在访问队列和读写消息时遇到问题时,我已经达到了能够连接到 MQ 的地步。
代码如下
strQMgrName = "queue manager name"
strMQMDllPath = "C:\Program Files (x86)\IBM\WebSphere MQ\bin\amqmdnet.dll"
Set oMqEnvironment = DotNetFactory.CreateInstance("IBM.WMQ.MQEnvironment",strMQMDllPath)
oMqEnvironment.Hostname = "host name"
oMqEnvironment.Port = "port number"
oMqEnvironment.Channel = "channel name"
Set oMQC = DotNetFactory.CreateInstance("IBM.WMQ.MQC",strMQMDllPath)
' qmanager name,channel name, connection name
Set oMqQMgr = DotNetFactory.CreateInstance("IBM.WMQ.MQQueueManager",strMQMDllPath,strQMgrName)
oMqQMgr.isConnected '给出 true
现在我想使用方法
public MQQueue AccessQueue(string queueName, int openOptions)
实例 IBM.WMQ.MQQueueManager。有人可以指导我做同样的事情,让我知道如何从上述队列中推送消息和读取消息
谢谢
经过大量谷歌搜索和阅读 IBM 文档后,我能够从 UFT 在 MQ 中放置和获取消息。 .. 下面是对我有用的代码片段.. 希望这对某些人有帮助.. 我正在分别处理 PUT 和 GET,因此代码中可能会有一些重复。
先决条件..您必须从 IBM 站点下载 MQ 客户端并将其安装在安装了 UFT 的 PC 上..IBM MQ 客户端是免费软件
Dim oMQEnvironment
Dim oMQM
Dim oMQC
Dim oMQMessage
Dim oMQQueue
Dim intOpenOptions
strMQMDLLPath = "C:\Program Files (x86)\IBM\WebSphere MQ\bin\amqmdnet.dll"
strHostName= "Host Name"
intPort = "Port Number"
strChannel ="Channel Name"
strMessage ="UFT Test Message"
strMQManager = "Quemanager Name"
strMessageQueue = "Queue Name"
' 这部分代码是公然从网上的post之一复制过来的。一旦我再次找到它,post link 会吗
'用于应用程序 (UFT) 以客户端模式连接到队列管理器
Set oMQEnvironment = DotNetFactory.CreateInstance("IBM.WMQ.MQEnvironment",strMQMDLLPath)
'Initize the Environment
With oMQEnvironment
.HostName = strHostName
.Port = intPort
.Channel = strChannel
End with
On Error Resume Next
'Create MQ Instatnces
Set oMQM = DotnetFactory.CreateInstance("IBM.WMQ.MQQueueManager",strMQMDLLPath)
'Check if MQM Connected
If Err.Number <> 0 Then
Reporter.ReportEvent micFail , "Step: Creating MQM Object" , "Unable to Connect to MQ Manager at" & strHostName
'Exit Test
End If
Set oMQC = DotnetFactory.CreateInstance("IBM.WMQ.MQC",strMQMDLLPath)
Set oMQMessage = DotnetFactory.CreateInstance("IBM.WMQ.MQMessage",strMQMDLLPath)
'Declare Q open options
intOpenOptions = oMQC.MQOO_OUTPUT or oMQC.MQOO_FAIL_IF_QUIESCING ' 16 + 8192
'Open the Q to post the messages
If strRemoteMQManager = "" Then
Set oMQQueue = oMQM.AccessQueue(strMessageQueue , intOpenOptions)
Else
Set oMQQueue = oMQM.AccessQueue(strMessageQueue , intOpenOptions ,strRemoteMQManager, "","" )
End If
'Format Message
With oMQMessage
.CharacterSet = 819
.WriteString(strMessage)
End with
'Post Message
With oMQQueue
.Put(oMQMessage)
.Close()
End With
现在从 MQ 获取消息
Dim oMQEnvironment
Dim oMQM
Dim oMQC
Dim oMQMessage
Dim oMQQueue
strMQMDLLPath = "C:\Program Files (x86)\IBM\WebSphere MQ\bin\amqmdnet.dll"
strHostName= "host name"
intPort = "port number"
strChannel ="channel name"
strMessage ="UFT Test Message"
strMessageQueue = "message queue intended to access"
strMQManager = "mq manager name"
strRemoteMQManager=""
'Create MQ Instances
Set oMQC = DotnetFactory.CreateInstance("IBM.WMQ.MQC",strMQMDLLPath)
'set the properties of the Queue manager
Set properties = DotNetFactory.CreateInstance("System.Collections.Hashtable")
properties.Add oMQC.HOST_NAME_PROPERTY, strHostName
properties.Add oMQC.PORT_PROPERTY, intPort
properties.Add oMQC.CHANNEL_PROPERTY, strChannel
'access the queue manager
Set oMQM = DotnetFactory.CreateInstance("IBM.WMQ.MQQueueManager",strMQMDLLPath,strMQManager,properties)
'here We are trying to browse the message one by one and keep the messages on the queue.
'Declare Q open options
Set oMQQueue = oMQM.AccessQueue(strMessageQueue,oMQC.MQOO_BROWSE)
Set oMQGetMessageOptions = DotNetFactory.CreateInstance("IBM.WMQ.MQGetMessageOptions",strMQMDLLPath)
oMQGetMessageOptions.Options = oMQC.MQGMO_BROWSE_FIRST
Set oMQMessage = DotnetFactory.CreateInstance("IBM.WMQ.MQMessage",strMQMDLLPath)
oMQQueue.Get oMQMessage,oMQGetMessageOptions
Set mqGetNextMsgOpts = DotNetFactory.CreateInstance("IBM.WMQ.MQGetMessageOptions",strMQMDLLPath)
mqGetNextMsgOpts.Options = oMQC.MQGMO_BROWSE_NEXT
browseMessages = true
Do while browseMessages
on error resume next
messageText = oMQMessage.ReadString(oMQMessage.MessageLength)
'Print messageText
Set oMQMessage = DotnetFactory.CreateInstance("IBM.WMQ.MQMessage",strMQMDLLPath)
oMQQueue.Get oMQMessage,mqGetNextMsgOpts
if Err.Number <> 0 then browseMessages =false
'Clear both MsgID and CorrelID for next use.
oMQMessage.MessageId = oMQC.MQMI_NONE
oMQMessage.CorrelationId = oMQC.MQCI_NONE
Loop
'Cleanup
Set oMQQueue = Nothing
Set oMQMessage= Nothing
Set oMQOpenOptions= Nothing
Set oMQM= Nothing
Set oMQEnvironment = Nothing
我一直在尝试从 UFT 读取消息并将消息写入 MQ。我正在使用 dotnet 工厂实例。当我在访问队列和读写消息时遇到问题时,我已经达到了能够连接到 MQ 的地步。
代码如下
strQMgrName = "queue manager name"
strMQMDllPath = "C:\Program Files (x86)\IBM\WebSphere MQ\bin\amqmdnet.dll"
Set oMqEnvironment = DotNetFactory.CreateInstance("IBM.WMQ.MQEnvironment",strMQMDllPath)
oMqEnvironment.Hostname = "host name"
oMqEnvironment.Port = "port number"
oMqEnvironment.Channel = "channel name"
Set oMQC = DotNetFactory.CreateInstance("IBM.WMQ.MQC",strMQMDllPath)
' qmanager name,channel name, connection name
Set oMqQMgr = DotNetFactory.CreateInstance("IBM.WMQ.MQQueueManager",strMQMDllPath,strQMgrName)
oMqQMgr.isConnected '给出 true
现在我想使用方法
public MQQueue AccessQueue(string queueName, int openOptions)
实例 IBM.WMQ.MQQueueManager。有人可以指导我做同样的事情,让我知道如何从上述队列中推送消息和读取消息
谢谢
经过大量谷歌搜索和阅读 IBM 文档后,我能够从 UFT 在 MQ 中放置和获取消息。 .. 下面是对我有用的代码片段.. 希望这对某些人有帮助.. 我正在分别处理 PUT 和 GET,因此代码中可能会有一些重复。
先决条件..您必须从 IBM 站点下载 MQ 客户端并将其安装在安装了 UFT 的 PC 上..IBM MQ 客户端是免费软件
Dim oMQEnvironment
Dim oMQM
Dim oMQC
Dim oMQMessage
Dim oMQQueue
Dim intOpenOptions
strMQMDLLPath = "C:\Program Files (x86)\IBM\WebSphere MQ\bin\amqmdnet.dll"
strHostName= "Host Name"
intPort = "Port Number"
strChannel ="Channel Name"
strMessage ="UFT Test Message"
strMQManager = "Quemanager Name"
strMessageQueue = "Queue Name"
' 这部分代码是公然从网上的post之一复制过来的。一旦我再次找到它,post link 会吗
'用于应用程序 (UFT) 以客户端模式连接到队列管理器
Set oMQEnvironment = DotNetFactory.CreateInstance("IBM.WMQ.MQEnvironment",strMQMDLLPath)
'Initize the Environment
With oMQEnvironment
.HostName = strHostName
.Port = intPort
.Channel = strChannel
End with
On Error Resume Next
'Create MQ Instatnces
Set oMQM = DotnetFactory.CreateInstance("IBM.WMQ.MQQueueManager",strMQMDLLPath)
'Check if MQM Connected
If Err.Number <> 0 Then
Reporter.ReportEvent micFail , "Step: Creating MQM Object" , "Unable to Connect to MQ Manager at" & strHostName
'Exit Test
End If
Set oMQC = DotnetFactory.CreateInstance("IBM.WMQ.MQC",strMQMDLLPath)
Set oMQMessage = DotnetFactory.CreateInstance("IBM.WMQ.MQMessage",strMQMDLLPath)
'Declare Q open options
intOpenOptions = oMQC.MQOO_OUTPUT or oMQC.MQOO_FAIL_IF_QUIESCING ' 16 + 8192
'Open the Q to post the messages
If strRemoteMQManager = "" Then
Set oMQQueue = oMQM.AccessQueue(strMessageQueue , intOpenOptions)
Else
Set oMQQueue = oMQM.AccessQueue(strMessageQueue , intOpenOptions ,strRemoteMQManager, "","" )
End If
'Format Message
With oMQMessage
.CharacterSet = 819
.WriteString(strMessage)
End with
'Post Message
With oMQQueue
.Put(oMQMessage)
.Close()
End With
现在从 MQ 获取消息
Dim oMQEnvironment
Dim oMQM
Dim oMQC
Dim oMQMessage
Dim oMQQueue
strMQMDLLPath = "C:\Program Files (x86)\IBM\WebSphere MQ\bin\amqmdnet.dll"
strHostName= "host name"
intPort = "port number"
strChannel ="channel name"
strMessage ="UFT Test Message"
strMessageQueue = "message queue intended to access"
strMQManager = "mq manager name"
strRemoteMQManager=""
'Create MQ Instances
Set oMQC = DotnetFactory.CreateInstance("IBM.WMQ.MQC",strMQMDLLPath)
'set the properties of the Queue manager
Set properties = DotNetFactory.CreateInstance("System.Collections.Hashtable")
properties.Add oMQC.HOST_NAME_PROPERTY, strHostName
properties.Add oMQC.PORT_PROPERTY, intPort
properties.Add oMQC.CHANNEL_PROPERTY, strChannel
'access the queue manager
Set oMQM = DotnetFactory.CreateInstance("IBM.WMQ.MQQueueManager",strMQMDLLPath,strMQManager,properties)
'here We are trying to browse the message one by one and keep the messages on the queue.
'Declare Q open options
Set oMQQueue = oMQM.AccessQueue(strMessageQueue,oMQC.MQOO_BROWSE)
Set oMQGetMessageOptions = DotNetFactory.CreateInstance("IBM.WMQ.MQGetMessageOptions",strMQMDLLPath)
oMQGetMessageOptions.Options = oMQC.MQGMO_BROWSE_FIRST
Set oMQMessage = DotnetFactory.CreateInstance("IBM.WMQ.MQMessage",strMQMDLLPath)
oMQQueue.Get oMQMessage,oMQGetMessageOptions
Set mqGetNextMsgOpts = DotNetFactory.CreateInstance("IBM.WMQ.MQGetMessageOptions",strMQMDLLPath)
mqGetNextMsgOpts.Options = oMQC.MQGMO_BROWSE_NEXT
browseMessages = true
Do while browseMessages
on error resume next
messageText = oMQMessage.ReadString(oMQMessage.MessageLength)
'Print messageText
Set oMQMessage = DotnetFactory.CreateInstance("IBM.WMQ.MQMessage",strMQMDLLPath)
oMQQueue.Get oMQMessage,mqGetNextMsgOpts
if Err.Number <> 0 then browseMessages =false
'Clear both MsgID and CorrelID for next use.
oMQMessage.MessageId = oMQC.MQMI_NONE
oMQMessage.CorrelationId = oMQC.MQCI_NONE
Loop
'Cleanup
Set oMQQueue = Nothing
Set oMQMessage= Nothing
Set oMQOpenOptions= Nothing
Set oMQM= Nothing
Set oMQEnvironment = Nothing