Solved

How to call MSMQ from Powerbuilder

Posted on 2003-11-04
9
1,610 Views
Last Modified: 2013-12-26
Hi,
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!
0
Comment
Question by:Byteman
  • 4
  • 2
9 Comments
 
LVL 5

Expert Comment

by:gafoor78
ID: 9683630
Hi Byteman

check out this vb.net example link will help u or not....

http://www.aspfree.com/print/1203,0


rgrds
gafoor
0
 

Author Comment

by:Byteman
ID: 9686641
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.

THX!
0
 
LVL 5

Accepted Solution

by:
gafoor78 earned 500 total points
ID: 9687747
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 5

Expert Comment

by:gafoor78
ID: 9687786
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, _
                            MQ_DENY_NONE)
 Dim msg As MSMQMessage
 Set msg = New MSMQMessage
 msg.Label = "Sales order #1001"
 msg.Body = "Customer=Bob;Product=PetRock;Quantity=120"
 msg.Send RequestQueue
 q.Close
 
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, _
                            MQ_DENY_NONE)
 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
 Else
   ' you timed out on an empty queue
 End If
 q.close
 
0
 
LVL 5

Expert Comment

by:gafoor78
ID: 9687801
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, _
                              MQ_DENY_NONE)
   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

rgrds
gafoor
0
 

Author Comment

by:Byteman
ID: 9689345
Gafoor,
although it wasn't quite was I was looking for it helped me a lot.

In PB the approach different.

Thanks again!
0
 

Expert Comment

by:FatFigaro
ID: 9782023
Byteman,

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:
http://www-3.ibm.com/software/integration/support/supportpacs/

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.

-FatFigaro
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now