Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Request/Reply in VB

Status
Not open for further replies.

rjohnso

Programmer
Aug 16, 2001
1
US
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 = &quot;Message is not a request message!&quot;
MsgBox &quot;Not a reply message&quot;
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 = &quot;<Reply>Reply Message</Reply>&quot;

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

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top