VB.NET with Webshere MQSERIES

  • Thread starter Thread starter joe
  • Start date Start date
J

joe

I am looking for VB.NET code to GET a message from the IBM Websphere MQ
Queue. more specifically get an XML message. I have code to PUT a
message:


Public Function GetQueue(ByVal QM As String, ByVal QN As String,
ByVal Channel As String, ByVal Conn As String) As Integer

Dim mqQMgr As MQQueueManager '* MQQueueManager
instance
Dim mqQueue As MQQueue '* MQQueue instance
Dim queueName As String '* Name of queue to use


'*
'* Try to create an MQQueueManager instance
'*
Try
'* queue name, queue manager name provided
mqQMgr = New MQQueueManager(QM, Channel, Conn)
Catch mqe As MQException
'* stop if failed
TextBox1.Text = "Creation of MQQueueManager ended with " &
mqe.Message
Return (mqe.Reason)
End Try

'*
'* Try to open the queue
'*
Try
mqQueue = mqQMgr.AccessQueue(QN, MQC.MQOO_INPUT_AS_Q_DEF +
MQC.MQOO_FAIL_IF_QUIESCING) '* open queue for input but not if MQM
stopping
Catch mqe As MQException
'* stop if failed

Console.WriteLine(String.Format("MQQueueManager::AccessQueue ended with
{0}", mqe.Message))
Return (mqe.Reason)
End Try

'*
'* Get messages from the message queue
'* Loop until there is a failure
'*
Dim isContinue As Boolean = True
Do While (isContinue = True)
Dim mqMsg As MQMessage '* MQMessage
instance
Dim mqGetMsgOpts As MQGetMessageOptions '*
MQGetMessageOptions instance

mqMsg = New MQMessage
mqGetMsgOpts = New MQGetMessageOptions
mqGetMsgOpts.WaitInterval = 15000 '* 15 second limit for
waiting
Try
mqQueue.Get(mqMsg, mqGetMsgOpts)
If (mqMsg.Format.CompareTo(MQC.MQFMT_STRING) = 0) Then
TextBox1.Text =
mqMsg.ReadString(mqMsg.MessageLength)
Else
TextBox1.Text = "Non-text message"
End If
Catch mqe As MQException
'* report reason, if any
If (mqe.Reason = MQC.MQRC_NO_MSG_AVAILABLE) Then
'* special report for normal end
TextBox1.Text = "no more messages"
isContinue = False
Else
'* general report for other reasons
TextBox1.Text = "MQQueue::Get ended with {0}" &
mqe.Message

'* treat truncated message as a failure for this
sample
If (mqe.Reason = MQC.MQRC_TRUNCATED_MSG_FAILED)
Then
isContinue = False
End If
End If
End Try
Loop

Return (0)

End Function
 
Back
Top