MessageQueue.Path 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置队列的路径。 设置 Path 会导致 MessageQueue 指向新队列。
public:
property System::String ^ Path { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.Browsable(false)]
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
[System.Messaging.MessagingDescription("MQ_Path")]
public string Path { get; set; }
[System.ComponentModel.Browsable(false)]
[System.Messaging.MessagingDescription("MQ_Path")]
[System.ComponentModel.SettingsBindable(true)]
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public string Path { get; set; }
[System.ComponentModel.Browsable(false)]
[System.Messaging.MessagingDescription("MQ_Path")]
[System.ComponentModel.SettingsBindable(true)]
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public string Path { get; set; }
[<System.ComponentModel.Browsable(false)>]
[<System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
[<System.Messaging.MessagingDescription("MQ_Path")>]
member this.Path : string with get, set
[<System.ComponentModel.Browsable(false)>]
[<System.Messaging.MessagingDescription("MQ_Path")>]
[<System.ComponentModel.SettingsBindable(true)>]
[<System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
member this.Path : string with get, set
[<System.ComponentModel.Browsable(false)>]
[<System.Messaging.MessagingDescription("MQ_Path")>]
[<System.ComponentModel.SettingsBindable(true)>]
[<System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
member this.Path : string with get, set
Public Property Path As String
属性值
由 MessageQueue 引用的队列。 默认值取决于所使用的 MessageQueue() 构造函数;它或者是 null
,或者是由构造函数的 path
参数指定的。
- 属性
例外
路径无效,可能是因为语法无效。
示例
下面的代码示例使用各种路径名称语法类型创建新 MessageQueue 对象。 在每种情况下,它都会向在构造函数中定义其路径的队列发送消息。
#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;
}
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.
}
}
}
}
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
' References public queues.
Public Sub SendPublic()
Dim myQueue As New MessageQueue(".\myQueue")
myQueue.Send("Public queue by path name.")
Return
End Sub
' References private queues.
Public Sub SendPrivate()
Dim myQueue As New MessageQueue(".\Private$\myQueue")
myQueue.Send("Private queue by path name.")
Return
End Sub
' References queues by label.
Public Sub SendByLabel()
Dim myQueue As New MessageQueue("Label:TheLabel")
myQueue.Send("Queue by label.")
Return
End Sub
' 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
' 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
' 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
' 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
' 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
End Class
注解
属性的 Path 语法取决于它指向的队列类型,如下表所示。
队列类型 | 语法 |
---|---|
公共队列 | MachineName \QueueName |
专用队列 | MachineName \Private$ \QueueName |
日志队列 | MachineName \QueueName \Journal$ |
计算机日记队列 | MachineName \Journal$ |
计算机死信队列 | MachineName \Deadletter$ |
计算机事务死信队列 | MachineName \XactDeadletter$ |
使用“.”表示本地计算机。
MachineName、 Path和 QueueName 属性是相关的。 更改 属性 MachineName 会导致 Path 属性更改。 它是从新的 MachineName 和 QueueName生成的。 例如,Path将 (更改为使用格式名称语法) 将 和 QueueName 属性重置MachineName为引用新队列。
或者,可以使用 FormatName 或 Label 来描述队列路径,如下表所示。
参考 | 语法 | 示例 |
---|---|---|
格式名 | FormatName: [ 格式名称 ] |
FormatName:Public= 5A5F7535-AE9A-41d4-935C-845C2AFF7112 |
Label | Label: [ label ] |
Label: TheLabel |
如果在发送消息时对 Path 属性使用标签语法,则 如果 Label 不唯一,将引发异常。
若要脱机工作,必须使用格式名称语法,而不是第一个表中的友好名称语法。 否则,将引发异常,因为 Active Directory 所在的主域控制器 () 无法解析格式名称的路径。
设置新路径会关闭消息队列并释放所有句柄。
下表显示了此属性在各种工作组模式下是否可用。
工作组模式 | 可用 |
---|---|
本地计算机 | 是 |
本地计算机和直接格式名称 | 是 |
远程计算机 | 是 |
远程计算机和直接格式名称 | 是 |
注意
在工作组模式下,只能使用专用队列。 使用专用队列语法 MachineName
\\Private$
QueueName
指定路径。