MessageQueue.Create Metod
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Skapar en ny kö på den angivna sökvägen på en Message Queuing-server.
Överlagringar
| Name | Description |
|---|---|
| Create(String) |
Skapar en kö för meddelandekö som inte är transaktionell vid den angivna sökvägen. |
| Create(String, Boolean) |
Skapar en transaktionell eller icke-transaktionell Meddelandekö på den angivna sökvägen. |
Create(String)
Skapar en kö för meddelandekö som inte är transaktionell vid den angivna sökvägen.
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
Parametrar
- path
- String
Sökvägen till kön som ska skapas.
Returer
En MessageQueue som representerar den nya kön.
Undantag
Parametern path är null eller är en tom sträng ("").
Det finns redan en kö på den angivna sökvägen.
-eller-
Ett fel uppstod vid åtkomst till en Message Queuing-metod.
Exempel
I följande kodexempel skapas offentliga och privata köer. Det skickar ett meddelande till valda köer.
#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
Kommentarer
Använd den här överlagringen för att skapa en kö för meddelandeköer som inte är transaktionella.
Om du vill skapa en ny instans av MessageQueue klassen i ditt program och binda den till en befintlig kö använder du MessageQueue konstruktorn. Om du vill skapa en ny kö i Message Queuing anropar du Create(String).
Syntaxen för parametern path beror på vilken typ av kö den refererar till, enligt följande tabell.
| Kötyp | Syntax |
|---|---|
| Offentlig kö | MachineName\QueueName |
| Privat kö | MachineName\Private$\QueueName |
Använd "." för den lokala datorn. Mer syntax finns i egenskapen Path .
I följande tabell visas om den här metoden är tillgänglig i olika arbetsgruppslägen.
| Arbetsgruppsläge | Tillgängligt |
|---|---|
| Lokal dator | Yes |
| Namn på lokal dator och direktformat | Yes |
| Fjärrdator | No |
| Namn på fjärrdator och direktformat | No |
Se även
Gäller för
Create(String, Boolean)
Skapar en transaktionell eller icke-transaktionell Meddelandekö på den angivna sökvägen.
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
Parametrar
- path
- String
Sökvägen till kön som ska skapas.
- transactional
- Boolean
true för att skapa en transaktionskö; false för att skapa en kö som inte är transaktionell.
Returer
En MessageQueue som representerar den nya kön.
Undantag
Parametern path är null eller är en tom sträng ("").
Det finns redan en kö på den angivna sökvägen.
-eller-
Ett fel uppstod vid åtkomst till en Message Queuing-metod.
Exempel
I följande kodexempel skapas offentliga och privata transaktionsköer. Det skickar ett meddelande till valda köer.
#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
Kommentarer
Du kan använda den här överbelastningen för att skapa en transaktionskö i Message Queuing. Du kan skapa en icke-transaktionell kö genom att ange parametern transactional till eller genom att false anropa den andra överlagringen av Create(String).
Om du vill skapa en ny instans av MessageQueue klassen i ditt program och binda den till en befintlig kö använder du MessageQueue konstruktorn. Om du vill skapa en ny kö i Message Queuing anropar du Create(String).
Syntaxen för parametern path beror på vilken typ av kö den refererar till, enligt följande tabell.
| Kötyp | Syntax |
|---|---|
| Offentlig kö | MachineName\QueueName |
| Privat kö | MachineName\Private$\QueueName |
Använd "." för den lokala datorn. Mer syntax finns i egenskapen Path .
I följande tabell visas om den här metoden är tillgänglig i olika arbetsgruppslägen.
| Arbetsgruppsläge | Tillgängligt |
|---|---|
| Lokal dator | Yes |
| Namn på lokal dator och direktformat | Yes |
| Fjärrdator | No |
| Namn på fjärrdator och direktformat | No |