다음을 통해 공유


MessageQueue.Send 메서드

정의

개체를 큐에 보냅니다.

오버로드

Name Description
Send(Object)

이 개체가 참조하는 트랜잭션이 아닌 큐에 개체를 MessageQueue보냅니다.

Send(Object, MessageQueueTransaction)

에서 참조하는 트랜잭션 큐에 개체를 MessageQueue보냅니다.

Send(Object, MessageQueueTransactionType)

에서 참조하는 큐에 개체를 MessageQueue보냅니다.

Send(Object, String)

개체를 이 항목에서 참조하는 트랜잭션이 아닌 큐로 MessageQueue 보내고 메시지의 레이블을 지정합니다.

Send(Object, String, MessageQueueTransaction)

이 항목에서 참조하는 트랜잭션 큐에 MessageQueue 개체를 보내고 메시지의 레이블을 지정합니다.

Send(Object, String, MessageQueueTransactionType)

이 개체가 참조하는 큐에 MessageQueue 개체를 보내고 메시지의 레이블을 지정합니다.

Send(Object)

이 개체가 참조하는 트랜잭션이 아닌 큐에 개체를 MessageQueue보냅니다.

public:
 void Send(System::Object ^ obj);
public void Send(object obj);
member this.Send : obj -> unit
Public Sub Send (obj As Object)

매개 변수

obj
Object

큐에 보낼 개체입니다.

예외

속성이 Path 설정되지 않았습니다.

-또는-

메시지 큐 메서드에 액세스할 때 오류가 발생했습니다.

예제

다음 코드 예제에서는 메시지 큐에 연결 하 고 큐에 메시지를 보냅니다.

#using <system.dll>
#using <system.messaging.dll.>

using namespace System;
using namespace System::Messaging;
ref class MyNewQueue
{
public:
   void SendMessage()
   {
      
      // Connect to a queue on the local computer.
      MessageQueue^ myQueue = gcnew MessageQueue( ".\\myQueue" );
      
      // Send a message to the queue.
      if ( myQueue->Transactional )
      {
         
         // Create a transaction.
         MessageQueueTransaction^ myTransaction = gcnew MessageQueueTransaction;
         
         // Begin the transaction.
         myTransaction->Begin();
         
         // Send the message.
         myQueue->Send( "My Message Data.", myTransaction );
         
         // Commit the transaction.
         myTransaction->Commit();
      }
      else
      {
         myQueue->Send( "My Message Data." );
      }

      return;
   }

};

int main()
{
   
   // Create a new instance of the class.
   MyNewQueue^ myNewQueue = gcnew MyNewQueue;
   
   // Send a message to a queue.
   myNewQueue->SendMessage();
   return 0;
}
using System;
using System.Messaging;

namespace MyProject
{

    /// <summary>
    /// Provides a container class for the example.
    /// </summary>
    public class MyNewQueue
    {

        //**************************************************
        // Provides an entry point into the application.
        //
        // This example sends a message to a queue.
        //**************************************************

        public static void Main()
        {
            // Create a new instance of the class.
            MyNewQueue myNewQueue = new MyNewQueue();

            // Send a message to a queue.
            myNewQueue.SendMessage();

            return;
        }

        //**************************************************
        // Sends a message to a queue.
        //**************************************************
        
        public void SendMessage()
        {
                        
            // Connect to a queue on the local computer.
            MessageQueue myQueue = new MessageQueue(".\\myQueue");

            // Send a message to the queue.
            if (myQueue.Transactional)
            {
                // Create a transaction.
                MessageQueueTransaction myTransaction = new
                    MessageQueueTransaction();

                // Begin the transaction.
                myTransaction.Begin();

                // Send the message.
                myQueue.Send("My Message Data.", myTransaction);

                // Commit the transaction.
                myTransaction.Commit();
            }
            else
            {
                myQueue.Send("My Message Data.");
            }

            return;
        }
    }
}
Imports System.Messaging

