2016-09-13 148 views
2

我一直在嘗試從UFT讀取和寫入消息到MQ。我正在使用dotnet工廠實例。我已經達到了能夠連接到MQ的程度,而我在訪問隊列和讀取和寫入消息時遇到問題。從UFT連接到IBM 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的

。有人可以指導我在做同樣的,讓我知道我可以從所提到的隊列將消息傳遞和閱讀郵件

謝謝

回答

2

很多google搜索和閱讀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" 

'的這部分代碼是公然從其中一個帖子在線複製。將發佈的鏈接,一旦我再次

「找到它的應用程序(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 
收到消息