Send
MSMQMessage

The Send method sends a message to the specified queue.

Syntax

object.Send (DestinationQueue, [pTransaction])
 
Syntax Element Description
object Message to be sent.
DestinationQueue Reference to destination queue object.
pTransaction Optional. An MSMQTransaction object or one of the following constants.

Constants include:

MQ_NO_TRANSACTION: Specifies that the call is not part of a transaction.

MQ_MTS_TRANSACTION: Default. Specifies that the call is part of the current MTS (Microsoft Transaction Server) transaction.

MQ_SINGLE_MESSAGE: Sends a single message as a transaction.

MQ_XA_TRANSACTION: Specifies that the call is part of an externally coordinated, XA-compliant transaction.


Remarks

To get the handle of a queue, use the Handle property of the queue.

To save a copy of the message in a machine journal, set Journal to MQMSG_JOURNAL. For information on machine journals, see Journal Queues.

Messages that do not reach their destination can be sent to a dead letter queue by setting the messages Journal property to MQMSG_DEADLETTER (transaction messages are automatically sent to the transaction dead letter queue if the transaction is not successful). For information on dead letter queues, see Dead Letter Queues.

The pTransaction parameter can be set to an MSMQTransaction object, or one of the constants described above. For information on the different types of transactions the MSMQ supports, see:

Example

This example sends a message to a queue that it creates. To try this example using Microsoft Visual Basic (version 5.0), paste the code into the Code window of a form, and then run the example and click the form.

Dim qinfo As MSMQQueueInfo
Dim q As MSMQQueue
Dim msg As New MSMQMessage

Private Sub Form_Click()
   '**************
   ' Create queue.
   '**************
  Set qinfo = New MSMQQueueInfo
  qinfo.PathName = ".\SendTest"
  qinfo.Label = "Test Queue"
  qinfo.Create
   '**************
   ' Open queue.
   '**************
  Set q = qinfo.Open(MQ_SEND_ACCESS, MQ_DENY_NONE)
   '**************
   ' Send Message.
   '**************
  msg.Label = "Test Message"
  msg.Body = "This is a test message with a string Body."
  msg.Send q
 
 
 q.Close

End Sub
 

See Also

Body, Close, Create, Label, MSMQMessage, MSMQQueue, MSMQQueueInfo, Open, PathName


© 1997 by Microsoft Corporation. All rights reserved.