ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » VB.NET Get Message

Post new topic  Reply to topic Goto page 1, 2  Next
 VB.NET Get Message « View previous topic :: View next topic » 
Author Message
pannonej
PostPosted: Wed Oct 05, 2005 10:46 am    Post subject: VB.NET Get Message Reply with quote

Novice

Joined: 30 Sep 2005
Posts: 13

I am looking for VB.NET code to get an (XML) message from a Websphere MQ Queue. I have found plenty of great examples on this site to Put messages, but I need to GET a message.
_________________
-Joe Pannone
Back to top
View user's profile Send private message AIM Address MSN Messenger
klabran
PostPosted: Wed Oct 05, 2005 10:53 am    Post subject: Reply with quote

Master

Joined: 19 Feb 2004
Posts: 259
Location: Flagstaff AZ

Here's some code I use to get messages as a string...

Code:


    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
            MessageBox.Show("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
                    MessageBox.Show(mqMsg.ReadString(mqMsg.MessageLength))
                Else
                    MessageBox.Show("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
                    MessageBox.Show("no more messages")
                    isContinue = False
                Else
                    '* general report for other reasons
                    MessageBox.Show("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 to top
View user's profile Send private message Visit poster's website
pannonej
PostPosted: Wed Oct 05, 2005 12:24 pm    Post subject: VB.NET Get Message cont Reply with quote

Novice

Joined: 30 Sep 2005
Posts: 13

Thanks for the reply, I get a "Creation of MQQueueManager ended with MQRC_Q_MGR_NOT_AVAILABLE"
Can you give me an example of the 4 parameters needed for the function.
_________________
-Joe Pannone
Back to top
View user's profile Send private message AIM Address MSN Messenger
klabran
PostPosted: Wed Oct 05, 2005 2:30 pm    Post subject: Reply with quote

Master

Joined: 19 Feb 2004
Posts: 259
Location: Flagstaff AZ

QM= queue manager name like QM_PROD
QN = queue name like QL_TEST
Channel = Server Connection Channel or Client Connection channel name defined in your QM.
Conn = Connection name used by channel

with a channel defined like...

SERVERNAME/TCP/XXX.XX.XX.XXX(1415)

then Channel = SERVERNAME
Conn=XXX.XX.XX.XXX(1415)

make sure you have a server connection channel or a client connection channel defined in your QM.
Back to top
View user's profile Send private message Visit poster's website
PeterPotkay
PostPosted: Wed Oct 05, 2005 4:24 pm    Post subject: Reply with quote

Poobah

Joined: 15 May 2001
Posts: 7722

Joe, on your machine there is a PDF on Using MQ with .NET, and there are sample programs installed as well.
_________________
Peter Potkay
Keep Calm and MQ On
Back to top
View user's profile Send private message
pannonej
PostPosted: Thu Oct 06, 2005 12:06 pm    Post subject: Reply with quote

Novice

Joined: 30 Sep 2005
Posts: 13

Thanks but that PDf document only has C# examples. I need ASP.NET/VB.NET.
_________________
-Joe Pannone
Back to top
View user's profile Send private message AIM Address MSN Messenger
pannonej
PostPosted: Thu Oct 06, 2005 12:09 pm    Post subject: GET in VB.NET Reply with quote

Novice

Joined: 30 Sep 2005
Posts: 13

I cant get the code above to get the message. I do not need to create the queue manager, it is already there with messages waiting for me. I need to connect to the queue, open, read (get), close and disconnect. All in vb.net.
The message will be in XML.
Can anyone help?
_________________
-Joe Pannone
Back to top
View user's profile Send private message AIM Address MSN Messenger
PeterPotkay
PostPosted: Thu Oct 06, 2005 12:25 pm    Post subject: Reply with quote

Poobah

Joined: 15 May 2001
Posts: 7722

Post your code and let's see what the problem is.

Moderator, please move this post. Its not WB-IMB related.
_________________
Peter Potkay
Keep Calm and MQ On
Back to top
View user's profile Send private message
pannonej
PostPosted: Thu Oct 06, 2005 12:38 pm    Post subject: Reply with quote

Novice

Joined: 30 Sep 2005
Posts: 13

Its the code listed above in this thread
_________________
-Joe Pannone
Back to top
View user's profile Send private message AIM Address MSN Messenger
EddieA
PostPosted: Thu Oct 06, 2005 12:47 pm    Post subject: Reply with quote

Jedi

Joined: 28 Jun 2001
Posts: 2453
Location: Los Angeles

Quote:
Its the code listed above in this thread

No. klabran's code is posted above.

We're after your code that produces: "Creation of MQQueueManager ended with MQRC_Q_MGR_NOT_AVAILABLE". Together with details about what you are using for Queue Manager, Queue, Channel, Conn, etc.

Cheers,
_________________
Eddie Atherton
IBM Certified Solution Developer - WebSphere Message Broker V6.1
IBM Certified Solution Developer - WebSphere Message Broker V7.0
Back to top
View user's profile Send private message
hopsala
PostPosted: Thu Oct 06, 2005 1:06 pm    Post subject: Reply with quote

Guardian

Joined: 24 Sep 2004
Posts: 960

Masters, read before you post! pannonej is using the code klabran gave him, the same one posted here.

pannonej - The message MQRC_Q_MGR_NOT_AVAILABLE means that either the listener on your QM is down, or you are specifing the wrong client channel parameters. Don't take "can't create queue manager" so literally - it means that the class cannot be created (constructors and all), not the QM itself.

Did you try what klabran suggested? What are the parameters you gave? Do you even know what a client channel is? If you don't, i'm afraid you'll have to read the Clients manual, there's no going around it.
Back to top
View user's profile Send private message
klabran
PostPosted: Thu Oct 06, 2005 1:12 pm    Post subject: Reply with quote

Master

Joined: 19 Feb 2004
Posts: 259
Location: Flagstaff AZ

Quote:
I do not need to create the queue manager, it is already there with messages waiting for me.


Quote:

"Creation of MQQueueManager ended with MQRC_Q_MGR_NOT_AVAILABLE".


Joe, The above is not trying to create the QMgr. It is telling you that it can't connect to the QMGR.

My code snippet uses a client connection or server connection channel that is defined in your QMGR under the channels folder in the QMGR's admin gui.

If you are not matching this exactly then you will get this error.

Try and connect without VB.Net to test if you can connect...
Open up a command line on the client PC you are trying to run this from:

SET MQSERVER = <ChannelName>/TCP/<ConnectionName> <- has to match what is in the QMGR.

amqsgetc <QUEUENAME> <QMGRNAME>

<> -> Replace everything in the brackets with your environments info.

If this fails then it is likely you do not have the Connection information correct or created.

Also the code installed with the Client has samples in VB and C#. In fact the code snippet I sent is a modified version of one of the VB samples installed with the Client install.

You can also convert c# to VB.Net fairly easily. There are several websites who will take pasted in code and convert it to either language.
Here's one of them: http://www.kamalpatel.net/ConvertCSharp2VB.aspx

Kevin
Back to top
View user's profile Send private message Visit poster's website
pannonej
PostPosted: Thu Oct 06, 2005 3:39 pm    Post subject: Reply with quote

Novice

Joined: 30 Sep 2005
Posts: 13

To PUT a message I use the following code succesfully:

Public Function PutQueue(ByVal QM As String, ByVal QN As String, _
ByVal Msg As String, ByVal OpenOptions As Integer) As Integer

Dim mqQMgr As MQQueueManager '* MQQueueManager instance
Dim mqQueue As MQQueue '* MQQueue instance
Dim mqMsg As MQMessage '* MQMessage instance
Dim mqPutMsgOpts As MQPutMessageOptions '* MQPutMessageOptions instance
Dim msgLen As Integer '* Message length

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

'*
'* Try to open the queue
'*
Try
mqQueue = mqQMgr.AccessQueue(QN, OpenOptions) '* open queue for input but not if MQM stopping
Catch mqe As MQException
'* stop if failed
Console.WriteLine("MQQueueManager::AccessQueue ended with {0}", mqe.Message)
Return (mqe.Reason)
End Try
'*
'* Put to the message queue
'*
msgLen = Msg.Length

If (msgLen > 0) Then
Try
'* put the next message to the queue
mqMsg = New MQMessage
'03/21/2004 Begin
mqMsg.CharacterSet = 437 'ascii - default is 1200 which is unicode.
'03/21/2004 End
mqMsg.ReplyToQueueManagerName = "QM_CC_P1"
'mqMsg.ReplyToQueueName = "MYREPLY"
mqMsg.Format = MQC.MQFMT_STRING
mqMsg.WriteString(Msg)
mqQueue.Put(mqMsg) ', mqPutMsgOpts)
Catch mqe As MQException
'* report the error
Console.WriteLine("MQQueue::Put ended with {0}", mqe.Message)
Return (mqe.Reason)
End Try
End If

Return (0)
End Function

I pass the following in a button click:
Dim putretval

Dim strQM = "UTQM"
Dim strQ = "TDXR1.TESTQ"
Dim strLine = "Hello from Forza at 2:20pm"

PutRetVal = PutQueue(strQM, strQ, strLine, IBM.WMQ.MQC.MQOO_OUTPUT + IBM.WMQ.MQC.MQOO_SET_ALL_CONTEXT + IBM.WMQ.MQC.MQOO_FAIL_IF_QUIESCING)
_________________
-Joe Pannone
Back to top
View user's profile Send private message AIM Address MSN Messenger
pannonej
PostPosted: Thu Oct 06, 2005 3:51 pm    Post subject: Reply with quote

Novice

Joined: 30 Sep 2005
Posts: 13

From the connected server I can use the following command successfully:
amqsputc TDXR1.TESTQ UTQM
I am able to type in a string, and exit when I hit enter twice.

I then can type the following to retrieve the messages:
amqsgetc TDXR1.TESTQ UTQM

I tried converting the c# code in a few of those transalation sites, but still came up with errors.
_________________
-Joe Pannone
Back to top
View user's profile Send private message AIM Address MSN Messenger
EddieA
PostPosted: Fri Oct 07, 2005 8:14 am    Post subject: Reply with quote

Jedi

Joined: 28 Jun 2001
Posts: 2453
Location: Los Angeles

Quote:
Masters, read before you post! pannonej is using the code klabran gave him, the same one posted here.

OK, I agree, I worded that badly. The provided code needed parameters passed to it, which is what I was really asking be provided. Plus, it's not a bad idea to make sure that someone hasn't changed the provided code before using it.
Quote:
mqQMgr = New MQQueueManager(QM)

For the PUT, you are making a bindings connection.
Quote:
amqsputc TDXR1.TESTQ UTQM
amqsgetc TDXR1.TESTQ UTQM

Here, you are using a Client connection.

Which type are you trying to use in you GET code. The code provided earier was Client code, that needed the values from your MQSERVER environemt passed to it.

Cheers,
_________________
Eddie Atherton
IBM Certified Solution Developer - WebSphere Message Broker V6.1
IBM Certified Solution Developer - WebSphere Message Broker V7.0
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Goto page 1, 2  Next Page 1 of 2

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » VB.NET Get Message
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.