Public Class MyNewQueue


        '
        ' Provides an entry point into the application.
        ' 
        ' This example sends a message to a queue.
        '

        Public Shared Sub Main()

            ' Create a new instance of the class.
            Dim myNewQueue As New MyNewQueue

            ' Send a message to a queue.
            myNewQueue.SendMessage()

            Return

        End Sub


        '
        ' Sends a message to a queue.
        '

        Public Sub SendMessage()

            ' Connect to a queue on the local computer.
            Dim myQueue As New MessageQueue(".\myQueue")

            ' Send a message to the queue.
            If myQueue.Transactional = True Then

                ' Create a transaction.
                Dim myTransaction As New MessageQueueTransaction

                ' Begin the transaction.
                myTransaction.Begin()

                ' Send the message.
                myQueue.Send("My Message Data.", myTransaction)

                ' Commit the transaction.
                myTransaction.Commit()

            Else
                myQueue.Send("My Message Data.")
            End If

            Return

        End Sub

End Class

다음 코드 예제에서는 애플리케이션 정의 Order 클래스를 큐에 보낸 다음 해당 큐에서 메시지를 받습니다.

설명

이 오버로드를 사용하여 매개 변수가 포함된 obj 메시지를 .에서 참조하는 큐로 MessageQueue보냅니다. 큐에 보내는 개체는 관리되는 개체이거나 관리되는 개체일 Message 수 있습니다. 다른 개체를 Message보내면 개체가 직렬화되어 메시지 본문에 삽입됩니다.

이 오버로드를 사용하여 트랜잭션 큐에 메시지를 보내는 경우 메시지는 배달 못 한 편지 큐로 전송됩니다. 메시지가 다른 메시지를 포함하는 트랜잭션의 일부가 되도록 하려면 매개 변수를 사용하거나 MessageQueueTransactionType 매개 변수로 사용하는 MessageQueueTransaction 오버로드를 사용합니다.

호출Send(Object)하기 전에 속성을 설정 Formatter 하지 않으면 포맷터가 기본값으로 XmlMessageFormatter지정됩니다.

이 속성은 DefaultPropertiesToSend .가 아닌 모든 개체에 Message적용됩니다. 예를 들어 멤버를 사용하여 DefaultPropertiesToSend 레이블 또는 우선 순위를 지정하는 경우 이러한 값은 애플리케이션이 큐에 보낼 때 형식 Message 이 아닌 개체가 포함된 모든 메시지에 적용됩니다. 전송할 Message때는 테이크 우선 DefaultPropertiesToSend 순위에 대해 Message 설정된 속성 값과 메시지의 Message.Formatter 속성이 큐의 MessageQueue.Formatter 속성보다 우선합니다.

다음 표에서는 이 메서드를 다양한 작업 그룹 모드에서 사용할 수 있는지 여부를 보여 줍니다.

작업 그룹 모드 사용 가능
로컬 컴퓨터
로컬 컴퓨터 및 직접 형식 이름
원격 컴퓨터 No
원격 컴퓨터 및 직접 형식 이름

추가 정보

적용 대상

Send(Object, MessageQueueTransaction)

에서 참조하는 트랜잭션 큐에 개체를 MessageQueue보냅니다.

public:
 void Send(System::Object ^ obj, System::Messaging::MessageQueueTransaction ^ transaction);
public void Send(object obj, System.Messaging.MessageQueueTransaction transaction);
member this.Send : obj * System.Messaging.MessageQueueTransaction -> unit
Public Sub Send (obj As Object, transaction As MessageQueueTransaction)

매개 변수

obj
Object

큐에 보낼 개체입니다.

예외

매개 변수는 transaction .입니다 null.

속성이 Path 설정되지 않았습니다.

-또는-

메시지 큐 애플리케이션이 잘못된 트랜잭션 사용을 표시했습니다.

-또는-

메시지 큐 메서드에 액세스할 때 오류가 발생했습니다.

예제

다음 코드 예제에서는 트랜잭션 큐에 문자열을 보낸 다음 해당 큐에서 메시지를 받습니다.

#using <system.dll>
#using <system.messaging.dll>

using namespace System;
using namespace System::Messaging;

