我一直在尝试从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'给出了真实的
现在我想使用方法
public MQQueue AccessQueue(string queueName, int openOptions)
实例IBM.WMQ.MQQueueManager的。有人可以指导我做同样的事情,让我知道如何推送消息和阅读上述队列中的消息
谢谢
答案 0 :(得分:2)
经过大量的谷歌搜索和阅读IBM文档后,我能够从UFT中放入和获取MQ中的消息。 ..下面的代码片段对我有用..希望这有助于一些..我正在分别处理PUT和GET,因此代码中可能会有一些重复。
此先决条件..您必须从IBM站点下载MQ Client并将其安装在安装了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"
'这部分代码是从网上其中一个帖子中公然复制的。一旦我再次找到它就会发布链接
'用于应用程序(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