MessageQueue.Create 方法
定义
在“消息队列”服务器上的指定路径中创建新队列。Creates a new queue at the specified path on a Message Queuing server.
重载
| Create(String) |
在指定的路径中创建非事务性“消息队列”队列。Creates a non-transactional Message Queuing queue at the specified path. |
| Create(String, Boolean) |
在指定的路径中创建事务性或非事务性“消息队列”队列。Creates a transactional or non-transactional Message Queuing queue at the specified path. |
Create(String)
在指定的路径中创建非事务性“消息队列”队列。Creates a non-transactional Message Queuing queue at the specified path.
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
要创建的队列的路径。The path of the queue to create.
返回
表示新队列的 MessageQueue。A MessageQueue that represents the new queue.
例外
path 参数为 null 或者是空字符串 ("")。The path parameter is null or is an empty string ("").
队列已存在于指定的路径中。A queue already exists at the specified path.
- 或 --or-
访问“消息队列”方法时出错。An error occurred when accessing a Message Queuing method.
示例
下面的代码示例创建公用和专用队列。The following code example creates public and private queues. 它将消息发送到所选队列。It sends a message to selected queues.
#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
注解
使用此重载创建非事务性 "消息队列" 队列。Use this overload to create a non-transactional Message Queuing queue.
若要 MessageQueue 在应用程序中创建类的新实例并将其绑定到现有队列,请使用 MessageQueue 构造函数。To create a new instance of the MessageQueue class in your application and bind it to an existing queue, use the MessageQueue constructor. 若要在消息队列中创建新队列,请调用 Create(String) 。To create a new queue in Message Queuing, call Create(String).
参数的语法 path 取决于它所引用的队列的类型,如下表所示。The syntax for the path parameter depends on the type of queue it references, as shown in the following table.
| 队列类型Queue type | 语法Syntax |
|---|---|
| 公用队列Public queue | MachineName\QueueName |
| 专用队列Private queue | MachineName\Private$\QueueName |
使用 "." 表示本地计算机。Use "." for the local computer. 有关更多语法,请参见 Path 属性。For more syntax, see the Path property.
下表显示了此方法是否在各种工作组模式下可用。The following table shows whether this method is available in various Workgroup modes.
| 工作组模式Workgroup mode | 可用Available |
|---|---|
| 本地计算机Local computer | 是Yes |
| 本地计算机和直接格式名称Local computer and direct format name | 是Yes |
| 远程计算机Remote computer | 否No |
| 远程计算机和直接格式名称Remote computer and direct format name | 否No |
另请参阅
适用于
Create(String, Boolean)
在指定的路径中创建事务性或非事务性“消息队列”队列。Creates a transactional or non-transactional Message Queuing queue at the specified path.
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
要创建的队列的路径。The path of the queue to create.
- transactional
- Boolean
如果创建事务性队列,为 true;如果创建非事务性队列,则为 false。true to create a transactional queue; false to create a non-transactional queue.
返回
表示新队列的 MessageQueue。A MessageQueue that represents the new queue.
例外
path 参数为 null 或者是空字符串 ("")。The path parameter is null or is an empty string ("").
队列已存在于指定的路径中。A queue already exists at the specified path.
- 或 --or-
访问“消息队列”方法时出错。An error occurred when accessing a Message Queuing method.
示例
下面的代码示例创建公共和专用事务性队列。The following code example creates public and private transactional queues. 它将消息发送到所选队列。It sends a message to selected queues.
#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
注解
您可以使用此重载在消息队列中创建事务性队列。You can use this overload to create a transactional queue in Message Queuing. 可以通过将 transactional 参数设置为 false 或,通过调用的其他重载,来创建非事务性队列 Create(String) 。You can create a non-transactional queue, by setting the transactional parameter to false or by calling the other overload of Create(String).
若要 MessageQueue 在应用程序中创建类的新实例并将其绑定到现有队列,请使用 MessageQueue 构造函数。To create a new instance of the MessageQueue class in your application and bind it to an existing queue, use the MessageQueue constructor. 若要在消息队列中创建新队列,请调用 Create(String) 。To create a new queue in Message Queuing, call Create(String).
参数的语法 path 取决于它所引用的队列的类型,如下表所示。The syntax for the path parameter depends on the type of queue it references, as shown in the following table.
| 队列类型Queue type | 语法Syntax |
|---|---|
| 公用队列Public queue | MachineName\QueueName |
| 专用队列Private queue | MachineName\Private$\QueueName |
使用 "." 表示本地计算机。Use "." for the local computer. 有关更多语法,请参见 Path 属性。For more syntax, see the Path property.
下表显示了此方法是否在各种工作组模式下可用。The following table shows whether this method is available in various Workgroup modes.
| 工作组模式Workgroup mode | 可用Available |
|---|---|
| 本地计算机Local computer | 是Yes |
| 本地计算机和直接格式名称Local computer and direct format name | 是Yes |
| 远程计算机Remote computer | 否No |
| 远程计算机和直接格式名称Remote computer and direct format name | 否No |