/// <summary>
/// Provides a container class for the example.
/// </summary>
ref class MyNewQueue
{
public:

   //*************************************************
   // Sends a message to a queue.
   //*************************************************
   void SendMessageTransactional()
   {
      // Connect to a queue on the local computer.
      MessageQueue^ myQueue = gcnew MessageQueue( ".\\myTransactionalQueue" );

      // Send a message to the queue.
      if ( myQueue->Transactional )
      {
         // Create a transaction.
         MessageQueueTransaction^ myTransaction = gcnew MessageQueueTransaction;

         // Begin the transaction.
         myTransaction->Begin();

         // Send the message.
         myQueue->Send( "My Message Data.", myTransaction );

         // Commit the transaction.
         myTransaction->Commit();
      }

      return;
   }


   //*************************************************
   // Receives a message containing an Order.
   //*************************************************
   void ReceiveMessageTransactional()
   {
      // Connect to a transactional queue on the local computer.
      MessageQueue^ myQueue = gcnew MessageQueue( ".\\myTransactionalQueue" );

      // Set the formatter.
      array<Type^>^p = gcnew array<Type^>(1);
      p[ 0 ] = String::typeid;
      myQueue->Formatter = gcnew XmlMessageFormatter( p );

      // Create a transaction.
      MessageQueueTransaction^ myTransaction = gcnew MessageQueueTransaction;
      try
      {
         // Begin the transaction.
         myTransaction->Begin();

         // Receive the message. 
         Message^ myMessage = myQueue->Receive( myTransaction );
         String^ myOrder = static_cast<String^>(myMessage->Body);

         // Display message information.
         Console::WriteLine( myOrder );

         // Commit the transaction.
         myTransaction->Commit();
      }
      catch ( MessageQueueException^ e ) 
      {
         // Handle nontransactional queues.
         if ( e->MessageQueueErrorCode == MessageQueueErrorCode::TransactionUsage )
         {
            Console::WriteLine( "Queue is not transactional." );
         }

         // Else catch other sources of MessageQueueException.
         // Roll back the transaction.
         myTransaction->Abort();
      }

      // Catch other exceptions as necessary, such as 
      // InvalidOperationException, thrown when the formatter 
      // cannot deserialize the message.
      return;
   }
};

//*************************************************
// Provides an entry point into the application.
// 
// This example sends and receives a message from
// a transactional queue.
//*************************************************
int main()
{
   // Create a new instance of the class.
   MyNewQueue^ myNewQueue = gcnew MyNewQueue;

   // Send a message to a queue.
   myNewQueue->SendMessageTransactional();

   // Receive a message from a queue.
   myNewQueue->ReceiveMessageTransactional();
   return 0;
}
using System;
using System.Messaging;

namespace MyProject
{

    /// <summary>
    /// Provides a container class for the example.
    /// </summary>
    public class MyNewQueue
    {

        //**************************************************
        // Provides an entry point into the application.
        //
        // This example sends and receives a message from
        // a transactional queue.
        //**************************************************

        public static void Main()
        {
            // Create a new instance of the class.
            MyNewQueue myNewQueue = new MyNewQueue();

            // Send a message to a queue.
            myNewQueue.SendMessageTransactional();

            // Receive a message from a queue.
            myNewQueue.ReceiveMessageTransactional();
        
            return;
        }

        //**************************************************
        // Sends a message to a queue.
        //**************************************************
        
        public void SendMessageTransactional()
        {
                        
            // Connect to a queue on the local computer.
            MessageQueue myQueue = new
                MessageQueue(".\\myTransactionalQueue");

            // Send a message to the queue.
            if (myQueue.Transactional)
            {
                // Create a transaction.
                MessageQueueTransaction myTransaction = new
                    MessageQueueTransaction();

                // Begin the transaction.
                myTransaction.Begin();

                // Send the message.
                myQueue.Send("My Message Data.", myTransaction);

                // Commit the transaction.
                myTransaction.Commit();
            }

            return;
        }

        //**************************************************
        // Receives a message containing an Order.
        //**************************************************
        
