MessageQueue.Create 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
在 Message Queuing 伺服器上的指定路徑建立新的佇列。
多載
Create(String) |
在指定的路徑建立非交易的訊息佇列。 |
Create(String, Boolean) |
在指定的路徑建立交易或非交易的訊息佇列。 |
Create(String)
在指定的路徑建立非交易的訊息佇列。
public:
static System::Messaging::MessageQueue ^ Create(System::String ^ path);
public static System.Messaging.MessageQueue Create (string path);
static member Create : string -> System.Messaging.MessageQueue
Public Shared Function Create (path As String) As MessageQueue
參數
- path
- String
要建立佇列的路徑。
傳回
表示新佇列的 MessageQueue。
例外狀況
path
參數為 null
或空字串 ("")。
範例
下列程式代碼範例會建立公用和私人佇列。 它會將訊息傳送至選取的佇列。
#using <system.dll>
#using <system.messaging.dll>
using namespace System;
using namespace System::Messaging;
// This example creates new public and private queues.
ref class MyNewQueue
{
public:
void CreatePublicQueues()
{
// Create and connect to a public Message Queuing queue.
if ( !MessageQueue::Exists( ".\\newPublicQueue" ) )
{
// Create the queue if it does not exist.
MessageQueue^ myNewPublicQueue = MessageQueue::Create( ".\\newPublicQueue" );
// Send a message to the queue.
myNewPublicQueue->Send( "My message data." );
}
// Create (but do not connect to) a second public queue.
if ( !MessageQueue::Exists( ".\\newPublicResponseQueue" ) )
{
MessageQueue::Create( ".\\newPublicResponseQueue" );
}
return;
}
// Creates private queues and sends a message.
void CreatePrivateQueues()
{
// Create and connect to a private Message Queuing queue.
if ( !MessageQueue::Exists( ".\\Private$\\newPrivQueue" ) )
{
// Create the queue if it does not exist.
MessageQueue^ myNewPrivateQueue = MessageQueue::Create( ".\\Private$\\newPrivQueue" );
// Send a message to the queue.
myNewPrivateQueue->Send( "My message data." );
}
// Create (but do not connect to) a second private queue.
if ( !MessageQueue::Exists( ".\\Private$\\newResponseQueue" ) )
{
MessageQueue::Create( ".\\Private$\\newResponseQueue" );
}
return;
}
};
// Provides an entry point into the application.
int main()
{
// Create a new instance of the class.
MyNewQueue^ myNewQueue = gcnew MyNewQueue;
// Create public and private queues.
myNewQueue->CreatePublicQueues();
myNewQueue->CreatePrivateQueues();
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 creates new public and private
// queues.
//**************************************************
public static void Main()
{
// Create a new instance of the class.
MyNewQueue myNewQueue = new MyNewQueue();
// Create public and private queues.
myNewQueue.CreatePublicQueues();
myNewQueue.CreatePrivateQueues();
return;
}
//**************************************************
// Creates public queues and sends a message.
//**************************************************
public void CreatePublicQueues()
{
// Create and connect to a public Message Queuing queue.
if (!MessageQueue.Exists(".\\newPublicQueue"))
{
// Create the queue if it does not exist.
MessageQueue myNewPublicQueue =
MessageQueue.Create(".\\newPublicQueue");
// Send a message to the queue.
myNewPublicQueue.Send("My message data.");
}
// Create (but do not connect to) a second public queue.
if (!MessageQueue.Exists(".\\newPublicResponseQueue"))
{
MessageQueue.Create(".\\newPublicResponseQueue");
}
return;
}
//**************************************************
// Creates private queues and sends a message.
//**************************************************
public void CreatePrivateQueues()
{
// Create and connect to a private Message Queuing queue.
if (!MessageQueue.Exists(".\\Private$\\newPrivQueue"))
{
// Create the queue if it does not exist.
MessageQueue myNewPrivateQueue =
MessageQueue.Create(".\\Private$\\newPrivQueue");
// Send a message to the queue.
myNewPrivateQueue.Send("My message data.");
}
// Create (but do not connect to) a second private queue.
if (!MessageQueue.Exists(".\\Private$\\newResponseQueue"))
{
MessageQueue.Create(".\\Private$\\newResponseQueue");
}
return;
}
}
}
Imports System.Messaging
' Provides a container class for the example.
Public Class MyNewQueue
' Provides an entry point into the application.
'
' This example creates new public and private
' queues.
Public Shared Sub Main()
' Create a new instance of the class.
Dim myNewQueue As New MyNewQueue()
' Create public and private queues.
myNewQueue.CreatePublicQueues()
myNewQueue.CreatePrivateQueues()
Return
End Sub
' Creates public queues and sends a message.
Public Sub CreatePublicQueues()
' Create and connect to a public Message Queuing queue.
If Not MessageQueue.Exists(".\newPublicQueue") Then
' Create the queue if it does not exist.
Dim myNewPublicQueue As MessageQueue = _
MessageQueue.Create(".\newPublicQueue")
' Send a message to the queue.
myNewPublicQueue.Send("My message data.")
End If
' Create (but do not connect to) a second public queue.
If Not MessageQueue.Exists(".\newPublicResponseQueue") _
Then
MessageQueue.Create(".\newPublicResponseQueue")
End If
Return
End Sub
' Creates private queues and sends a message.
Public Sub CreatePrivateQueues()
' Create and connect to a private Message Queuing queue.
If Not MessageQueue.Exists(".\Private$\newPrivateQueue") _
Then
' Create the queue if it does not exist.
Dim myNewPrivateQueue As MessageQueue = _
MessageQueue.Create(".\Private$\newPrivateQueue")
' Send a message to the queue.
myNewPrivateQueue.Send("My message data.")
End If
' Create (but do not connect to) a second private queue.
If Not MessageQueue.Exists(".\Private$\newResponseQueue") _
Then
MessageQueue.Create(".\Private$\newResponseQueue")
End If
Return
End Sub
End Class
備註
使用此多載來建立非交易式消息佇列佇列隊列。
若要在應用程式中建立 類別的新實例 MessageQueue ,並將它系結至現有的佇列,請使用 建 MessageQueue 構函式。 若要在消息佇列中建立新的佇列,請呼叫 Create(String)。
參數的 path
語法取決於它參考的佇列類型,如下表所示。
佇列類型 | 語法 |
---|---|
公用佇列 | MachineName \QueueName |
私用佇列 | MachineName \Private$ \QueueName |
針對本機計算機使用 “ .” 如需更多語法,請參閱 Path 屬性。
下表顯示此方法是否可在各種工作組模式中使用。
工作組模式 | 可用 |
---|---|
本機電腦 | 是 |
本機計算機和直接格式名稱 | 是 |
遠端電腦 | 否 |
遠端電腦和直接格式名稱 | 否 |
另請參閱
適用於
Create(String, Boolean)
在指定的路徑建立交易或非交易的訊息佇列。
public:
static System::Messaging::MessageQueue ^ Create(System::String ^ path, bool transactional);
public static System.Messaging.MessageQueue Create (string path, bool transactional);
static member Create : string * bool -> System.Messaging.MessageQueue
Public Shared Function Create (path As String, transactional As Boolean) As MessageQueue
參數
- path
- String
要建立佇列的路徑。
- transactional
- Boolean
true
表示建立交易式佇列,false
表示建立非交易式佇列。
傳回
表示新佇列的 MessageQueue。
例外狀況
path
參數為 null
或空字串 ("")。
範例
下列程式代碼範例會建立公用和私人交易式佇列。 它會將訊息傳送至選取的佇列。
#using <system.dll>
#using <system.messaging.dll>
using namespace System;
using namespace System::Messaging;
ref class MyNewQueue
{
public:
// Creates public transactional queues and sends a
// message.
void CreatePublicTransactionalQueues()
{
// Create and connect to a public message Queuing queue.
if ( !MessageQueue::Exists( ".\\newPublicTransQueue1" ) )
{
// Create the queue if it does not exist.
MessageQueue::Create( ".\\newPublicTransQueue1", true );
}
// Connect to the queue.
MessageQueue^ myNewPublicQueue = gcnew MessageQueue( ".\\newPublicTransQueue1" );
// Create a transaction.
MessageQueueTransaction^ myTransaction = gcnew MessageQueueTransaction;
// Begin the transaction.
myTransaction->Begin();
// Send the message.
myNewPublicQueue->Send( "My Message Data.", myTransaction );
// Commit the transaction.
myTransaction->Commit();
if ( !MessageQueue::Exists( ".\\newPublicTransQueue2" ) )
{
// Create (but do not connect to) second public queue
MessageQueue::Create( ".\\newPublicTransQueue2", true );
}
return;
}
// Creates private queues and sends a message.
void CreatePrivateTransactionalQueues()
{
// Create and connect to a private Message Queuing queue.
if ( !MessageQueue::Exists( ".\\Private$\\newPrivTransQ1" ) )
{
// Create the queue if it does not exist.
MessageQueue^ myNewPrivateQueue = MessageQueue::Create( ".\\Private$\\newPrivTransQ1", true );
}
// Connect to the queue.
MessageQueue^ myNewPrivateQueue = gcnew MessageQueue( ".\\Private$\\newPrivTransQ1" );
// Create a transaction.
MessageQueueTransaction^ myTransaction = gcnew MessageQueueTransaction;
// Begin the transaction.
myTransaction->Begin();
// Send the message.
myNewPrivateQueue->Send( "My Message Data.", myTransaction );
// Commit the transaction.
myTransaction->Commit();
// Create (but do not connect to) a second private queue.
if ( !MessageQueue::Exists( ".\\Private$\\newPrivTransQ2" ) )
{
MessageQueue::Create( ".\\Private$\\newPrivTransQ2", true );
}
return;
}
};
// Provides an entry point into the application.
// This example creates new transactional queues.
int main()
{
// Create a new instance of the class.
MyNewQueue^ myNewQueue = gcnew MyNewQueue;
// Create transactional queues.
myNewQueue->CreatePublicTransactionalQueues();
myNewQueue->CreatePrivateTransactionalQueues();
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 creates new transactional queues.
//**************************************************
public static void Main()
{
// Create a new instance of the class.
MyNewQueue myNewQueue = new MyNewQueue();
// Create transactional queues.
myNewQueue.CreatePublicTransactionalQueues();
myNewQueue.CreatePrivateTransactionalQueues();
return;
}
//**************************************************
// Creates public transactional queues and sends a
// message.
//**************************************************
public void CreatePublicTransactionalQueues()
{
// Create and connect to a public Message Queuing queue.
if (!MessageQueue.Exists(".\\newPublicTransQueue1"))
{
// Create the queue if it does not exist.
MessageQueue.Create(".\\newPublicTransQueue1", true);
}
// Connect to the queue.
MessageQueue myNewPublicQueue =
new MessageQueue(".\\newPublicTransQueue1");
// Send a message to the queue.
// Create a transaction.
MessageQueueTransaction myTransaction = new
MessageQueueTransaction();
// Begin the transaction.
myTransaction.Begin();
// Send the message.
myNewPublicQueue.Send("My Message Data.", myTransaction);
// Commit the transaction.
myTransaction.Commit();
if (!MessageQueue.Exists(".\\newPublicTransQueue2"))
{
// Create (but do not connect to) second public queue.
MessageQueue.Create(".\\newPublicTransQueue2", true);
}
return;
}
//**************************************************
// Creates private queues and sends a message.
//**************************************************
public void CreatePrivateTransactionalQueues()
{
// Create and connect to a private Message Queuing queue.
if (!MessageQueue.Exists(".\\Private$\\newPrivTransQ1"))
{
// Create the queue if it does not exist.
MessageQueue.Create(".\\Private$\\newPrivTransQ1", true);
}
// Connect to the queue.
MessageQueue myNewPrivateQueue =
new MessageQueue(".\\Private$\\newPrivTransQ1");
// Send a message to the queue.
// Create a transaction.
MessageQueueTransaction myTransaction = new
MessageQueueTransaction();
// Begin the transaction.
myTransaction.Begin();
// Send the message.
myNewPrivateQueue.Send("My Message Data.", myTransaction);
// Commit the transaction.
myTransaction.Commit();
// Create (but do not connect to) a second private queue.
if (!MessageQueue.Exists(".\\Private$\\newPrivTransQ2"))
{
MessageQueue.Create(".\\Private$\\newPrivTransQ2",
true);
}
return;
}
}
}
Imports System.Messaging
Public Class MyNewQueue
' Provides an entry point into the application.
'
' This example creates new transactional queues.
Public Shared Sub Main()
' Create a new instance of the class.
Dim myNewQueue As New MyNewQueue
' Create transactional queues.
myNewQueue.CreatePublicTransactionalQueues()
myNewQueue.CreatePrivateTransactionalQueues()
Return
End Sub
' Creates public transactional queues and sends a
' message.
Public Sub CreatePublicTransactionalQueues()
' Create and connect to a public Message Queuing queue.
If Not MessageQueue.Exists(".\newPublicTransQueue1") Then
' Create the queue if it does not exist.
MessageQueue.Create(".\newPublicTransQueue1", True)
End If
' Connect to the queue.
Dim myNewPublicQueue As New MessageQueue(".\newPublicTransQueue1")
' Create a transaction.
Dim myTransaction As New MessageQueueTransaction
' Begin the transaction.
myTransaction.Begin()
' Send the message.
myNewPublicQueue.Send("My Message Data.", myTransaction)
' Commit the transaction.
myTransaction.Commit()
If Not MessageQueue.Exists(".\newPublicTransQueue2") Then
' Create (but do not connect to) a second queue.
MessageQueue.Create(".\newPublicTransQueue2", True)
End If
Return
End Sub
' Creates private queues and sends a message.
Public Sub CreatePrivateTransactionalQueues()
' Create and connect to a private Message Queuing queue.
If Not MessageQueue.Exists(".\Private$\newPrivTransQ1") _
Then
' Create the queue if it does not exist.
MessageQueue.Create(".\Private$\newPrivTransQ1", True)
End If
' Connect to the queue.
Dim myNewPrivateQueue As New MessageQueue(".\Private$\newPrivTransQ1")
' Create a transaction.
Dim myTransaction As New MessageQueueTransaction
' Begin the transaction.
myTransaction.Begin()
' Send the message.
myNewPrivateQueue.Send("My Message Data.", myTransaction)
' Commit the transaction.
myTransaction.Commit()
' Create (but do not connect to) a second private queue.
If Not MessageQueue.Exists(".\Private$\newPrivTransQ2") _
Then
MessageQueue.Create(".\Private$\newPrivTransQ2", True)
End If
Return
End Sub
End Class
備註
您可以使用此多載在消息佇列中建立交易佇列。 您可以藉由將 參數設定 transactional
為 false
或呼叫 的其他多載 Create(String),來建立非交易式佇列。
若要在應用程式中建立 類別的新實例 MessageQueue ,並將它系結至現有的佇列,請使用 建 MessageQueue 構函式。 若要在消息佇列中建立新的佇列,請呼叫 Create(String)。
參數的 path
語法取決於它參考的佇列類型,如下表所示。
佇列類型 | 語法 |
---|---|
公用佇列 | MachineName \QueueName |
私用佇列 | MachineName \Private$ \QueueName |
針對本機計算機使用 “ .” 如需更多語法,請參閱 Path 屬性。
下表顯示此方法是否可在各種工作組模式中使用。
工作組模式 | 可用 |
---|---|
本機電腦 | 是 |
本機計算機和直接格式名稱 | 是 |
遠端電腦 | 否 |
遠端電腦和直接格式名稱 | 否 |