MessageQueue イベント

名前 | 説明 | |
---|---|---|
![]() | Disposed | コンポーネントの Disposed イベントを待機するイベント ハンドラを追加します。 ( Component から継承されます。) |
![]() | PeekCompleted | キューから削除せずにメッセージを読み取ると発生します。この発生は、非同期操作 BeginPeek の結果です。 |
![]() | ReceiveCompleted | メッセージがキューから削除されると発生します。このイベントは、非同期操作 BeginReceive によって発生します。 |

MessageQueue クラス
アセンブリ: System.Messaging (system.messaging.dll 内)


メッセージ キューの技術を使用すると、一時的にオフラインになる可能性のある異種ネットワークや異種システム間で、異なる時間に実行される複数のアプリケーションが相互に通信できます。アプリケーションは、キューからのメッセージを送信、受信、またはピーク (削除せずに読み取ること) します。メッセージ キューは Windows 2000 および Windows NT のオプションのコンポーネントです。個別にインストールする必要があります。
MessageQueue クラスは、メッセージ キューのラッパー クラスです。メッセージ キューには複数のバージョンがあり、使用しているオペレーティング システムによって MessageQueue クラスの動作が少し異なります。メッセージ キューの各バージョンにおける固有の機能の詳細については、MSDN のプラットフォーム SDK ドキュメントのトピック「What's New in Message Queuing」を参照してください。
MessageQueue クラスによりメッセージ キューのキューへの参照ができます。MessageQueue コンストラクタでパスを指定して既存のリソースに接続するか、サーバーに新しいキューを作成できます。Send(Object)、Peek、または Receive を呼び出す前に、MessageQueue クラスの新しいインスタンスを既存のキューに関連付ける必要があります。この時点で、Category や Label などのキュー プロパティの操作ができるようになります。
MessageQueue は、同期と非同期の 2 種類のメッセージ取得をサポートします。同期メソッドである Peek と Receive を使用して、プロセス スレッドは新しいメッセージがキューに到達するまで待機する時間間隔を指定します。非同期メソッドである BeginPeek と BeginReceive を使用すると、キューにメッセージが到達するまで、メイン アプリケーションのタスクは別のスレッドで継続します。これらのメソッドは、コールバック オブジェクトと状態オブジェクトを使用してスレッド間で情報を通信することによって動作します。
MessageQueue クラスの新しいインスタンスを作成するときに、新しいメッセージ キューのキューは作成されません。その代わりに、Create(String)、Delete、Purge の各メソッドを使用してサーバーのキューを管理できます。
Purge とは異なり、Create(String) と Delete は static メンバであるため、MessageQueue クラスの新しいインスタンスを作成せずに呼び出すことができます。
MessageQueue オブジェクトの Path プロパティには、表示名、FormatName、Label など、3 種類ある名前のうちの 1 つを設定できます。表示名とは、キューの MachineName プロパティと QueueName プロパティで定義される名前であり、パブリック キューの場合は MachineName \ QueueName、プライベート キューの場合は MachineName \ Private$ \ QueueName です。FormatName プロパティを使用すると、メッセージ キューにオフラインでアクセスできます。キューの Label プロパティを使用してキューの Path を設定することもできます。
MessageQueue のインスタンスの初期プロパティ値の一覧については、MessageQueue コンストラクタのトピックを参照してください。