        public  void ReceiveMessageTransactional()
        {
            // Connect to a transactional queue on the local computer.
            MessageQueue myQueue = new
                MessageQueue(".\\myTransactionalQueue");

            // Set the formatter.
            myQueue.Formatter = new XmlMessageFormatter(new Type[]
                {typeof(String)});
            
            // Create a transaction.
            MessageQueueTransaction myTransaction = new
                MessageQueueTransaction();

            try
            {
                // Begin the transaction.
                myTransaction.Begin();
                
                // Receive the message.
                Message myMessage =	myQueue.Receive(myTransaction);
                String myOrder = (String)myMessage.Body;

                // Display message information.
                Console.WriteLine(myOrder);

                // Commit the transaction.
                myTransaction.Commit();
            }
            
            catch (MessageQueueException e)
            {
                // Handle nontransactional queues.
                if (e.MessageQueueErrorCode ==
                    MessageQueueErrorCode.TransactionUsage)
                {
                    Console.WriteLine("Queue is not transactional.");
                }
                
                // Else catch other sources of MessageQueueException.

                // Roll back the transaction.
                myTransaction.Abort();
            }

            // Catch other exceptions as necessary, such as
            // InvalidOperationException, thrown when the formatter
            // cannot deserialize the message.

            return;
        }
    }
}
Imports System.Messaging

   
Public Class MyNewQueue


        '
        ' Provides an entry point into the application.
        ' 
        ' This example sends and receives a message from
        ' a transactional queue.
        '

        Public Shared Sub Main()

            ' Create a new instance of the class.
            Dim myNewQueue As New MyNewQueue

            ' Send a message to a queue.
            myNewQueue.SendMessageTransactional()

            ' Receive a message from a queue.
            myNewQueue.ReceiveMessageTransactional()

            Return

        End Sub


        '
        ' Sends a message to a queue.
        '

        Public Sub SendMessageTransactional()

            ' Connect to a queue on the local computer.
            Dim myQueue As New MessageQueue(".\myTransactionalQueue")

            ' Send a message to the queue.
            If myQueue.Transactional = True Then
                ' Create a transaction.
                Dim myTransaction As New MessageQueueTransaction

                ' Begin the transaction.
                myTransaction.Begin()

                ' Send the message.
                myQueue.Send("My Message Data.", myTransaction)

                ' Commit the transaction.
                myTransaction.Commit()
            End If

            Return

        End Sub


        '
        ' Receives a message containing an Order.
        '

        Public Sub ReceiveMessageTransactional()

            ' Connect to a transactional queue on the local computer.
            Dim myQueue As New MessageQueue(".\myTransactionalQueue")

            ' Set the formatter.
            myQueue.Formatter = New XmlMessageFormatter(New Type() _
                {GetType([String])})

            ' Create a transaction.
            Dim myTransaction As New MessageQueueTransaction

            Try

                ' Begin the transaction.
                myTransaction.Begin()

                ' Receive the message. 
                Dim myMessage As Message = _
                    myQueue.Receive(myTransaction)
                Dim myOrder As [String] = CType(myMessage.Body, _
                    [String])

                ' Display message information.
                Console.WriteLine(myOrder)

                ' Commit the transaction.
                myTransaction.Commit()


            Catch e As MessageQueueException

                ' Handle nontransactional queues.
                If e.MessageQueueErrorCode = _
                    MessageQueueErrorCode.TransactionUsage Then

                    Console.WriteLine("Queue is not transactional.")

                End If

                ' Else catch other sources of a MessageQueueException.


                ' Roll back the transaction.
                myTransaction.Abort()


                ' Catch other exceptions as necessary, such as 
                ' InvalidOperationException, thrown when the formatter
                ' cannot deserialize the message.

            End Try

            Return

        End Sub

End Class

설명

이 오버로드를 사용하여 매개 변수로 정의된 내부 트랜잭션 컨텍스트를 사용하여 매개 변수가 포함된 obj 메시지를 참조하는 트랜잭션 큐 MessageQueuetransaction 보냅니다. 큐에 보내는 개체는 관리되는 개체이거나 관리되는 개체일 Message 수 있습니다. 다른 개체를 Message보내면 개체가 직렬화되어 메시지 본문에 삽입됩니다.

이 오버로드를 사용하여 비 트랜잭션 큐에 메시지를 보내는 경우 예외를 throw하지 않고 배달 못 한 편지 큐로 메시지를 보낼 수 있습니다.

호출Send(Object)하기 전에 속성을 설정 Formatter 하지 않으면 포맷터가 기본값으로 XmlMessageFormatter지정됩니다.

이 속성은 DefaultPropertiesToSend .가 아닌 모든 개체에 Message적용됩니다. 예를 들어 멤버를 사용하여 DefaultPropertiesToSend 레이블 또는 우선 순위를 지정하는 경우 이러한 값은 애플리케이션이 큐에 보낼 때 형식 Message 이 아닌 개체가 포함된 모든 메시지에 적용됩니다. 전송할 Message때는 테이크 우선 DefaultPropertiesToSend 순위에 대해 Message 설정된 속성 값과 메시지의 Message.Formatter 속성이 큐의 MessageQueue.Formatter 속성보다 우선합니다.

