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 為使用格式名稱語法,) 重 MachineName 設 和 QueueName 屬性以參考新的佇列。
或者,您可以使用 FormatName 或 Label 來描述佇列路徑,如下表所示。
參考 | 語法 | 範例 |
---|---|---|
格式名稱 | FormatName: 【 格式名稱 ] |
FormatName:Public= 5A5F7535-AE9A-41d4-935C-845C2AFF7112 |
標籤 | Label: [ 標籤 ] |
Label: TheLabel |
如果您在傳送訊息時使用 屬性的 Path 標籤法,如果 Label 不是唯一的,則會擲回例外狀況。
若要離線運作,您必須使用格式名稱語法,而不是第一個數據表中的易記名稱語法。 否則,會擲回例外狀況,因為 Active Directory 所在的主要域控制器 () 無法解析格式名稱的路徑。
設定新路徑會關閉消息佇列,並釋放所有句柄。
下表顯示此屬性是否可在各種工作組模式中使用。
工作組模式 | 可用 |
---|---|
本機電腦 | 是 |
本機計算機和直接格式名稱 | 是 |
遠端電腦 | 是 |
遠端電腦和直接格式名稱 | 是 |
注意
在工作組模式中,您只能使用私人佇列。 您可以使用私人佇列語法MachineName
Private$
\\QueueName
來指定路徑。