How to call MSMQ from Powerbuilder

I am working on a legacy App written in PB 6.5. A new requirement is that the App sends messages to MSMQ (Microsoft Messaging Queue). Does anybody know how to do it? ..  or could someone point me to a site/document where it is shown/explained?
Any help very appreciated!
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi Byteman

check out this example link will help u or not....,0

BytemanAuthor Commented:
Thanks Gaforr .. it gave me a general ideia about what things to do .. but I need more specific Info about how to do it in PB.

I read somewhere that MSMQ COM+ object(s) could be used.
Where can I find info/documentation about them? I tried the Microsoft site and I only found references to them not actual documentation nor examples.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Some part from MSDN Library

    Let's start out by examining the code required to send a message that represents a sales order. MSMQ makes this task remarkably easy. You start by using an MSMQQueueInfo object to open an MSMQQueue object for send access. Next, create a new MSMQMessage object and prepare it by setting a few properties. You can then invoke the MSMQMessage object's Send method and MSMQ will route your message to its destination queue. Here's a simple example:
Dim QI As MSMQQueueInfo, RequestQueue As MSMQQueue
 Set QI = New MSMQQueueInfo
 QI.PathName = "MyServerComputer\MyQueue"
 Set RequestQueue = QI.Open(MQ_SEND_ACCESS, _
 Dim msg As MSMQMessage
 Set msg = New MSMQMessage
 msg.Label = "Sales order #1001"
 msg.Body = "Customer=Bob;Product=PetRock;Quantity=120"
 msg.Send RequestQueue
This code creates a sender application. The sender is typically a client application that wants to run a transaction or retrieve a requested set of data. To complement a client-side sender application, you typically create a server-side listener application. A listener application monitors a queue for incoming messages. It's the responsibility of the listener application to receive and process messages when they arrive at the queue.

    To receive a message in a listener application, you first open an MSMQQueue object with receive access, and then you invoke the Receive method to read and remove the first message in the queue:
Dim QI As MSMQQueueInfo, RequestQueue As MSMQQueue
 Set QI = New MSMQQueueInfo
 QI.PathName = "MyServerComputer\MyQueue"
 Set RequestQueue = QI.Open(MQ_RECEIVE_ACCESS, _
 Dim msg As MSMQMessage
 ' Attempt to receive first message in queue.
 Set msg = RequestQueue.Receive(ReceiveTimeout:=1000)
 If Not (msg Is Nothing) Then
   ' You have removed the first message from the queue.
   ' now process the message
   ' you timed out on an empty queue
 End If
Receiving Messages with MSMQ Events

    Earlier, I demonstrated a technique for synchronously receiving messages from a queue. This is an easy way to read and remove all the messages that are currently in a queue. It also lets you process future messages as they arrive at the destination queue. While this style of coding allows you to process messages as they arrive, it also holds the calling thread hostage. If you have a single-threaded application, the application can't do anything else.

    You can use MSMQ events as an alternative to this synchronous style of message processing. MSMQ events let your application respond to asynchronous notifications that are raised by MSMQ as messages arrive at a queue. You can therefore respond to a new message without having to dedicate a thread to block on a call to Receive.

    Let's look at how MSMQ events work. The MSMQ event mechanism is based on the MSMQEvent component. To use events, you must first create an MSMQEvent object and set up an event sink. Next, you must associate the MSMQEvent object with an MSMQQueue object that has been opened with receive access. You create the association between the two objects by invoking the EnableNotification method on the MSMQQueue object and passing a reference to the MSMQEvent object. After you call EnableNotification, MSMQ notifies your application when a message has arrived by raising an Arrived event.

    To create an event sink, you must use the Visual Basic WithEvents keyword and declare the source object's reference variable in the declaration section of a form or class module. The following code shows how to set up an event sink for a new MSMQEvent object in a form module of a standard EXE project:
Private RequestQueue As MSMQQueue
 Private WithEvents RequestEvent As MSMQEvent
 Private Sub Form_Load()
   Dim QI As MSMQQueueInfo
   Set QI = New MSMQQueueInfo
   QI.PathName = "MyServerComputer\MyQueue"
   Set RequestQueue = QI.Open(MQ_RECEIVE_ACCESS, _
   Set RequestEvent = New MSMQEvent
   RequestQueue.EnableNotification RequestEvent
 End Sub

    Once you set up the MSMQEvent object's event sink and call EnableNotification, you will be notified with an Arrived event as soon as MSMQ finds a message in the queue. Here, an implementation of the Arrived event processes messages as they arrive in the queue:
Sub RequestEvent_Arrived(ByVal Queue As Object, _
                          ByVal Cursor As Long)
   Dim RequestQueue As MSMQQueue
   ' cast to MSMQQueue to avoid late binding  
   Set RequestQueue = Queue
   Dim msg As MSMQMessage
   Set msg = RequestQueue.Receive(ReceiveTimeOut:=0)
   If Not (msg Is Nothing) Then
     ' process message when it arrives
   End If
   RequestQueue.EnableNotification RequestEvent
 End Sub

I don't know any of the above will help u !.
i think it will be gud if u r getting bit more info about it

BytemanAuthor Commented:
although it wasn't quite was I was looking for it helped me a lot.

In PB the approach different.

Thanks again!

You might be able to find the MQ client and MQ active X on this site, there is a lot of stuff there so it may take a bit of searching:

Once you have the client and active x installed you can use the following to read and write to MQ.

oleobject iole_MQSession, iole_QM

// create MQ session ole object
iole_MQSession = CREATE oleobject
ls_object = "MQAX200.MQsession"

// connect MQ session
li_ret = iole_MQSession.ConnectToNewObject(ls_object)
if li_ret <> 0 then
      MessageBox("Error","Cannot connect")
      return li_ret
end if

// Create and setup Q Manager object
iole_QM = iole_MQSession.AccessQueueManager("Q Manager Name")

// get Q Manager description
ls_description = iole_QM.Description

// get Q Manager dead message Q name
ls_DeadQ = iole_QM.DeadLetterQueueName


Once you get the Active X you'll be able to see the functions and attributes available.  I think there is a pdf that comes with the Active X describing functions to open a Q, put to a Q, get from a Q, open and close a Q, etc.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.