Managing Queues on Windows 2000

< BACK  NEXT >
[oR]

Computer Management can be used to inspect queues on Windows 2000, as well as to create new queues and look at queued messages. To run Computer Management the following steps are required:

  • Select the Start+Settings+Control Panel menu command.

  • Double-click the "Administrative Tools" icon.

  • Double-click the "Computer Manager" icon.

  • Expand the "Services and Applications" and then the "Message Queuing" entries in the Tree.

Message queuing (Figure 15.1) allows four types of queue to be managed:

Figure 15.1. Managing queues using Computer Management
graphics/15fig01.gif
  • Outgoing queues. This is where messages waiting to be delivered to queues on other computers are stored.

  • Public queues. The location of public message queues is resolved using Active Directory. Windows CE or a Message Queue Workgroup installation on Windows 2000 does not support public queues.

  • Private queues. Private message queues are accessed using the DNS name and are used by Windows CE. Figure 15.1 shows a queue that has been created called wincequeue.

  • System queues. Journal queues are used for logging messages. The dead-letter queue receives messages that cannot be delivered.

Creating a Private Queue

Private queues can be created programmatically or, more easily, can be created using Computer Management.

  • Right-click "Private Queues" in Computer Management and select New+ Private Queue. This displays the "Queue Name" dialog.

  • Enter the name of the new queue (such as "wincequeue" from Figure 15.1) and click OK. You have the option to create a transactional queue, described later in this chapter.

Once a private queue has been created, it can be accessed by applications running on any computer that has the appropriate security access.

The code in the next sections shows how to read messages from a queue created on a Windows 2000 computer using Visual Basic and how to write messages to the queue from a Windows CE device using C++ (Figure 15.2).

Figure 15.2. Reading and writing a queue
graphics/15fig02.gif

Reading Messages from a Queue in Windows 2000

The Computer Manager does not allow messages to be added to or read from a queue you must write code to do this. You will find a Visual Basic project in the directory \QueueServer on the CDROM containing the code described in this chapter. On Windows 2000 Visual Basic can be used with the Microsoft Message Queue object model:

  • Run Visual Basic, and create a new project.

  • Select the Project+References menu command. In the "Available References" list, add a check against "Microsoft Message Queue 2.0 Object Library."

The code in the "QueueServer" application opens a private queue when the form is loaded. The form has a timer control that fires an event every two seconds, and this checks to see if a new message has arrived in the queue. In the next section you will find code that runs on a Windows CE device that adds messages to this queue. Finally, the queue is closed when the form unloads:

 Private qi As MSMQQueueInfo Private q As MSMQQueuePrivate Sub Form_Load()   Set qi = New MSMQQueueInfo   qi.PathName = ".\Private$\WinCEQueue"   Set q = qi.Open(MQ_RECEIVE_ACCESS, MQ_DENY_NONE) End Sub Private Sub Form_Unload(Cancel As Integer)   q.Close End Sub Private Sub tmrMessage_Timer()   Dim msg As MSMQMessage   Dim s As String   Dim sTime As String   Dim sLabel As String   Dim sBody As String   Dim sSent As String   ' check for message   Set msg = q.Receive(ReceiveTimeout:=0)   If (Not (msg Is Nothing)) Then     ' have got a message     sTime = msg.ArrivedTime     sLabel = msg.Label     sBody = msg.Body     sSent = msg.SentTime     s = s & "Sent:" & sSent & _       " Arrived: " & sTime & ":" & _       sLabel & vbCrLf & sBody & vbCrLf     txtMessageLog.Text = s + txtMessageLog.Text   End If End Sub 

Three Message Queue objects are used in this code:

  • MSMQQueueInfo Access information about an existing queue, create a new queue, or open an existing queue.

  • MSMQQueue Represents an open queue and allows messages to be added to the queue or read from the queue.

  • MSMQMessage Represents a single message to be added to the queue or read from the queue.

The queue name is specified using the "PathName" property. In this case a private queue called "WinCEQueue" on the local machine (indicated by ".") is specified. The queue is opened using the "Open" method. This then is passed information about how the queue is to be accessed (MQ_RECEIVE_ACCESS indicates that messages are to be read from the queue) and queue-sharing options (MQ_DENY_NONE means that other applications can open the queue for reading and writing while this application has the queue open).

The Receive method is called on an open queue in the timer event and checks to see if a message has arrived. This method is passed a single optional ReceiveTimeout parameter that specifies how long to wait before timing out. In this case the value 0 specifies no timeout value, so the call will return immediately if no message is waiting. This, together with the use of a timer, ensures that the Visual Basic application is not blocked waiting for messages. If a message is waiting, a MSMQMessage object is returned.

The MSMQMessage object is used to access the message's label, body, time sent, and time received, and this information is added to a text box. In the next section some Windows CE code will be demonstrated that will write a message to the queue used by this Visual Basic application.


< BACK  NEXT >


Windows CE 3. 0 Application Programming
Windows CE 3.0: Application Programming (Prentice Hall Series on Microsoft Technologies)
ISBN: 0130255920
EAN: 2147483647
Year: 2002
Pages: 181

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net