さまざまな種類のパス名構文を使用して、新しい MessageQueue オブジェクトを作成するコード例を次に示します。いずれの場合も、コンストラクタでパスが定義されているキューにメッセージを送信します。
Imports System Imports System.Messaging Public Class MyNewQueue ' Provides an entry point into the application. ' ' This example demonstrates several ways to set ' a queue's path. Public Shared Sub Main() ' Create a new instance of the class. Dim myNewQueue As New MyNewQueue() myNewQueue.SendPublic() myNewQueue.SendPrivate() myNewQueue.SendByLabel() myNewQueue.SendByFormatName() myNewQueue.MonitorComputerJournal() myNewQueue.MonitorQueueJournal() myNewQueue.MonitorDeadLetter() myNewQueue.MonitorTransactionalDeadLetter() Return End Sub 'Main ' References public queues. Public Sub SendPublic() Dim myQueue As New MessageQueue(".\myQueue") myQueue.Send("Public queue by path name.") Return End Sub 'SendPublic ' References private queues. Public Sub SendPrivate() Dim myQueue As New MessageQueue(".\Private$\myQueue") myQueue.Send("Private queue by path name.") Return End Sub 'SendPrivate ' References queues by label. Public Sub SendByLabel() Dim myQueue As New MessageQueue("Label:TheLabel") myQueue.Send("Queue by label.") Return End Sub 'SendByLabel ' References queues by format name. Public Sub SendByFormatName() Dim myQueue As New _ MessageQueue("FormatName:Public=" + _ "5A5F7535-AE9A-41d4-935C-845C2AFF7112") myQueue.Send("Queue by format name.") Return End Sub 'SendByFormatName ' References computer journal queues. Public Sub MonitorComputerJournal() Dim computerJournal As New MessageQueue(".\Journal$") While True Dim journalMessage As Message = _ computerJournal.Receive() ' Process the journal message. End While Return End Sub 'MonitorComputerJournal ' References queue journal queues. Public Sub MonitorQueueJournal() Dim queueJournal As New _ MessageQueue(".\myQueue\Journal$") While True Dim journalMessage As Message = _ queueJournal.Receive() ' Process the journal message. End While Return End Sub 'MonitorQueueJournal ' References dead-letter queues. Public Sub MonitorDeadLetter() Dim deadLetter As New MessageQueue(".\DeadLetter$") While True Dim deadMessage As Message = deadLetter.Receive() ' Process the dead-letter message. End While Return End Sub 'MonitorDeadLetter ' References transactional dead-letter queues. Public Sub MonitorTransactionalDeadLetter() Dim TxDeadLetter As New MessageQueue(".\XactDeadLetter$") While True Dim txDeadLetterMessage As Message = _ TxDeadLetter.Receive() ' Process the transactional dead-letter message. End While Return End Sub 'MonitorTransactionalDeadLetter End Class 'MyNewQueue
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 demonstrates several ways to set // a queue's path. //************************************************** public static void Main() { // Create a new instance of the class. MyNewQueue myNewQueue = new MyNewQueue(); myNewQueue.SendPublic(); myNewQueue.SendPrivate(); myNewQueue.SendByLabel(); myNewQueue.SendByFormatName(); myNewQueue.MonitorComputerJournal(); myNewQueue.MonitorQueueJournal(); myNewQueue.MonitorDeadLetter(); myNewQueue.MonitorTransactionalDeadLetter(); return; } // References public queues. public void SendPublic() { MessageQueue myQueue = new MessageQueue(".\\myQueue"); myQueue.Send("Public queue by path name."); return; } // References private queues. public void SendPrivate() { MessageQueue myQueue = new MessageQueue(".\\Private$\\myQueue"); myQueue.Send("Private queue by path name."); return; } // References queues by label. public void SendByLabel() { MessageQueue myQueue = new MessageQueue("Label:TheLabel"); myQueue.Send("Queue by label."); return; } // References queues by format name. public void SendByFormatName() { MessageQueue myQueue = new MessageQueue("FormatName:Public=5A5F7535-AE9A-41d4" + "-935C-845C2AFF7112"); myQueue.Send("Queue by format name."); return; } // References computer journal queues. public void MonitorComputerJournal() { MessageQueue computerJournal = new MessageQueue(".\\Journal$"); while(true) { Message journalMessage = computerJournal.Receive(); // Process the journal message. } } // References queue journal queues. public void MonitorQueueJournal() { MessageQueue queueJournal = new MessageQueue(".\\myQueue\\Journal$"); while(true) { Message journalMessage = queueJournal.Receive(); // Process the journal message. } } // References dead-letter queues. public void MonitorDeadLetter() { MessageQueue deadLetter = new MessageQueue(".\\DeadLetter$"); while(true) { Message deadMessage = deadLetter.Receive(); // Process the dead-letter message. } } // References transactional dead-letter queues. public void MonitorTransactionalDeadLetter() { MessageQueue TxDeadLetter = new MessageQueue(".\\XactDeadLetter$"); while(true) { Message txDeadLetter = TxDeadLetter.Receive(); // Process the transactional dead-letter message. } } } }
#using <system.dll> #using <system.messaging.dll> using namespace System; using namespace System::Messaging; ref class MyNewQueue { public: // References public queues. void SendPublic() { MessageQueue^ myQueue = gcnew MessageQueue( ".\\myQueue" ); myQueue->Send( "Public queue by path name." ); return; } // References private queues. void SendPrivate() { MessageQueue^ myQueue = gcnew MessageQueue( ".\\Private$\\myQueue" ); myQueue->Send( "Private queue by path name." ); return; } // References queues by label. void SendByLabel() { MessageQueue^ myQueue = gcnew MessageQueue( "Label:TheLabel" ); myQueue->Send( "Queue by label." ); return; } // References queues by format name. void SendByFormatName() { MessageQueue^ myQueue = gcnew MessageQueue( "FormatName:Public=5A5F7535-AE9A-41d4 -935C-845C2AFF7112" ); myQueue->Send( "Queue by format name." ); return; } // References computer journal queues. void MonitorComputerJournal() { MessageQueue^ computerJournal = gcnew MessageQueue( ".\\Journal$" ); while ( true ) { Message^ journalMessage = computerJournal->Receive(); // Process the journal message. } } // References queue journal queues. void MonitorQueueJournal() { MessageQueue^ queueJournal = gcnew MessageQueue( ".\\myQueue\\Journal$" ); while ( true ) { Message^ journalMessage = queueJournal->Receive(); // Process the journal message. } } // References dead-letter queues. void MonitorDeadLetter() { MessageQueue^ deadLetter = gcnew MessageQueue( ".\\DeadLetter$" ); while ( true ) { Message^ deadMessage = deadLetter->Receive(); // Process the dead-letter message. } } // References transactional dead-letter queues. void MonitorTransactionalDeadLetter() { MessageQueue^ TxDeadLetter = gcnew MessageQueue( ".\\XactDeadLetter$" ); while ( true ) { Message^ txDeadLetter = TxDeadLetter->Receive(); // Process the transactional dead-letter message. } } }; //************************************************* // Provides an entry point into the application. // // This example demonstrates several ways to set // a queue's path. //************************************************* int main() { // Create a new instance of the class. MyNewQueue^ myNewQueue = gcnew MyNewQueue; myNewQueue->SendPublic(); myNewQueue->SendPrivate(); myNewQueue->SendByLabel(); myNewQueue->SendByFormatName(); myNewQueue->MonitorComputerJournal(); myNewQueue->MonitorQueueJournal(); myNewQueue->MonitorDeadLetter(); myNewQueue->MonitorTransactionalDeadLetter(); return 0; }
package MyProject; import System.*; import System.Messaging.*; /// <summary> /// Provides a container class for the example. /// </summary> public class MyNewQueue { //************************************************** // Provides an entry point into the application. // // This example demonstrates several ways to set // a queue's path. //************************************************** public static void main(String[] args) { // Create a new instance of the class. MyNewQueue myNewQueue = new MyNewQueue(); myNewQueue.SendPublic(); myNewQueue.SendPrivate(); myNewQueue.SendByLabel(); myNewQueue.SendByFormatName(); myNewQueue.MonitorComputerJournal(); myNewQueue.MonitorQueueJournal(); myNewQueue.MonitorDeadLetter(); myNewQueue.MonitorTransactionalDeadLetter(); return; } //main // References public queues. public void SendPublic() { MessageQueue myQueue = new MessageQueue(".\\myQueue"); myQueue.Send("Public queue by path name."); return; } //SendPublic // References private queues. public void SendPrivate() { MessageQueue myQueue = new MessageQueue(".\\Private$\\myQueue"); myQueue.Send("Private queue by path name."); return; } //SendPrivate // References queues by label. public void SendByLabel() { MessageQueue myQueue = new MessageQueue("Label:TheLabel"); myQueue.Send("Queue by label."); return; } //SendByLabel // References queues by format name. public void SendByFormatName() { MessageQueue myQueue = new MessageQueue("FormatName:Public=5A5F7535-AE9A-41d4" + "-935C-845C2AFF7112"); myQueue.Send("Queue by format name."); return; } //SendByFormatName // References computer journal queues. public void MonitorComputerJournal() { MessageQueue computerJournal = new MessageQueue(".\\Journal$"); while (true) { Message journalMessage = computerJournal.Receive(); // Process the journal message. } } //MonitorComputerJournal // References queue journal queues. public void MonitorQueueJournal() { MessageQueue queueJournal = new MessageQueue(".\\myQueue\\Journal$"); while (true) { Message journalMessage = queueJournal.Receive(); // Process the journal message. } } //MonitorQueueJournal // References dead-letter queues. public void MonitorDeadLetter() { MessageQueue deadLetter = new MessageQueue(".\\DeadLetter$"); while (true) { Message deadMessage = deadLetter.Receive(); // Process the dead-letter message. } } //MonitorDeadLetter // References transactional dead-letter queues. public void MonitorTransactionalDeadLetter() { MessageQueue objTxDeadLetter = new MessageQueue(".\\XactDeadLetter$"); while (true) { Message txDeadLetter = objTxDeadLetter.Receive(); // Process the transactional dead-letter message. } } //MonitorTransactionalDeadLetter } //MyNewQueue
アプリケーション固有の Order というクラスを使用して、メッセージをキューに送信し、キューからメッセージを受信するコード例を次に示します。
Imports System Imports System.Messaging ' This class represents an object the following example ' sends to a queue and receives from a queue. Public Class Order Public orderId As Integer Public orderTime As DateTime End Class 'Order Public Class MyNewQueue ' ' Provides an entry point into the application. ' ' This example sends and receives a message from ' a qeue. ' Public Shared Sub Main() ' Create a new instance of the class. Dim myNewQueue As New MyNewQueue() ' Send a message to a queue. myNewQueue.SendMessage() ' Receive a message from a queue. myNewQueue.ReceiveMessage() Return End Sub 'Main ' ' Sends an Order to a queue. ' Public Sub SendMessage() ' Create a new order and set values. Dim sentOrder As New Order() sentOrder.orderId = 3 sentOrder.orderTime = DateTime.Now ' Connect to a queue on the local computer. Dim myQueue As New MessageQueue(".\myQueue") ' Send the Order to the queue. myQueue.Send(sentOrder) Return End Sub 'SendMessage ' ' Receives a message containing an Order. ' Public Sub ReceiveMessage() ' Connect to the a queue on the local computer. Dim myQueue As New MessageQueue(".\myQueue") ' Set the formatter to indicate the body contains an Order. myQueue.Formatter = New XmlMessageFormatter(New Type() _ {GetType(Order)}) Try ' Receive and format the message. Dim myMessage As Message = myQueue.Receive() Dim myOrder As Order = CType(myMessage.Body, Order) ' Display message information. Console.WriteLine(("Order ID: " + _ myOrder.orderId.ToString())) Console.WriteLine(("Sent: " + _ myOrder.orderTime.ToString())) Catch m As MessageQueueException ' Handle Message Queuing exceptions. Catch e As InvalidOperationException ' Handle invalid serialization format. Console.WriteLine(e.Message) ' Catch other exceptions as necessary. End Try Return End Sub 'ReceiveMessage End Class 'MyNewQueue
using System; using System.Messaging; namespace MyProject { // This class represents an object the following example // sends to a queue and receives from a queue. public class Order { public int orderId; public DateTime orderTime; }; /// <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 queue. //************************************************** public static void Main() { // Create a new instance of the class. MyNewQueue myNewQueue = new MyNewQueue(); // Send a message to a queue. myNewQueue.SendMessage(); // Receive a message from a queue. myNewQueue.ReceiveMessage(); return; } //************************************************** // Sends an Order to a queue. //************************************************** public void SendMessage() { // Create a new order and set values. Order sentOrder = new Order(); sentOrder.orderId = 3; sentOrder.orderTime = DateTime.Now; // Connect to a queue on the local computer. MessageQueue myQueue = new MessageQueue(".\\myQueue"); // Send the Order to the queue. myQueue.Send(sentOrder); return; } //************************************************** // Receives a message containing an Order. //************************************************** public void ReceiveMessage() { // Connect to the a queue on the local computer. MessageQueue myQueue = new MessageQueue(".\\myQueue"); // Set the formatter to indicate body contains an Order. myQueue.Formatter = new XmlMessageFormatter(new Type[] {typeof(MyProject.Order)}); try { // Receive and format the message. Message myMessage = myQueue.Receive(); Order myOrder = (Order)myMessage.Body; // Display message information. Console.WriteLine("Order ID: " + myOrder.orderId.ToString()); Console.WriteLine("Sent: " + myOrder.orderTime.ToString()); } catch (MessageQueueException) { // Handle Message Queuing exceptions. } // Handle invalid serialization format. catch (InvalidOperationException e) { Console.WriteLine(e.Message); } // Catch other exceptions as necessary. return; } } }
#using <system.dll> #using <system.messaging.dll> using namespace System; using namespace System::Messaging; // This class represents an object the following example // sends to a queue and receives from a queue. ref class Order { public: int orderId; DateTime orderTime; }; /// <summary> /// Provides a container class for the example. /// </summary> ref class MyNewQueue { public: //************************************************* // Sends an Order to a queue. //************************************************* void SendMessage() { // Create a new order and set values. Order^ sentOrder = gcnew Order; sentOrder->orderId = 3; sentOrder->orderTime = DateTime::Now; // Connect to a queue on the local computer. MessageQueue^ myQueue = gcnew MessageQueue( ".\\myQueue" ); // Send the Order to the queue. myQueue->Send( sentOrder ); return; } //************************************************* // Receives a message containing an Order. //************************************************* void ReceiveMessage() { // Connect to the a queue on the local computer. MessageQueue^ myQueue = gcnew MessageQueue( ".\\myQueue" ); // Set the formatter to indicate body contains an Order. array<Type^>^p = gcnew array<Type^>(1); p[ 0 ] = Order::typeid; myQueue->Formatter = gcnew XmlMessageFormatter( p ); try { // Receive and format the message. Message^ myMessage = myQueue->Receive(); Order^ myOrder = static_cast<Order^>(myMessage->Body); // Display message information. Console::WriteLine( "Order ID: {0}", myOrder->orderId ); Console::WriteLine( "Sent: {0}", myOrder->orderTime ); } catch ( MessageQueueException^ ) { // Handle Message Queuing exceptions. } // Handle invalid serialization format. catch ( InvalidOperationException^ e ) { Console::WriteLine( e->Message ); } // Catch other exceptions as necessary. return; } }; //************************************************* // Provides an entry point into the application. // // This example sends and receives a message from // a queue. //************************************************* int main() { // Create a new instance of the class. MyNewQueue^ myNewQueue = gcnew MyNewQueue; // Send a message to a queue. myNewQueue->SendMessage(); // Receive a message from a queue. myNewQueue->ReceiveMessage(); return 0; }
package MyProject; import System.*; import System.Messaging.*; // This class represents an object the following example // sends to a queue and receives from a queue. public class Order { public int orderId; public DateTime orderTime; } //Order /// <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 queue. //************************************************** public static void main(String[] args) { // Create a new instance of the class. MyNewQueue myNewQueue = new MyNewQueue(); // Send a message to a queue. myNewQueue.SendMessage(); // Receive a message from a queue. myNewQueue.ReceiveMessage(); return; } //main //************************************************** // Sends an Order to a queue. //************************************************** public void SendMessage() { // Create a new order and set values. Order sentOrder = new Order(); sentOrder.orderId = 3; sentOrder.orderTime = DateTime.get_Now(); // Connect to a queue on the local computer. MessageQueue myQueue = new MessageQueue(".\\myQueue"); // Send the Order to the queue. myQueue.Send(sentOrder); return; } //SendMessage //************************************************** // Receives a message containing an Order. //************************************************** public void ReceiveMessage() { // Connect to the a queue on the local computer. MessageQueue myQueue = new MessageQueue(".\\myQueue"); // Set the formatter to indicate body contains an Order. myQueue.set_Formatter(new XmlMessageFormatter(new Type[] { MyProject.Order.class.ToType() })); try { // Receive and format the message. Message myMessage = myQueue.Receive(); Order myOrder = (Order)(myMessage.get_Body()); // Display message information. Console.WriteLine("Order ID: "+((Int32)myOrder.orderId).ToString()); Console.WriteLine("Sent: " + myOrder.orderTime.ToString()); } catch (MessageQueueException exp) { // Handle Message Queuing exceptions. } // Handle invalid serialization format. catch (InvalidOperationException e) { Console.WriteLine(e.get_Message()); } // Catch other exceptions as necessary. return; } //ReceiveMessage } //MyNewQueue

System.MarshalByRefObject
System.ComponentModel.Component
System.Messaging.MessageQueue


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


MessageQueue コンストラクタ ()
アセンブリ: System.Messaging (system.messaging.dll 内)


このオーバーロードを使用して、メッセージ キュー サーバーのキューにすぐには結び付けられない MessageQueue クラスの新しいインスタンスを作成します。このインスタンスを使用する前に、Path プロパティを設定して、既存のメッセージ キューのキューに接続する必要があります。または、MessageQueue 参照に Create(String) メソッドの戻り値を設定して、新しいメッセージ キューのキューを作成することもできます。
MessageQueue コンストラクタは MessageQueue クラスの新しいインスタンスをインスタンス化します。メッセージ キューの新しいキューは作成しません。
MessageQueue のインスタンスの初期プロパティ値を次の表に示します。



Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


MessageQueue コンストラクタ (String)
アセンブリ: System.Messaging (system.messaging.dll 内)



パス、書式名、ラベルが判明している、メッセージ キューの特定のキューに MessageQueue の新しいインスタンスを結び付ける場合は、このオーバーロードを使用します。キューを参照する最初のアプリケーションに排他アクセス許可を与える場合は、DenySharedReceive プロパティに true を設定するか、読み取りアクセス制限パラメータを渡すコンストラクタを使用する必要があります。
MessageQueue コンストラクタは MessageQueue クラスの新しいインスタンスをインスタンス化します。メッセージ キューの新しいキューは作成しません。メッセージ キューに新しいキューを作成するには、Create(String) を使用します。
path パラメータの構文は、参照するキューの種類によって異なります。詳細については、次の表を参照してください。
MachineName\QueueName | |
MachineName\Private$\QueueName | |
MachineName\QueueName\Journal$ | |
MachineName\Journal$ | |
MachineName\Deadletter$ | |
MachineName\XactDeadletter$ |
代わりに、FormatName または Label を使用してキューのパスを記述することもできます。詳細については、次の表を参照してください。
例 | ||
---|---|---|
書式名 | FormatName:Public= 5A5F7535-AE9A-41d4-935C-845C2AFF7112 FormatName:DIRECT=SPX: NetworkNumber; HostNumber\QueueName | |
Label: TheLabel |
オフラインで作業をするには、パス名構文ではなく書式名構文をコンストラクタで使用する必要があります。パス名構文を使用すると、パスを書式名に解決するプライマリ ドメイン コントローラが利用できないため、例外がスローされます。
MessageQueue のインスタンスの初期プロパティ値を次の表に示します。これらの値は、path パラメータで指定されたパスのメッセージ キューのキュー プロパティに基づきます。
Authenticate | |
BasePriority | 0 |
DefaultPropertiesToSend | |
EncryptionRequired | |
XmlMessageFormatter | |
MachineName | |
MaximumJournalSize | InfiniteQueueSize |
MaximumQueueSize | InfiniteQueueSize |
MessageReadPropertyFilter | |
QueueName | |
DenySharedReceive | |
UseJournalQueue |
Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows CE プラットフォームメモ : デバイスで Active Directory がサポートされないため、.NET Compact Framework ではリモート キューがトランザクションかどうかを確認できません。リモート トランザクション キューにメッセージを送信するには、コンストラクタに渡す path パラメータに ;XACTONLY を付加します。詳細については、「.NET Compact Framework の MSMQ」を参照してください。

さまざまな種類のパス名構文を使用して、新しい MessageQueue オブジェクトを作成するコード例を次に示します。いずれの場合も、コンストラクタでパスが定義されているキューにメッセージを送信します。
Imports System Imports System.Messaging Public Class MyNewQueue ' Provides an entry point into the application. ' ' This example demonstrates several ways to set ' a queue's path. Public Shared Sub Main() ' Create a new instance of the class. Dim myNewQueue As New MyNewQueue() myNewQueue.SendPublic() myNewQueue.SendPrivate() myNewQueue.SendByLabel() myNewQueue.SendByFormatName() myNewQueue.MonitorComputerJournal() myNewQueue.MonitorQueueJournal() myNewQueue.MonitorDeadLetter() myNewQueue.MonitorTransactionalDeadLetter() Return End Sub 'Main ' References public queues. Public Sub SendPublic() Dim myQueue As New MessageQueue(".\myQueue") myQueue.Send("Public queue by path name.") Return End Sub 'SendPublic ' References private queues. Public Sub SendPrivate() Dim myQueue As New MessageQueue(".\Private$\myQueue") myQueue.Send("Private queue by path name.") Return End Sub 'SendPrivate ' References queues by label. Public Sub SendByLabel() Dim myQueue As New MessageQueue("Label:TheLabel") myQueue.Send("Queue by label.") Return End Sub 'SendByLabel ' References queues by format name. Public Sub SendByFormatName() Dim myQueue As New _ MessageQueue("FormatName:Public=" + _ "5A5F7535-AE9A-41d4-935C-845C2AFF7112") myQueue.Send("Queue by format name.") Return End Sub 'SendByFormatName ' References computer journal queues. Public Sub MonitorComputerJournal() Dim computerJournal As New MessageQueue(".\Journal$") While True Dim journalMessage As Message = _ computerJournal.Receive() ' Process the journal message. End While Return End Sub 'MonitorComputerJournal ' References queue journal queues. Public Sub MonitorQueueJournal() Dim queueJournal As New _ MessageQueue(".\myQueue\Journal$") While True Dim journalMessage As Message = _ queueJournal.Receive() ' Process the journal message. End While Return End Sub 'MonitorQueueJournal ' References dead-letter queues. Public Sub MonitorDeadLetter() Dim deadLetter As New MessageQueue(".\DeadLetter$") While True Dim deadMessage As Message = deadLetter.Receive() ' Process the dead-letter message. End While Return End Sub 'MonitorDeadLetter ' References transactional dead-letter queues. Public Sub MonitorTransactionalDeadLetter() Dim TxDeadLetter As New MessageQueue(".\XactDeadLetter$") While True Dim txDeadLetterMessage As Message = _ TxDeadLetter.Receive() ' Process the transactional dead-letter message. End While Return End Sub 'MonitorTransactionalDeadLetter End Class 'MyNewQueue
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 demonstrates several ways to set // a queue's path. //************************************************** public static void Main() { // Create a new instance of the class. MyNewQueue myNewQueue = new MyNewQueue(); myNewQueue.SendPublic(); myNewQueue.SendPrivate(); myNewQueue.SendByLabel(); myNewQueue.SendByFormatName(); myNewQueue.MonitorComputerJournal(); myNewQueue.MonitorQueueJournal(); myNewQueue.MonitorDeadLetter(); myNewQueue.MonitorTransactionalDeadLetter(); return; } // References public queues. public void SendPublic() { MessageQueue myQueue = new MessageQueue(".\\myQueue"); myQueue.Send("Public queue by path name."); return; } // References private queues. public void SendPrivate() { MessageQueue myQueue = new MessageQueue(".\\Private$\\myQueue"); myQueue.Send("Private queue by path name."); return; } // References queues by label. public void SendByLabel() { MessageQueue myQueue = new MessageQueue("Label:TheLabel"); myQueue.Send("Queue by label."); return; } // References queues by format name. public void SendByFormatName() { MessageQueue myQueue = new MessageQueue("FormatName:Public=5A5F7535-AE9A-41d4" + "-935C-845C2AFF7112"); myQueue.Send("Queue by format name."); return; } // References computer journal queues. public void MonitorComputerJournal() { MessageQueue computerJournal = new MessageQueue(".\\Journal$"); while(true) { Message journalMessage = computerJournal.Receive(); // Process the journal message. } } // References queue journal queues. public void MonitorQueueJournal() { MessageQueue queueJournal = new MessageQueue(".\\myQueue\\Journal$"); while(true) { Message journalMessage = queueJournal.Receive(); // Process the journal message. } } // References dead-letter queues. public void MonitorDeadLetter() { MessageQueue deadLetter = new MessageQueue(".\\DeadLetter$"); while(true) { Message deadMessage = deadLetter.Receive(); // Process the dead-letter message. } } // References transactional dead-letter queues. public void MonitorTransactionalDeadLetter() { MessageQueue TxDeadLetter = new MessageQueue(".\\XactDeadLetter$"); while(true) { Message txDeadLetter = TxDeadLetter.Receive(); // Process the transactional dead-letter message. } } } }
#using <system.dll> #using <system.messaging.dll> using namespace System; using namespace System::Messaging; ref class MyNewQueue { public: // References public queues. void SendPublic() { MessageQueue^ myQueue = gcnew MessageQueue( ".\\myQueue" ); myQueue->Send( "Public queue by path name." ); return; } // References private queues. void SendPrivate() { MessageQueue^ myQueue = gcnew MessageQueue( ".\\Private$\\myQueue" ); myQueue->Send( "Private queue by path name." ); return; } // References queues by label. void SendByLabel() { MessageQueue^ myQueue = gcnew MessageQueue( "Label:TheLabel" ); myQueue->Send( "Queue by label." ); return; } // References queues by format name. void SendByFormatName() { MessageQueue^ myQueue = gcnew MessageQueue( "FormatName:Public=5A5F7535-AE9A-41d4 -935C-845C2AFF7112" ); myQueue->Send( "Queue by format name." ); return; } // References computer journal queues. void MonitorComputerJournal() { MessageQueue^ computerJournal = gcnew MessageQueue( ".\\Journal$" ); while ( true ) { Message^ journalMessage = computerJournal->Receive(); // Process the journal message. } } // References queue journal queues. void MonitorQueueJournal() { MessageQueue^ queueJournal = gcnew MessageQueue( ".\\myQueue\\Journal$" ); while ( true ) { Message^ journalMessage = queueJournal->Receive(); // Process the journal message. } } // References dead-letter queues. void MonitorDeadLetter() { MessageQueue^ deadLetter = gcnew MessageQueue( ".\\DeadLetter$" ); while ( true ) { Message^ deadMessage = deadLetter->Receive(); // Process the dead-letter message. } } // References transactional dead-letter queues. void MonitorTransactionalDeadLetter() { MessageQueue^ TxDeadLetter = gcnew MessageQueue( ".\\XactDeadLetter$" ); while ( true ) { Message^ txDeadLetter = TxDeadLetter->Receive(); // Process the transactional dead-letter message. } } }; //************************************************* // Provides an entry point into the application. // // This example demonstrates several ways to set // a queue's path. //************************************************* int main() { // Create a new instance of the class. MyNewQueue^ myNewQueue = gcnew MyNewQueue; myNewQueue->SendPublic(); myNewQueue->SendPrivate(); myNewQueue->SendByLabel(); myNewQueue->SendByFormatName(); myNewQueue->MonitorComputerJournal(); myNewQueue->MonitorQueueJournal(); myNewQueue->MonitorDeadLetter(); myNewQueue->MonitorTransactionalDeadLetter(); return 0; }
package MyProject; import System.*; import System.Messaging.*; /// <summary> /// Provides a container class for the example. /// </summary> public class MyNewQueue { //************************************************** // Provides an entry point into the application. // // This example demonstrates several ways to set // a queue's path. //************************************************** public static void main(String[] args) { // Create a new instance of the class. MyNewQueue myNewQueue = new MyNewQueue(); myNewQueue.SendPublic(); myNewQueue.SendPrivate(); myNewQueue.SendByLabel(); myNewQueue.SendByFormatName(); myNewQueue.MonitorComputerJournal(); myNewQueue.MonitorQueueJournal(); myNewQueue.MonitorDeadLetter(); myNewQueue.MonitorTransactionalDeadLetter(); return; } //main // References public queues. public void SendPublic() { MessageQueue myQueue = new MessageQueue(".\\myQueue"); myQueue.Send("Public queue by path name."); return; } //SendPublic // References private queues. public void SendPrivate() { MessageQueue myQueue = new MessageQueue(".\\Private$\\myQueue"); myQueue.Send("Private queue by path name."); return; } //SendPrivate // References queues by label. public void SendByLabel() { MessageQueue myQueue = new MessageQueue("Label:TheLabel"); myQueue.Send("Queue by label."); return; } //SendByLabel // References queues by format name. public void SendByFormatName() { MessageQueue myQueue = new MessageQueue("FormatName:Public=5A5F7535-AE9A-41d4" + "-935C-845C2AFF7112"); myQueue.Send("Queue by format name."); return; } //SendByFormatName // References computer journal queues. public void MonitorComputerJournal() { MessageQueue computerJournal = new MessageQueue(".\\Journal$"); while (true) { Message journalMessage = computerJournal.Receive(); // Process the journal message. } } //MonitorComputerJournal // References queue journal queues. public void MonitorQueueJournal() { MessageQueue queueJournal = new MessageQueue(".\\myQueue\\Journal$"); while (true) { Message journalMessage = queueJournal.Receive(); // Process the journal message. } } //MonitorQueueJournal // References dead-letter queues. public void MonitorDeadLetter() { MessageQueue deadLetter = new MessageQueue(".\\DeadLetter$"); while (true) { Message deadMessage = deadLetter.Receive(); // Process the dead-letter message. } } //MonitorDeadLetter // References transactional dead-letter queues. public void MonitorTransactionalDeadLetter() { MessageQueue objTxDeadLetter = new MessageQueue(".\\XactDeadLetter$"); while (true) { Message txDeadLetter = objTxDeadLetter.Receive(); // Process the transactional dead-letter message. } } //MonitorTransactionalDeadLetter } //MyNewQueue


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


MessageQueue コンストラクタ (String, Boolean)
アセンブリ: System.Messaging (system.messaging.dll 内)

Dim path As String Dim sharedModeDenyReceive As Boolean Dim instance As New MessageQueue(path, sharedModeDenyReceive)


パス、書式名、ラベルが判明している、メッセージ キューの特定のキューに新しい MessageQueue を結び付ける場合は、このオーバーロードを使用します。キューを参照する最初のアプリケーションに排他アクセス許可を与える場合は、sharedModeDenyReceive パラメータに true を設定します。それ以外の場合は、sharedModeDenyReceive に false を設定するか、path パラメータだけを指定するコンストラクタを使用します。
sharedModeDenyReceive に true を設定すると、他のアプリケーションも含めて、そのメッセージ キューのキューにアクセスするすべてのオブジェクトが影響を受けます。パラメータの影響は、このアプリケーションだけにとどまりません。
MessageQueue コンストラクタは MessageQueue クラスの新しいインスタンスを作成します。メッセージ キューの新しいキューは作成しません。メッセージ キューに新しいキューを作成するには、Create(String) を使用します。
path パラメータの構文は、キューの種類によって異なります。
MachineName\QueueName | |
MachineName\Private$\QueueName | |
MachineName\QueueName\Journal$ | |
MachineName\Journal$ | |
MachineName\Deadletter$ | |
MachineName\XactDeadletter$ |
メッセージ キューのキューの書式名またはラベルを使用してキューのパスを記述することもできます。
例 | ||
---|---|---|
書式名 | FormatName:Public= 5A5F7535-AE9A-41d4-935C-845C2AFF7112 FormatName:DIRECT=SPX: NetworkNumber; HostNumber\QueueName | |
Label: TheLabel |
オフラインで作業をするには、表示名の構文ではなく書式名構文を使用する必要があります。表示名の構文を使用すると、パスを書式名に解決するプライマリ ドメイン コントローラ (Active Directory が常駐) が利用できないため、例外がスローされます
MessageQueue が sharedModeDenyReceive パラメータに true を設定してキューを開くと、そのキューから読み取ろうとするあらゆる MessageQueue は、共有違反のため MessageQueueException を生成します。既に MessageQueue が非排他モードでキューにアクセスしているときに、別の MessageQueue が排他モードでそのキューにアクセスしようとした場合にも、MessageQueueException がスローされます。
MessageQueue のインスタンスの初期プロパティ値を次の表に示します。これらの値は、path パラメータで指定されたパスのメッセージ キューのキュー プロパティに基づきます。
Authenticate | |
BasePriority | 0 |
DefaultPropertiesToSend | |
EncryptionRequired | |
XmlMessageFormatter | |
MachineName | |
MaximumJournalSize | InfiniteQueueSize |
MaximumQueueSize | InfiniteQueueSize |
MessageReadPropertyFilter | |
QueueName | |
DenySharedReceive | sharedModeDenyReceive パラメータの値。 |
UseJournalQueue |

新しい MessageQueue を排他アクセスで作成し、パスを設定し、メッセージをキューに送信するコード例を次に示します。
Imports System Imports System.Messaging Public Class MyNewQueue ' Provides an entry point into the application. ' ' This example connects to a message queue, and ' requests exclusive read access to the queue. Public Shared Sub Main() ' Create a new instance of the class. Dim myNewQueue As New MyNewQueue() ' Output the count of Lowest priority messages. myNewQueue.GetExclusiveAccess() Return End Sub 'Main ' Requests exlusive read access to the queue. If ' access is granted, receives a message from the ' queue. Public Sub GetExclusiveAccess() Try ' Request exclusive read access to the queue. Dim myQueue As New MessageQueue(".\myQueue", True) ' Receive a message. This is where a SharingViolation ' exception would be thrown. Dim myMessage As Message = myQueue.Receive() Catch e As MessageQueueException ' Handle request for denial of exclusive read access. If e.MessageQueueErrorCode = _ MessageQueueErrorCode.SharingViolation Then Console.WriteLine("Denied exclusive read access.") End If ' Handle other sources of a MessageQueueException. ' Handle other exceptions as necessary. End Try Return End Sub 'GetExclusiveAccess End Class 'MyNewQueue
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 connects to a message queue, and // requests exclusive read access to the queue. //************************************************** public static void Main() { // Create a new instance of the class. MyNewQueue myNewQueue = new MyNewQueue(); // Output the count of Lowest priority messages. myNewQueue.GetExclusiveAccess(); return; } //************************************************** // Requests exlusive read access to the queue. If // access is granted, receives a message from the // queue. //************************************************** public void GetExclusiveAccess() { try { // Request exclusive read access to the queue. MessageQueue myQueue = new MessageQueue(".\\myQueue", true); // Receive a message. This is where SharingViolation // exceptions would be thrown. Message myMessage = myQueue.Receive(); } catch (MessageQueueException e) { // Handle request for denial of exclusive read access. if (e.MessageQueueErrorCode == MessageQueueErrorCode.SharingViolation) { Console.WriteLine("Denied exclusive read access"); } // Handle other sources of a MessageQueueException. } // Handle other exceptions as necessary. return; } } }
#using <system.dll> #using <system.messaging.dll> using namespace System; using namespace System::Messaging; ref class MyNewQueue { public: // Requests exlusive read access to the queue. If // access is granted, receives a message from the // queue. void GetExclusiveAccess() { try { // Request exclusive read access to the queue. MessageQueue^ myQueue = gcnew MessageQueue( ".\\myQueue",true ); // Receive a message. This is where SharingViolation // exceptions would be thrown. Message^ myMessage = myQueue->Receive(); } catch ( MessageQueueException^ e ) { // Handle request for denial of exclusive read access. if ( e->MessageQueueErrorCode == MessageQueueErrorCode::SharingViolation ) { Console::WriteLine( "Denied exclusive read access" ); } // Handle other sources of a MessageQueueException. } // Handle other exceptions as necessary. return; } }; // Provides an entry point into the application. // This example connects to a message queue, and // requests exclusive read access to the queue. int main() { // Create a new instance of the class. MyNewQueue^ myNewQueue = gcnew MyNewQueue; // Output the count of Lowest priority messages. myNewQueue->GetExclusiveAccess(); return 0; }
package MyProject; import System.*; import System.Messaging.*; /// <summary> /// Provides a container class for the example. /// </summary> public class MyNewQueue { //************************************************** // Provides an entry point into the application. // // This example connects to a message queue, and // requests exclusive read access to the queue. //************************************************** public static void main(String[] args) { // Create a new instance of the class. MyNewQueue myNewQueue = new MyNewQueue(); // Output the count of Lowest priority messages. myNewQueue.GetExclusiveAccess(); return; } //main //************************************************** // Requests exlusive read access to the queue. If // access is granted, receives a message from the // queue. //************************************************** public void GetExclusiveAccess() { try { // Request exclusive read access to the queue. MessageQueue myQueue = new MessageQueue(".\\myQueue", true); // Receive a message.This is where SharingViolation // exceptions would be thrown. Message myMessage = myQueue.Receive(); } catch (MessageQueueException e) { // Handle request for denial of exclusive read access. if (e.get_MessageQueueErrorCode(). Equals(MessageQueueErrorCode.SharingViolation)) { Console.WriteLine("Denied exclusive read access"); } // Handle other sources of a MessageQueueException. } // Handle other exceptions as necessary. return; } //GetExclusiveAccess } //MyNewQueue


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


MessageQueue コンストラクタ (String, Boolean, Boolean)
アセンブリ: System.Messaging (system.messaging.dll 内)

Dim path As String Dim sharedModeDenyReceive As Boolean Dim enableCache As Boolean Dim instance As New MessageQueue(path, sharedModeDenyReceive, enableCache)
public function MessageQueue ( path : String, sharedModeDenyReceive : boolean, enableCache : boolean )

排他読み取りアクセスで、接続キャッシュを有効にして、新しい MessageQueue を作成するコード例を次に示します。
// Connect to a queue on the local computer, grant exclusive read // access to the first application that accesses the queue, and // enable connection caching. MessageQueue queue = new MessageQueue(".\\exampleQueue", true, true);


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


MessageQueue コンストラクタ (String, QueueAccessMode)
アセンブリ: System.Messaging (system.messaging.dll 内)

Dim path As String Dim accessMode As QueueAccessMode Dim instance As New MessageQueue(path, accessMode)
- accessMode
QueueAccessMode 値の 1 つ。


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


MessageQueue コンストラクタ (String, Boolean, Boolean, QueueAccessMode)
アセンブリ: System.Messaging (system.messaging.dll 内)

Public Sub New ( _ path As String, _ sharedModeDenyReceive As Boolean, _ enableCache As Boolean, _ accessMode As QueueAccessMode _ )
Dim path As String Dim sharedModeDenyReceive As Boolean Dim enableCache As Boolean Dim accessMode As QueueAccessMode Dim instance As New MessageQueue(path, sharedModeDenyReceive, enableCache, accessMode)
public MessageQueue ( string path, bool sharedModeDenyReceive, bool enableCache, QueueAccessMode accessMode )
public: MessageQueue ( String^ path, bool sharedModeDenyReceive, bool enableCache, QueueAccessMode accessMode )
public MessageQueue ( String path, boolean sharedModeDenyReceive, boolean enableCache, QueueAccessMode accessMode )
public function MessageQueue ( path : String, sharedModeDenyReceive : boolean, enableCache : boolean, accessMode : QueueAccessMode )
- accessMode
QueueAccessMode 値の 1 つ。


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


MessageQueue コンストラクタ

名前 | 説明 |
---|---|
MessageQueue () | MessageQueue クラスの新しいインスタンスを初期化します。既定のコンストラクタが新しいインスタンスを初期化した後、そのインスタンスを使用する前にインスタンスの Path プロパティを設定する必要があります。 .NET Compact Framework によってサポートされています。 |
MessageQueue (String) | 指定したパスのメッセージ キューのキューを参照する MessageQueue クラスの新しいインスタンスを初期化します。 .NET Compact Framework によってサポートされています。 |
MessageQueue (String, Boolean) | 指定した読み取りアクセス制限を持つ指定したパスのメッセージ キューのキューを参照する MessageQueue クラスの新しいインスタンスを初期化します。 .NET Compact Framework によってサポートされています。 |
MessageQueue (String, QueueAccessMode) | MessageQueue クラスの新しいインスタンスを初期化します。 |
MessageQueue (String, Boolean, Boolean) | MessageQueue クラスの新しいインスタンスを初期化します。 |
MessageQueue (String, Boolean, Boolean, QueueAccessMode) | MessageQueue クラスの新しいインスタンスを初期化します。 |

MessageQueue フィールド
MessageQueue プロパティ

名前 | 説明 | |
---|---|---|
![]() | AccessMode | キューのアクセス モードを示す値を取得します。 |
![]() | Authenticate | キューが認証済みメッセージだけを受け入れるかどうかを示す値を取得または設定します。 |
![]() ![]() ![]() ![]() ![]() | Container | Component を格納している IContainer を取得します。 ( Component から継承されます。) |
![]() | Site | Component の ISite を取得または設定します。 ( Component から継承されます。) |
![]() | WriteHandle | メッセージ キューにメッセージを送信するときに使用するネイティブ ハンドルを取得します。 |

名前 | 説明 | |
---|---|---|
![]() | CanRaiseEvents | コンポーネントがイベントを発生させることがきるかどうかを示す値を取得します。 ( Component から継承されます。) |
![]() | DesignMode | Component が現在デザイン モードかどうかを示す値を取得します。 ( Component から継承されます。) |
![]() | Events | Component に結び付けられているイベント ハンドラのリストを取得します。 ( Component から継承されます。) |

MessageQueue メソッド


名前 | 説明 | |
---|---|---|
![]() | Dispose | オーバーロードされます。 オーバーライドされます。 MessageQueue で使用されていたリソース (メモリを除く) を解放します。 |
![]() | Finalize | Component がガベージ コレクションによってクリアされる前に、アンマネージ リソースを解放し、その他のクリーンアップ操作を実行します。 ( Component から継承されます。) |
![]() | GetService | Component またはその Container で提供されるサービスを表すオブジェクトを返します。 ( Component から継承されます。) |
![]() | MemberwiseClone | オーバーロードされます。 ( MarshalByRefObject から継承されます。) |

MessageQueue メンバ
メッセージ キューサーバーのキューにアクセスできるようにします。
MessageQueue データ型で公開されるメンバを以下の表に示します。



名前 | 説明 | |
---|---|---|
![]() | AccessMode | キューのアクセス モードを示す値を取得します。 |
![]() | Authenticate | キューが認証済みメッセージだけを受け入れるかどうかを示す値を取得または設定します。 |
![]() ![]() ![]() ![]() ![]() | Container | Component を格納している IContainer を取得します。(Component から継承されます。) |
![]() | Site | Component の ISite を取得または設定します。(Component から継承されます。) |
![]() | WriteHandle | メッセージ キューにメッセージを送信するときに使用するネイティブ ハンドルを取得します。 |

名前 | 説明 | |
---|---|---|
![]() | CanRaiseEvents | コンポーネントがイベントを発生させることがきるかどうかを示す値を取得します。(Component から継承されます。) |
![]() | DesignMode | Component が現在デザイン モードかどうかを示す値を取得します。(Component から継承されます。) |
![]() | Events | Component に結び付けられているイベント ハンドラのリストを取得します。(Component から継承されます。) |


名前 | 説明 | |
---|---|---|
![]() | Dispose | オーバーロードされます。 オーバーライドされます。 MessageQueue で使用されていたリソース (メモリを除く) を解放します。 |
![]() | Finalize | Component がガベージ コレクションによってクリアされる前に、アンマネージ リソースを解放し、その他のクリーンアップ操作を実行します。 (Component から継承されます。) |
![]() | GetService | Component またはその Container で提供されるサービスを表すオブジェクトを返します。 (Component から継承されます。) |
![]() | MemberwiseClone | オーバーロードされます。 ( MarshalByRefObject から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Disposed | コンポーネントの Disposed イベントを待機するイベント ハンドラを追加します。(Component から継承されます。) |
![]() | PeekCompleted | キューから削除せずにメッセージを読み取ると発生します。この発生は、非同期操作 BeginPeek の結果です。 |
![]() | ReceiveCompleted | メッセージがキューから削除されると発生します。このイベントは、非同期操作 BeginReceive によって発生します。 |

メッセージキュー
メッセージキュー(英: Message queue)は、プロセス間通信や同一プロセス内のスレッド間通信に使われるソフトウェアコンポーネントである。制御やデータを伝達するメッセージのキューである。
概要
メッセージキューは非同期型通信プロトコルの一種を提供しており、送信側と受信側がメッセージキューに同時にやり取りしなくともよいことを意味する。キューに置かれるメッセージは、受信側がそれを取り出すまで格納されたままとなる。メッセージキューは大抵の場合、格納できる1つのメッセージの大きさや保持できるメッセージ数に上限を設けている。
メッセージキューには様々な実装がある。オペレーティングシステム内に実装される場合やアプリケーションソフトウェア内に実装される場合がある。それらのキューはそのシステムが必要とする用途でのみ使われる[1][2][3]。
その他の実装では、コンピュータ間のメッセージのやり取りに使われたり、複数のアプリケーションや複数のオペレーティングシステム間の接続に使われたりする[4]。このようなメッセージキューシステムでは、システムの障害が発生してもメッセージを無くしたりしないような「回復力; resilience」のある機能が提供されることが多い。この種のメッセージキューを実装した商用ソフトウェア(メッセージ指向ミドルウェアとも呼ぶ)として、IBM の WebSphere MQ、オラクルの Oracle Database に含まれる Oracle Advanced Queuing (AQ)、マイクロソフトの MSMQ、日立製作所のTP1/MessageQueue、セゾン情報システムズのHULFT-Message などがある。Java の関連する標準として Java Message Service があり、これにはオープンソースのものもプロプライエタリのものも含めていくつかの実装がある。
メッセージ関連のミドルウェアシステムとして、いくつかのオープンソースのものがある。例えば、JBoss Messaging、JORAM、Apache ActiveMQ、Apache Qpid[5]、RabbitMQ、Skytools PgQ 、Mule、OpenMQなどである。
VxWorksやQNXといったリアルタイムオペレーティングシステム (RTOS) では、メッセージキューを主要なプロセス間通信機構やスレッド間通信機構として採用している。これらの場合、リアルタイム性が重視されるため、メッセージキューとCPUスケジューリングが密に関連している。1980年代初期には、VRTX や pSOS+ といった RTOS でメッセージキューを使ったスレッド間通信機構が使われ始めた。
利用
典型的なメッセージキューの実装では、システムアドミニストレータがメッセージキューソフトウェア(キューマネージャ)をインストール・設定し、名前のついたメッセージキューを定義する。アプリケーションは、そのキューにメッセージが置かれるのを待つソフトウェアルーチン(リスナー)を登録する。別の(複数の)アプリケーションがそのキューに接続し、メッセージをそこに転送する。キューマネージャは受信側アプリケーションが接続するまでメッセージを蓄積しておき、接続した時点で登録されたソフトウェアルーチンを呼び出す。受信アプリケーションは適切な方法でメッセージを処理する。
これには様々なバリエーションが存在する。例えば、次のような点である。
- 永続性(キューをメモリ上に置くか、ディスク上に置くか。さらに安全性を高めるためにDBMSに置くこともある)
- セキュリティポリシー - メッセージへのアプリケーションのアクセス権の認証
- メッセージ消去ポリシー - キューやメッセージに生存時間 (time to live) が設定される場合がある。
- システムによってはデータのフィルタリングをサポートしており、受信側は事前に設定した基準に合致したメッセージだけを受け取る。
- 配布ポリシー - 1つのメッセージが少なくとも1度配布されることを保証するか、それとも複数回配布されないことを保証するか。
- ルーティングポリシー - キュー(サーバ)が複数存在する場合、それらの間のメッセージの受け渡しをどうするか。
- バッチポリシー - メッセージは即時に配布されるか。それとも、短時間待って溜まったメッセージを1度に配布するか。
- メッセージが「エンキュー; enqueue」されたというのはどういう場合を指すか。どこかのキューに置かれた場合全てを指すか。それとも、少なくとも1つのリモートのキューに置かれた場合を指すか。あるいは、全てのキューに置かれた場合を指すか。
- 送信側は(一部あるいは全部の)受信側がメッセージを受け取ったことを知る必要があるかどうか。
これらは、システムとしての意味論、信頼性、効率などを具体的にどうするかといった設計上の考慮すべき点である。
標準とプロトコル
歴史的には、メッセージキューはプロプライエタリな閉鎖的プロトコルとして使われ始めたもので、そのために異なるOSやプログラミング言語を含めた環境の構築が制限されていた。
メッセージキューをより遍在的にする初期の試みとして、サン・マイクロシステムズのJMS仕様があり、JavaによってクライアントAPIを抽象化して異機種間接続を可能にしていた。これによりJavaを使えばメッセージキューのプロバイダーを切り替え可能となっており、SQLによってデータベースの切り替えが可能になったのと似ている。しかし実際にはメッセージキューの技法やシナリオは非常に多様であり、JMSが常に有効というわけではない。
その後、メッセージキューをオープンで遍在的なものにすべく以下の標準が生まれている。
- Advanced Message Queuing Protocol
- Streaming Text Oriented Messaging Protocol
これらの標準化や採用の段階はそれぞれ異なる。いずれもHTTPと同じレベルで運用される。
プロプライエタリな実装でもHTTPを使ってメッセージキューを提供している場合があり、例えばAmazonのSQSがある。これは、要求-応答型の同期プロトコルの上で(メッセージキューに必要とされる)非同期動作の層を構築することが可能なためである。しかし、そのような実装は下層のプロトコルに制限され、上述したようなメッセージキューのあらゆるオプションを提供できない可能性がある。
同期と非同期
多くの通信プロトコルは、同期型である。World Wide WebやWebサービスで使われている HTTP などは明らかに同期型である。同期モデルでは、あるシステムが別のシステムとのコネクションを形成し、要求を送って、応答を待つ。多くの場合、これで全く問題ない。例えば、ユーザーが Web ページに要求を送り、応答を待つというような場合である。
しかし、このようなシナリオではうまくいかない場合がある。例えば、AJAX (Asynchronous Javascript and XML) は非同期にテキストやXMLを送って、ウェブページの一部をより適切な情報で更新する。Googleはオートコンプリート機能でこの方式を採用しており、検索ボックスにキーワードの一部を入力した際に考えられるキーワード全体の一覧を提供する。この一覧はユーザーの入力に従って非同期に更新される。
他の非同期な例として、イベント通知システムや出版-購読型システムがある。
- あるアプリケーションが別のアプリケーションにイベント発生を知らせたいが、その応答を待つ必要がない(あるいは待てない)場合
- 出版-購読型モデルのシステムでは、アプリケーションは情報を任意の(不明な個数の)受信者に対して「出版」する。
これらの場合、例えば情報の受け手がクラッシュしてしまっている可能性もあり、送信側が応答を待つのは適切ではない。
アプリケーションは同期または非同期のどちらか一方だけで実装する必要はない。対話型アプリケーションは特定の要求に対して即座に応答する必要があるだろう(顧客に対して、在庫を確認したうえで購入要求が受理されたことを知らせる場合など)。しかし一方で、キューを使って処理を遅延させることが可能な部分もある(請求金額の計算を完了させ、そのデータを中央のデータベースに登録し、関連する他のサービスを実行する)。このような場合に、非同期型のメッセージキューを使えば、システム全体の性能(特に顧客から見た応答性能)を向上させることができる。
脚注
- ^ Win32 system message queues. “About Messages and Message Queues”. Windows User Interface. Microsoft Developer Network. 2010年4月21日閲覧。
- ^ Linux and POSIX message queues. Overview of POSIX message queues at linux.die.net
- ^ Using Linux Message Queues. [1] at www.civilized.com
- ^ 例えば MSMQ がある。“Message Queuing (MSMQ)”. Network Communication. Microsoft Developer Network. 2009年5月9日閲覧。
- ^ Apache Qpid Project, an implementation of AMQP.
関連項目
- Advanced Message Queuing Protocol
- Enterprise Message Service (TIBCO softwire)
- IBM WebSphere MQ
- Java Message Service
- メッセージ指向ミドルウェア
- Microsoft Azure Services Platform - 特に Azure ストレージキューと AppFabric Service Bus
- RabbitMQ
外部リンク
- Minimalist Queue Service (MQS) - Perlで実装されたメッセージキューシステム。単純な XML-RPC による非同期メッセージ処理を実装。
- message queueのページへのリンク