MessageQueueTransaction 는 아파트 인식 스레딩이므로 아파트 상태 STA인 경우 여러 스레드에서 트랜잭션을 사용할 수 없습니다. Visual Basic은 주 스레드STA의 상태를 설정하므로 서브루틴에 Main 적용 MTAThreadAttribute 해야 합니다. 그렇지 않으면 다른 스레드를 사용하여 트랜잭션 메시지를 보내면 예외가 MessageQueueException throw됩니다. 다음 조각을 사용하여 적용 MTAThreadAttribute 합니다.

<System.MTAThreadAttribute>
 public sub Main()

다음 표에서는 이 메서드를 다양한 작업 그룹 모드에서 사용할 수 있는지 여부를 보여 줍니다.

작업 그룹 모드 사용 가능
로컬 컴퓨터
로컬 컴퓨터 및 직접 형식 이름
원격 컴퓨터 No
원격 컴퓨터 및 직접 형식 이름

추가 정보

적용 대상

Send(Object, MessageQueueTransactionType)

에서 참조하는 큐에 개체를 MessageQueue보냅니다.

public:
 void Send(System::Object ^ obj, System::Messaging::MessageQueueTransactionType transactionType);
public void Send(object obj, System.Messaging.MessageQueueTransactionType transactionType);
member this.Send : obj * System.Messaging.MessageQueueTransactionType -> unit
Public Sub Send (obj As Object, transactionType As MessageQueueTransactionType)

매개 변수

obj
Object

큐에 보낼 개체입니다.

transactionType
MessageQueueTransactionType

MessageQueueTransactionType 메시지와 연결할 트랜잭션 컨텍스트의 형식을 설명하는 값 중 하나입니다.

예외

transactionType 매개 변수가 멤버 중 MessageQueueTransactionType 하나가 아닙니다.

속성이 Path 설정되지 않았습니다.

-또는-

메시지 큐 메서드에 액세스할 때 오류가 발생했습니다.

예제

다음 코드 예제에서는 .의 Send(Object, MessageQueueTransactionType)사용을 보여 줍니다.


// Connect to a transactional queue on the local computer.
MessageQueue^ queue = gcnew MessageQueue(".\\exampleTransQueue");

// Create a new message.
Message^ msg = gcnew Message("Example Message Body");

// Send the message.
queue->Send(msg, MessageQueueTransactionType::Single);

queue->Close();

// Connect to a transactional queue on the local computer.
MessageQueue queue = new MessageQueue(".\\exampleTransQueue");

// Create a new message.
Message msg = new Message("Example Message Body");

// Send the message.
queue.Send(msg, MessageQueueTransactionType.Single);

설명

이 오버로드를 사용하여 매개 변수로 정의된 트랜잭션 컨텍스트를 사용하여 매개 변수가 포함된 obj 메시지를 참조하는 큐 MessageQueuetransactionType 보냅니다. transactionType 메시지를 보내는 데 사용할 스레드에 연결된 외부 트랜잭션 컨텍스트가 이미 있는 경우 매개 변수를 지정 Automatic 합니다. Single 메시지를 단일 내부 트랜잭션으로 보낼지 지정합니다. 트랜잭션 메시지를 비트랜잭션 스레드로 보낼지 지정할 수 있습니다 None .

큐에 보내는 개체는 관리되는 개체이거나 관리되는 개체일 Message 수 있습니다. 다른 개체를 Message보내면 개체가 직렬화되어 메시지 본문에 삽입됩니다.

호출Send(Object)하기 전에 속성을 설정 Formatter 하지 않으면 포맷터가 기본값으로 XmlMessageFormatter지정됩니다.

이 속성은 DefaultPropertiesToSend .가 아닌 모든 개체에 Message적용됩니다. 예를 들어 멤버를 사용하여 DefaultPropertiesToSend 레이블 또는 우선 순위를 지정하는 경우 이러한 값은 애플리케이션이 큐에 보낼 때 형식 Message 이 아닌 개체가 포함된 모든 메시지에 적용됩니다. 전송할 Message때는 테이크 우선 DefaultPropertiesToSend 순위에 대해 Message 설정된 속성 값과 메시지의 Message.Formatter 속성이 큐의 MessageQueue.Formatter 속성보다 우선합니다.

다음 표에서는 이 메서드를 다양한 작업 그룹 모드에서 사용할 수 있는지 여부를 보여 줍니다.

작업 그룹 모드 사용 가능
로컬 컴퓨터
로컬 컴퓨터 및 직접 형식 이름
원격 컴퓨터 No
원격 컴퓨터 및 직접 형식 이름

추가 정보

적용 대상

Send(Object, String)

개체를 이 항목에서 참조하는 트랜잭션이 아닌 큐로 MessageQueue 보내고 메시지의 레이블을 지정합니다.

public:
 void Send(System::Object ^ obj, System::String ^ label);
public void Send(object obj, string label);
member this.Send : obj * string -> unit
Public Sub Send (obj As Object, label As String)

매개 변수

obj
Object

큐에 보낼 개체입니다.

label
String

메시지의 레이블입니다.

예외

매개 변수는 label .입니다 null.

속성이 Path 설정되지 않았습니다.

-또는-

메시지 큐 메서드에 액세스할 때 오류가 발생했습니다.

예제

다음 코드 예제에서는 .의 Send(Object, String)사용을 보여 줍니다.


// Connect to a queue on the local computer.
MessageQueue^ queue = gcnew MessageQueue(".\\exampleQueue");

// Create a new message.
Message^ msg = gcnew Message("Example Message Body");

// Send the message.
queue->Send(msg, "Example Message Label");

queue->Close();

// Connect to a queue on the local computer.
MessageQueue queue = new MessageQueue(".\\exampleQueue");

// Create a new message.
Message msg = new Message("Example Message Body");

// Send the message.
queue.Send(msg, "Example Message Label");

설명

이 오버로드를 사용하여 매개 변수가 포함된 obj 메시지를 .에서 참조하는 큐로 MessageQueue보냅니다. 이 오버로드를 사용하면 메시지를 식별하는 문자열 레이블을 지정할 수 있습니다. 큐에 보내는 개체는 구조체, 데이터 개체 또는 관리되는 개체일 Message수 있습니다. 다른 개체를 Message보내면 개체가 직렬화되어 메시지 본문에 삽입됩니다.

메시지 레이블은 메시지 큐 레이블과 다르지만 둘 다 애플리케이션에 종속되며 메시지 큐에 상속 의미가 없습니다.

이 오버로드를 사용하여 트랜잭션 큐에 메시지를 보내는 경우 메시지는 배달 못 한 편지 큐로 전송됩니다. 메시지가 다른 메시지를 포함하는 트랜잭션의 일부가 되도록 하려면 매개 변수를 사용하거나 MessageQueueTransactionType 매개 변수로 사용하는 MessageQueueTransaction 오버로드를 사용합니다.

Path 메시지를 보내기 전에 이 MessageQueue 인스턴스의 속성을 지정해야 합니다. 호출Send(Object)하기 전에 속성을 설정 Formatter 하지 않으면 포맷터가 기본값으로 XmlMessageFormatter지정됩니다.

이 속성은 DefaultPropertiesToSend .가 아닌 모든 개체에 Message적용됩니다. 예를 들어 멤버를 사용하여 DefaultPropertiesToSend 레이블 또는 우선 순위를 지정하는 경우 이러한 값은 애플리케이션이 큐에 보낼 때 형식 Message 이 아닌 개체가 포함된 모든 메시지에 적용됩니다. 전송할 Message때는 테이크 우선 DefaultPropertiesToSend 순위에 대해 Message 설정된 속성 값과 메시지의 Message.Formatter 속성이 큐의 MessageQueue.Formatter 속성보다 우선합니다.

다음 표에서는 이 메서드를 다양한 작업 그룹 모드에서 사용할 수 있는지 여부를 보여 줍니다.

작업 그룹 모드 사용 가능
로컬 컴퓨터
로컬 컴퓨터 및 직접 형식 이름
원격 컴퓨터 No
원격 컴퓨터 및 직접 형식 이름

추가 정보

적용 대상

Send(Object, String, MessageQueueTransaction)

이 항목에서 참조하는 트랜잭션 큐에 MessageQueue 개체를 보내고 메시지의 레이블을 지정합니다.

public:
 void Send(System::Object ^ obj, System::String ^ label, System::Messaging::MessageQueueTransaction ^ transaction);
public void Send(object obj, string label, System.Messaging.MessageQueueTransaction transaction);
member this.Send : obj * string * System.Messaging.MessageQueueTransaction -> unit
Public Sub Send (obj As Object, label As String, transaction As MessageQueueTransaction)

매개 변수

obj
Object

큐에 보낼 개체입니다.

label
String

메시지의 레이블입니다.

예외

매개 변수는 label .입니다 null.

-또는-

매개 변수는 transaction .입니다 null.

속성이 Path 설정되지 않았습니다.

-또는-

메시지 큐 애플리케이션에서 잘못된 트랜잭션 사용량을 표시했습니다.

-또는-

메시지 큐 메서드에 액세스할 때 오류가 발생했습니다.

예제

다음 코드 예제에서는 .의 Send(Object, String, MessageQueueTransaction)사용을 보여 줍니다.


// Connect to a transactional queue on the local computer.
MessageQueue^ queue = gcnew MessageQueue(".\\exampleTransQueue");

// Create a new message.
Message^ msg = gcnew Message("Example Message Body");

// Create a message queuing transaction.
MessageQueueTransaction^ transaction = gcnew MessageQueueTransaction();

try
{
    // Begin a transaction.
    transaction->Begin();

    // Send the message to the queue.
    queue->Send(msg, "Example Message Label", transaction);

    // Commit the transaction.
    transaction->Commit();
}
catch (Exception^ ex)
{
    // Cancel the transaction.
    transaction->Abort();

    // Propagate the exception.
    throw ex;
}
finally
{
    // Dispose of the transaction object.
    delete transaction;
    queue->Close();
}

// Connect to a transactional queue on the local computer.
MessageQueue queue = new MessageQueue(".\\exampleTransQueue");

// Create a new message.
Message msg = new Message("Example Message Body");

// Create a message queuing transaction.
MessageQueueTransaction transaction = new MessageQueueTransaction();

try
{
    // Begin a transaction.
    transaction.Begin();

    // Send the message to the queue.
    queue.Send(msg, "Example Message Label", transaction);

    // Commit the transaction.
    transaction.Commit();
}
catch (System.Exception e)
{
    // Cancel the transaction.
    transaction.Abort();

    // Propagate the exception.
    throw e;
}
finally
{
    // Dispose of the transaction object.
    transaction.Dispose();
}

설명

이 오버로드를 사용하여 매개 변수로 정의된 내부 트랜잭션 컨텍스트를 사용하여 매개 변수가 포함된 obj 메시지를 참조하는 트랜잭션 큐 MessageQueuetransaction 보냅니다. 이 오버로드를 사용하면 메시지를 식별하는 문자열 레이블을 지정할 수 있습니다. 큐에 보내는 개체는 구조체, 데이터 개체 또는 관리되는 개체일 Message수 있습니다. 다른 개체를 Message보내면 개체가 직렬화되어 메시지 본문에 삽입됩니다.

메시지 레이블은 메시지 큐 레이블과 다르지만 둘 다 애플리케이션에 종속되며 메시지 큐에 상속 의미가 없습니다.

이 오버로드를 사용하여 비 트랜잭션 큐에 메시지를 보내는 경우 예외를 throw하지 않고 배달 못 한 편지 큐로 메시지를 보낼 수 있습니다.

호출Send(Object)하기 전에 속성을 설정 Formatter 하지 않으면 포맷터가 기본값으로 XmlMessageFormatter지정됩니다.

이 속성은 DefaultPropertiesToSend .가 아닌 모든 개체에 Message적용됩니다. 예를 들어 멤버를 사용하여 DefaultPropertiesToSend 레이블 또는 우선 순위를 지정하는 경우 이러한 값은 애플리케이션이 큐에 보낼 때 형식 Message 이 아닌 개체가 포함된 모든 메시지에 적용됩니다. 보낼 Message때는 테이크 우선 DefaultPropertiesToSend 순위에 대해 Message 설정된 속성 값과 메시지의 Message.Formatter 속성이 큐의 MessageQueue.Formatter 속성보다 우선합니다.

MessageQueueTransaction 는 아파트 인식 스레딩이므로 아파트 상태 STA인 경우 여러 스레드에서 트랜잭션을 사용할 수 없습니다. Visual Basic은 주 스레드STA의 상태를 설정하므로 서브루틴에 Main 적용 MTAThreadAttribute 해야 합니다. 그렇지 않으면 다른 스레드를 사용하여 트랜잭션 메시지를 보내면 예외가 MessageQueueException throw됩니다. 다음 조각을 사용하여 적용 MTAThreadAttribute 합니다.

<System.MTAThreadAttribute>
 public sub Main()

다음 표에서는 이 메서드를 다양한 작업 그룹 모드에서 사용할 수 있는지 여부를 보여 줍니다.

