Visual Basic
  Home arrow Visual Basic arrow Page 4 - MSMQ Part 1/2: Architecture and Simple Imp...
Iron Speed
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Download TestComplete 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
IBM Rational Software Development Conference
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
VISUAL BASIC

MSMQ Part 1/2: Architecture and Simple Implementation Using VB
By: Liviu Tudor
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 96
    2002-03-19

    Table of Contents:
  • MSMQ Part 1/2: Architecture and Simple Implementation Using VB
  • MSMQ Architecture
  • Hello world with MSMQ
  • Creating, looking up and deleting queues
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    Iron Speed
     
    ADVERTISEMENT

    Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    MSMQ Part 1/2: Architecture and Simple Implementation Using VB - Creating, looking up and deleting queues
    (Page 4 of 5 )

    In our example we've seen a quick way of locating, opening and creating a queue. On this page we will take a closer look at how to locate a queue using more than just PathName and an MSMQQueue object.

    FormatName Property

    If you look in MSDN under the MSMQQueueInfo object property, you will notice a property called FormatName. The "name" bit at the end of this property suggests that it might be somehow related to the PathName, and that's not far from the truth.

    Using the FormatName property, we can access a certain queue more or less in the same way that we did with the PathName property. The difference is (apart from the format) that by using this approach, a client can provide disconnected messaging (i.e. not reliant on a SC).

    The format of this property is as follows:

    QueueInfo.FormatName = "DIRECT=Protocol:Address\Queue"

    QueueInfo.FormatName = "DIRECT=OS:ComputerName\Queue"

    QueueInfo.FormatName = "PUBLIC=QueueGUID"

    QueueInfo.FormatName = "PRIVATE=ComputerGUID\Queue"


    Where the first part denotes the way the communication is achieved: PUBLIC (locating the queue via a SC), PRIVATE (locating a private queue), or DIRECT (bypass the SC – this is normally used for disconnected messaging, when we don't have access to the SC).

    Protocol determines the protocol to be used for locating the machine holding the queue. Possible values are SPX, TCP or whatever other protocols are supported by MSMQ. In most of the cases the value will be TCP, because this is the standard protocol in an enterprise network. Queue is the queue name (if we considered our previous example, Queue would be "Greeting").

    To get an idea of how queues are opened, we can use the following code to inspect the FormatName property:

    Private Sub TestFormatName()

    Dim qinfo As MSMQQueueInfo

    Dim q As MSMQQueue

    Set qinfo = New MSMQQueueInfo

    qinfo.PathName = ".\PRIVATE$\Greeting2"

    qinfo.Label = "Second Greeting Queue"

    qinfo.Create

    MsgBox "Queue format name is: " + qinfo.FormatName

    Set q = qinfo.Open(MQ_SEND_ACCESS, MQ_DENY_NONE)

    End Sub


    Of course, you will have to replace the PathName with whatever path you're using to store your message in (in this case we are creating a private queue on the local machine, but the queue could be public and created on any server in your enterprise).

    Deleting a queue

    Deleting a queue is just as simple as creating one, and I won't go into to much detail about it. The only thing we have to do once we have located our queue is call the delete method of an MSMQQueueInfo object.

    Here's a quick example on how to delete all queues called "Greeting".

    Dim query As New MSMQQuery

    Dim qinfos As MSMQQueueInfos

    Dim qinfo As MSMQQueueInfo

    Private Sub DelQ()

    Set qinfos = query.LookupQueue(Label:="Greeting")

    qinfos.Reset

    Set qinfo = qinfos.Next

    While Not qinfo Is Nothing

    qinfo.Delete

    Set qinfo = qinfos.Next

    Wend

    End Sub


    As you may have noticed, we are using two new object types here: MSMQQuery and MSMQQueueInfos. Briefly, MSMQQuery allows us to query for queues. It has one single method called LookupQueue, which allows us to query the active directory for existing public queues. This method returns an MSMQQueueInfos object, which is basically a list of MSMQQueueInfo objects. If we reconsider the relationship diagram presented earlier on, here's what it looks like:

    The extended MSMQ relationship diagram

    Locating a queue by name

    As we’ve just seen on the last page, we have already discovered another way of locating a queue – by using the MSMQQuery object and calling its LookupQueue method. This method returns an MSMQQueueInfos object, which is a collection of MSMQQueueInfo objects. The syntax of the function includes quite a few parameters, however the most interesting (and most used) one is label, which allows us to specify the name of the queue we're after.

    Furthermore, another very interesting parameter is the one called RelLabel, which allows us to define a relationship between the value we pass as the parameter Label and the actual label of the queue (i.e. equal, not equal, greater than etc.) The possible values for this parameter are:

    REL_EQ Equal

    REL_NEQ Not equal

    REL_LT Less than

    REL_GT Greater than

    REL_GE Greater than or equal

    REL_LE Less than or equal

    For example, to retrieve all of the queues not labelled "Greeting", we could use the following piece of code:

    Dim Qs As MSMQQueueInfos

    Dim MQ As New MSMQQuery

    Set Qs = MQ.LookupQueue( Label:="Greeting", RelLabel:=REL_NEQ)


    Once we get hold of the MSMQQueueInfos object, we can iterate through its items using the Next method, as seen on the previous page. However, remember before starting to iterate through an MSMQQueueInfos object, we must call its reset method to reset the position of the pointer right back to the beginning of the list.

    So, getting back to our receiver example, here's another way to locate a queue called "Greeting":

    Dim MQ As New MSMQQuery

    Dim QS As MSMQQueryInfos

    Dim QI As MSMQQueryInfo

    Dim Q As MSMQQueue

    Set QS = MQ.LookupQueue( Label:="Greeting") 'default relation is REL_EQ

    QS.Reset

    Set QI = QS.Next

    Set Q = QI.Open( MQ_RECEIVE_ACCESS, MQ_DENY_NONE )

    More Visual Basic Articles
    More By Liviu Tudor


     

    VISUAL BASIC ARTICLES

    - Developing an XML Web Service Using Visual S...
    - Creating an HTML File List with VB
    - Fun with Email: VB6, CDO, MAPI, and a Remote...
    - Extranet/Intranet Dictionary Cracker in VB
    - Finding Default App Icons With Visual Basic
    - Registry Fever With Visual Basic
    - Implementing An ADO Data Control With VB6
    - Printing With Visual Basic
    - MSMQ Part 1/2: Architecture and Simple Imple...
    - Magnifying The Desktop With Visual Basic
    - Sending Email With MAPI Components in Visual...
    - Two Person Chat With The Winsock Control And...
    - A Real-Time ActiveX News Control
    - Accessing the Windows API in Visual Basic






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway