Trying to use IBM activeX (mqaz200.dll) to do request reply.
Request message work but I'm having a problem putting the reply message. get error MQRC_NOT_OPEN
Code:
Public Function MQReplyTest(ByVal astrQMgr As String, ByVal astrQName As String) As Integer
Dim objMsg As MQMessage '* message object for get
'Added the put message below
Dim objMsgPut As MQMessage
Dim objPutOptions As MQPutMessageOptions '* put message options
Dim objGetOptions As MQGetMessageOptions '* get message options
Dim objRequest As MQQueue
Dim objReply As MQQueue
On Error GoTo HandleError
'Initalize Return Code
MQReplyTest = -1
'*******************************************************************************
'* Connect to the MQQueueManager
'*******************************************************************************
If MQConnect(astrQMgr) = -1 Then Exit Function
'*******************************************************************************
'* Connect to the Local Queue
'*******************************************************************************
Set objRequest = mobjQMgr.AccessQueue(astrQName, MQOO_INPUT_SHARED + MQOO_FAIL_IF_QUIESCING)
'*******************************************************************************
'* Get a Request Message
'*******************************************************************************
Set objMsg = mobjSess.AccessMessage()
objMsg.MessageId = vbNullString
objMsg.CorrelationId = vbNullString
Set objGetOptions = mobjSess.AccessGetMessageOptions()
objGetOptions.Options = MQGMO_WAIT + MQGMO_CONVERT + MQGMO_NO_SYNCPOINT + MQGMO_FAIL_IF_QUIESCING
objGetOptions.WaitInterval = 5000
objRequest.Get objMsg, objGetOptions
MsgBox objMsg.MessageData
'*******************************************************************************
'* Verify the message received was a request
'*******************************************************************************
If objMsg.MessageType <> MQMT_REQUEST Then
mstrLastErr = "Message is not a request message!"
MsgBox "Not a reply message"
End If
'*******************************************************************************
'* Put Relpy Information
'*******************************************************************************
Set objReply = New MQQueue
objReply.Name = objMsg.ReplyToQueueName()
objReply.ConnectionReference = mobjQMgr
objReply.QueueManagerName = objMsg.ReplyToQueueManagerName()
objReply.OpenOptions = MQOO_OUTPUT
'*******************************************************************************
'* Format the Message
'*******************************************************************************
Set objMsgPut = mobjSess.AccessMessage()
objMsgPut.MessageType = MQMT_REPLY
objMsgPut.CorrelationIdHex = objMsg.MessageIdHex()
objMsgPut.MessageId = vbNullString
objMsgPut.MessageData = "<Reply>Reply Message</Reply>"
Set objPutOptions = mobjSess.AccessPutMessageOptions()
objPutOptions.Options = MQPMO_NO_SYNCPOINT
'objReply.Open
objReply.Put objMsgPut, objPutOptions
'Close queues
objRequest.Close
objReply.Close
'Disconnect
mobjQMgr.Disconnect
Set objRequest = Nothing
Set objReply = Nothing
Set mobjQMgr = Nothing
Set mobjSess = Nothing
Set objMsg = Nothing
Set objMsgPut = Nothing
Set objGetOptions = Nothing
Set objPutOptions = Nothing
MQReplyTest = 1
Exit Function
HandleError:
Call MQFormatErr
End Function
Request message work but I'm having a problem putting the reply message. get error MQRC_NOT_OPEN
Code:
Public Function MQReplyTest(ByVal astrQMgr As String, ByVal astrQName As String) As Integer
Dim objMsg As MQMessage '* message object for get
'Added the put message below
Dim objMsgPut As MQMessage
Dim objPutOptions As MQPutMessageOptions '* put message options
Dim objGetOptions As MQGetMessageOptions '* get message options
Dim objRequest As MQQueue
Dim objReply As MQQueue
On Error GoTo HandleError
'Initalize Return Code
MQReplyTest = -1
'*******************************************************************************
'* Connect to the MQQueueManager
'*******************************************************************************
If MQConnect(astrQMgr) = -1 Then Exit Function
'*******************************************************************************
'* Connect to the Local Queue
'*******************************************************************************
Set objRequest = mobjQMgr.AccessQueue(astrQName, MQOO_INPUT_SHARED + MQOO_FAIL_IF_QUIESCING)
'*******************************************************************************
'* Get a Request Message
'*******************************************************************************
Set objMsg = mobjSess.AccessMessage()
objMsg.MessageId = vbNullString
objMsg.CorrelationId = vbNullString
Set objGetOptions = mobjSess.AccessGetMessageOptions()
objGetOptions.Options = MQGMO_WAIT + MQGMO_CONVERT + MQGMO_NO_SYNCPOINT + MQGMO_FAIL_IF_QUIESCING
objGetOptions.WaitInterval = 5000
objRequest.Get objMsg, objGetOptions
MsgBox objMsg.MessageData
'*******************************************************************************
'* Verify the message received was a request
'*******************************************************************************
If objMsg.MessageType <> MQMT_REQUEST Then
mstrLastErr = "Message is not a request message!"
MsgBox "Not a reply message"
End If
'*******************************************************************************
'* Put Relpy Information
'*******************************************************************************
Set objReply = New MQQueue
objReply.Name = objMsg.ReplyToQueueName()
objReply.ConnectionReference = mobjQMgr
objReply.QueueManagerName = objMsg.ReplyToQueueManagerName()
objReply.OpenOptions = MQOO_OUTPUT
'*******************************************************************************
'* Format the Message
'*******************************************************************************
Set objMsgPut = mobjSess.AccessMessage()
objMsgPut.MessageType = MQMT_REPLY
objMsgPut.CorrelationIdHex = objMsg.MessageIdHex()
objMsgPut.MessageId = vbNullString
objMsgPut.MessageData = "<Reply>Reply Message</Reply>"
Set objPutOptions = mobjSess.AccessPutMessageOptions()
objPutOptions.Options = MQPMO_NO_SYNCPOINT
'objReply.Open
objReply.Put objMsgPut, objPutOptions
'Close queues
objRequest.Close
objReply.Close
'Disconnect
mobjQMgr.Disconnect
Set objRequest = Nothing
Set objReply = Nothing
Set mobjQMgr = Nothing
Set mobjSess = Nothing
Set objMsg = Nothing
Set objMsgPut = Nothing
Set objGetOptions = Nothing
Set objPutOptions = Nothing
MQReplyTest = 1
Exit Function
HandleError:
Call MQFormatErr
End Function