작업 그룹 모드 사용 가능
로컬 컴퓨터
로컬 컴퓨터 및 직접 형식 이름
원격 컴퓨터 No
원격 컴퓨터 및 직접 형식 이름

추가 정보

적용 대상

Send(Object, String, MessageQueueTransactionType)

이 개체가 참조하는 큐에 MessageQueue 개체를 보내고 메시지의 레이블을 지정합니다.

public:
 void Send(System::Object ^ obj, System::String ^ label, System::Messaging::MessageQueueTransactionType transactionType);
public void Send(object obj, string label, System.Messaging.MessageQueueTransactionType transactionType);
member this.Send : obj * string * System.Messaging.MessageQueueTransactionType -> unit
Public Sub Send (obj As Object, label As String, transactionType As MessageQueueTransactionType)

매개 변수

obj
Object

큐에 보낼 개체입니다.

label
String

메시지의 레이블입니다.

transactionType
MessageQueueTransactionType

MessageQueueTransactionType 메시지와 연결할 트랜잭션 컨텍스트의 형식을 설명하는 값 중 하나입니다.

예외

매개 변수는 label .입니다 null.

메시지 큐 애플리케이션에서 잘못된 트랜잭션 사용량을 표시했습니다.

transactionType 매개 변수가 멤버 중 MessageQueueTransactionType 하나가 아닙니다.

속성이 Path 설정되지 않았습니다.

-또는-

메시지 큐 메서드에 액세스할 때 오류가 발생했습니다.

예제

다음 코드 예제에서는 .의 Send(Object, String, MessageQueueTransactionType)사용을 보여 줍니다.


// Connect to a transactional queue on the local computer.
MessageQueue^ queue = gcnew MessageQueue(".\\exampleTransQueue");

// Create a new message.
Message^ msg = gcnew Message("Example Message Body");

// Send the message.
queue->Send(msg, "Example Message Label",
    MessageQueueTransactionType::Single);

queue->Close();

// Connect to a transactional queue on the local computer.
MessageQueue queue = new MessageQueue(".\\exampleTransQueue");

// Create a new message.
Message msg = new Message("Example Message Body");

// Send the message.
queue.Send(msg, "Example Message Label",
    MessageQueueTransactionType.Single);

설명

이 오버로드를 사용하여 매개 변수로 정의된 트랜잭션 컨텍스트를 사용하여 매개 변수가 포함된 obj 메시지를 참조하는 큐 MessageQueuetransactionType 보냅니다. transactionType 메시지를 보내는 데 사용할 스레드에 연결된 외부 트랜잭션 컨텍스트가 이미 있는 경우 매개 변수를 지정 Automatic 합니다. Single 메시지를 단일 내부 트랜잭션으로 보낼지 지정합니다. 트랜잭션 메시지를 비트랜잭션 스레드로 보낼지 지정할 수 있습니다 None .

큐에 보내는 개체는 관리되는 개체이거나 관리되는 개체일 Message 수 있습니다. 다른 개체를 Message보내면 개체가 직렬화되어 메시지 본문에 삽입됩니다. 이 오버로드를 사용하면 메시지를 식별하는 문자열 레이블을 지정할 수 있습니다.

메시지 레이블은 메시지 큐 레이블과 다르지만 둘 다 애플리케이션에 종속되며 메시지 큐에 상속 의미가 없습니다.

호출Send(Object)하기 전에 속성을 설정 Formatter 하지 않으면 포맷터가 기본값으로 XmlMessageFormatter지정됩니다.

이 속성은 DefaultPropertiesToSend .가 아닌 모든 개체에 Message적용됩니다. 예를 들어 멤버를 사용하여 DefaultPropertiesToSend 레이블 또는 우선 순위를 지정하는 경우 이러한 값은 애플리케이션이 큐에 보낼 때 형식 Message 이 아닌 개체가 포함된 모든 메시지에 적용됩니다. 전송할 Message때는 테이크 우선 DefaultPropertiesToSend순위에 대해 Message 설정된 속성 값과 메시지의 Message.Formatter 속성이 큐의 MessageQueue.Formatter 속성보다 우선합니다.

다음 표에서는 이 메서드를 다양한 작업 그룹 모드에서 사용할 수 있는지 여부를 보여 줍니다.

작업 그룹 모드 사용 가능
로컬 컴퓨터
로컬 컴퓨터 및 직접 형식 이름
원격 컴퓨터 No
원격 컴퓨터 및 직접 형식 이름

추가 정보

적용 대상