本文整理汇总了C#中NamespaceManager.CreateQueue方法的典型用法代码示例。如果您正苦于以下问题:C# NamespaceManager.CreateQueue方法的具体用法?C# NamespaceManager.CreateQueue怎么用?C# NamespaceManager.CreateQueue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NamespaceManager
的用法示例。
在下文中一共展示了NamespaceManager.CreateQueue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main()
{
_servicesBusConnectionString = AmbientConnectionStringProvider.Instance.GetConnectionString(ConnectionStringNames.ServiceBus);
namespaceManager = NamespaceManager.CreateFromConnectionString(_servicesBusConnectionString);
if (!namespaceManager.QueueExists(nameof(Step1)))
{
namespaceManager.CreateQueue(nameof(Step1));
}
if (!namespaceManager.QueueExists(nameof(Step2)))
{
namespaceManager.CreateQueue(nameof(Step2));
}
JobHostConfiguration config = new JobHostConfiguration();
config.UseServiceBus();
var host = new JobHost(config);
CreateStartMessage();
host.RunAndBlock();
}
示例2: Main
public static void Main(string[] args)
{
ServiceNamespace = ConfigurationManager.AppSettings["ServiceNamespace"];
// Issuer key
sasKeyValue = ConfigurationManager.AppSettings["SASKey"];
// Create management credentials
TokenProvider credentials = TokenProvider.CreateSharedAccessSignatureTokenProvider(sasKeyName, sasKeyValue);
NamespaceManager namespaceClient =
new NamespaceManager(
ServiceBusEnvironment.CreateServiceUri("sb", ServiceNamespace, string.Empty),
credentials);
QueueDescription myQueue;
if (!namespaceClient.QueueExists(QUEUE))
{
myQueue = namespaceClient.CreateQueue(QUEUE);
}
MessagingFactory factory = MessagingFactory.Create(ServiceBusEnvironment.CreateServiceUri("sb", ServiceNamespace, string.Empty), credentials);
QueueClient myQueueClient = factory.CreateQueueClient(QUEUE);
// Send message
Poco poco = new Poco();
poco.Id = "001";
poco.content = "This is some content";
BrokeredMessage message = new BrokeredMessage();
message.Properties.Add("Id", poco.Id);
message.Properties.Add("Content", poco.content);
myQueueClient.Send(message);
}
示例3: CreateQueue
//Queue and its credentials in another project, this never called
static void CreateQueue()
{
// Create management credentials
TokenProvider credentials = TokenProvider.CreateSharedAccessSignatureTokenProvider(manageKeyName, manageKeyValue);
NamespaceManager namespaceClient = new NamespaceManager(ServiceBusEnvironment.CreateServiceUri("sb", ServiceNamespace, string.Empty), credentials);
QueueDescription myQueue = namespaceClient.CreateQueue("MyQueue");
}
示例4: CreateQueue
static void CreateQueue(Uri baseAddress,string queueName,QueueDescription queueDescription,TokenProvider credentials)
{
if(QueueExists(baseAddress,queueName,credentials))
{
DeleteQueue(baseAddress,queueName,credentials);
}
NamespaceManager namespaceClient = new NamespaceManager(baseAddress,credentials);
namespaceClient.CreateQueue(queueDescription);
}
示例5: CreateQueue_WhenSslErrorOccurs_MessagingExceptionExceptionIsThrown
public void CreateQueue_WhenSslErrorOccurs_MessagingExceptionExceptionIsThrown()
{
string queueName = Guid.NewGuid().ToString();
Uri validCertUri = ServiceBusHelper.GetLocalHttpsEndpoint();
Uri invalidCertUri = new Uri("https://localhost:9355/ServiceBusDefaultNamespace");
TokenProvider tokenProvider = TokenProvider.CreateWindowsTokenProvider(new Uri[] { validCertUri });
NamespaceManager nsManager = new NamespaceManager(invalidCertUri, tokenProvider);
Assert.Throws<MessagingException>(() => nsManager.CreateQueue(queueName));
}
示例6: TryCreateQueueIfNotExists
private void TryCreateQueueIfNotExists(NamespaceManager namespaceManager, string queueName)
{
if (!namespaceManager.QueueExists(queueName))
{
var queueDescription = new QueueDescription(queueName)
{
MaxSizeInMegabytes = 5120,
DefaultMessageTimeToLive = TimeSpan.FromDays(7),
RequiresDuplicateDetection = false,
MaxDeliveryCount = 10
};
namespaceManager.CreateQueue(queueDescription);
}
}
示例7: CreateQueue
public bool CreateQueue(string queueId)
{
// Holds credentials and handles tokens from AZS
TokenProvider tokenProvider = GetTokenProvider();
Uri uri = GetServiceBusUri();
var namespaceManager = new NamespaceManager(uri, tokenProvider);
if (!namespaceManager.QueueExists(queueId))
{
namespaceManager.CreateQueue(queueId);
}
throw new NotImplementedException();
}
示例8: PrepareWatchingQueue
private QueueClient PrepareWatchingQueue()
{
var namespaceManagerSetting = new NamespaceManagerSettings()
{
TokenProvider = TokenProvider.CreateSharedSecretTokenProvider(ServiceBusIssuerName, ServiceBusIssuerSecret),
};
var namespaceManager = new NamespaceManager(ServiceBusAddress, namespaceManagerSetting);
if (!namespaceManager.QueueExists(_watchingQueueName))
{
namespaceManager.CreateQueue(_watchingQueueName);
}
var factory = MessagingFactory.Create(ServiceBusAddress, SharedSecretTokenProvider.CreateSharedSecretTokenProvider(ServiceBusIssuerName, ServiceBusIssuerSecret));
var queueClient = factory.CreateQueueClient(_watchingQueueName);
return queueClient;
}
示例9: CreateQueuesIfNotExists
private static void CreateQueuesIfNotExists(NamespaceManager namespaceManager, ServiceBusQueueOptions options)
{
foreach (var queue in options.Queues)
{
var prefixed = options.GetQueueName(queue);
if (!namespaceManager.QueueExists(prefixed))
{
var description = new QueueDescription(prefixed);
if (options.Configure != null)
{
options.Configure(description);
}
namespaceManager.CreateQueue(description);
}
}
}
示例10: MainSync
public async static Task MainSync()
{
ServiceNamespace = ConfigurationManager.AppSettings["ServiceNamespace"];
// Issuer key
sasKeyValue = ConfigurationManager.AppSettings["SASKey"];
// Get test async
string testId = "56b747d9fdfad82a0cfdce65";
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("http://getcmewebapi.azurewebsites.net/");
Task<string> testTask = client.GetStringAsync("api/v1/Test/" + testId);
// do other stuff while we're waiting for the test ...
// Create management credentials
TokenProvider credentials = TokenProvider.CreateSharedAccessSignatureTokenProvider(sasKeyName, sasKeyValue);
NamespaceManager namespaceClient =
new NamespaceManager(
ServiceBusEnvironment.CreateServiceUri("sb", ServiceNamespace, string.Empty),
credentials);
QueueDescription myQueue;
if (!namespaceClient.QueueExists(QUEUE))
{
myQueue = namespaceClient.CreateQueue(QUEUE);
}
MessagingFactory factory = MessagingFactory.Create(ServiceBusEnvironment.CreateServiceUri("sb", ServiceNamespace, string.Empty), credentials);
QueueClient myQueueClient = factory.CreateQueueClient(QUEUE);
// Send message
BrokeredMessage message = new BrokeredMessage();
// we need the test now ...
var testJsonString = await testTask;
Test test = JObject.Parse(testJsonString).ToObject<Test>();
message.Properties.Add("TestId", test.Id);
message.Properties.Add("InputDataId", test.InputDataId);
message.Properties.Add("DateSetId", test.DateSetId);
myQueueClient.Send(message);
}
示例11: Main
static void Main(string[] args)
{
GetUserCredentials();
TokenProvider credentials = null;
Uri serviceUri = null;
CreateTokenProviderAndServiceUri(out credentials, out serviceUri);
MessagingFactory factory = null;
try
{
NamespaceManager namespaceClient = new NamespaceManager(serviceUri, credentials);
if (namespaceClient == null)
{
Console.WriteLine("\nUnexpected Error: NamespaceManager is NULL");
return;
}
Console.WriteLine("\nCreating Queue '{0}'...", QueueName);
//Eliminar se a queue já existir
if (namespaceClient.QueueExists(QueueName))
namespaceClient.DeleteQueue(QueueName);
namespaceClient.CreateQueue(QueueName);
QueueClient myQueueClient = CreateQueueClient(serviceUri, credentials, out factory);
List<BrokeredMessage> messageList = new List<BrokeredMessage>();
messageList.Add(CreateIssueMessage("1", "First message "));
messageList.Add(CreateIssueMessage("2", "Second message "));
messageList.Add(CreateIssueMessage("3", "Third message "));
SendListOfMessages(messageList, myQueueClient);
}
catch (Exception e)
{
Console.WriteLine("Unexpected exception {0}", e.ToString());
throw;
}
finally
{
if (factory != null)
factory.Close();
}
}
示例12: WriteQueueMessage
private void WriteQueueMessage(NamespaceManager namespaceManager, string connectionString, string queueName, string message)
{
if (!namespaceManager.QueueExists(queueName))
{
namespaceManager.CreateQueue(queueName);
}
QueueClient queueClient = QueueClient.CreateFromConnectionString(connectionString, queueName);
using (Stream stream = new MemoryStream())
using (TextWriter writer = new StreamWriter(stream))
{
writer.Write(message);
writer.Flush();
stream.Position = 0;
queueClient.Send(new BrokeredMessage(stream) { ContentType = "text/plain" });
}
queueClient.Close();
}
示例13: ServiceBusConnection
/// <summary>
/// Setup and connect to Service Bus.
/// </summary>
/// <param name="namespaceManager"></param>
/// <param name="messagingFactory"></param>
/// <param name="durableMessageSender"></param>
private static void ServiceBusConnection(out NamespaceManager namespaceManager, out MessagingFactory messagingFactory, out DurableMessageSender durableMessageSender)
{
//Read user credentials.
//Console.Write("Service Namespace: ");
//string serviceNamespace = Console.ReadLine();
//Console.Write("Issuer Name: ");
//string issuerName = Console.ReadLine();
//Console.Write("Issuer Key: ");
//string issuerKey = Console.ReadLine();
//Console.WriteLine();
string serviceNamespace = "scoring";
string issuerName = "owner";
string issuerKey = "r3JxwjeQwuWwwLasXSQR7tDGx2FCiQLijr9ZBzPCti4=";
Console.WriteLine("Service Namespace: " + serviceNamespace);
Console.WriteLine("Issuer Name: " + issuerName);
Console.WriteLine("Issuer Key: " + issuerKey);
// Create token provider.
Uri namespaceUri = ServiceBusEnvironment.CreateServiceUri("sb", serviceNamespace, string.Empty);
Console.WriteLine("Namespace URI: " + namespaceUri.ToString());
TokenProvider tokenProvider = TokenProvider.CreateSharedSecretTokenProvider(issuerName, issuerKey);
// Create namespace manager and create Service Bus queue if it does not exist already.
namespaceManager = new NamespaceManager(namespaceUri, tokenProvider);
QueueDescription queueDescription = new QueueDescription(ServiceBusQueueOrTopicName);
queueDescription.RequiresDuplicateDetection = true;
if (!namespaceManager.QueueExists(ServiceBusQueueOrTopicName))
{
namespaceManager.CreateQueue(queueDescription);
Console.WriteLine("Created Service Bus queue \"{0}\".", ServiceBusQueueOrTopicName);
}
// Create a MessagingFactory.
messagingFactory = MessagingFactory.Create(namespaceUri, tokenProvider);
// Create a durable sender.
durableMessageSender = new DurableMessageSender(messagingFactory, ServiceBusQueueOrTopicName);
}
示例14: CreateQueueClientIfNotExist
private QueueClient CreateQueueClientIfNotExist(string p_healthMonitorCommandQueueName, bool p_requiresSession, string p_serviceBusUri, TokenProvider p_tokenProvider, NamespaceManager p_namespaceManager)
{
if (!p_namespaceManager.QueueExists(p_healthMonitorCommandQueueName))
{
QueueDescription qDesc = new QueueDescription(p_healthMonitorCommandQueueName);
qDesc.MaxSizeInMegabytes = 5120;
qDesc.DefaultMessageTimeToLive = TimeSpan.FromDays(14); // on Free tier pricing, max 14 days are allowed
qDesc.EnableDeadLetteringOnMessageExpiration = false;
qDesc.LockDuration = TimeSpan.FromMinutes(5); // default is 30seconds, I have changed it to 5minutes, which is the maximum
qDesc.RequiresDuplicateDetection = false;
// 'RequiresSession' cannot be set when creating a Queue IF the namespace 'sqhealthmonitorservicebusqueue-ns' is using free 'Basic' tier.
qDesc.RequiresSession = p_requiresSession; // if there is only one consumer of the command queue, no sessionID is required, for the commandResult there are more consumers
qDesc.EnablePartitioning = true;
// until this line is the properties that can be set in Azure portal
qDesc.EnableBatchedOperations = false; // for low latency, quick response, don't wait miliseconds to batch messages, but send them instantly
var qDescCreated = p_namespaceManager.CreateQueue(qDesc);
}
MessagingFactorySettings mfs = new MessagingFactorySettings();
mfs.TokenProvider = p_tokenProvider;
//mfs.TransportType = TransportType.Amqp; // 400msec latency
mfs.TransportType = Microsoft.ServiceBus.Messaging.TransportType.NetMessaging; // 50msec latency
mfs.NetMessagingTransportSettings.BatchFlushInterval = TimeSpan.Zero; // instead of 20msec, // latency is 37msec was the minimum I measured (instead of 43msec)
MessagingFactory factory = MessagingFactory.Create(p_serviceBusUri, mfs);
var queueClient = factory.CreateQueueClient(p_healthMonitorCommandQueueName, ReceiveMode.PeekLock);
queueClient.PrefetchCount = 0; // it is the default too, and it was 0 in the fast and in the slow cases too
return queueClient;
}
示例15: CreateQueueIfNecessary
private QueueClient CreateQueueIfNecessary(NamespaceManager namespaceManager, string queueName)
{
//Trace.TraceWarning("Does queue exist: " + queueName);
if (!namespaceManager.QueueExists(queueName))
{
Trace.TraceWarning("CreateQueue: " + _connectionString + " " + queueName);
namespaceManager.CreateQueue(queueName);
}
Trace.TraceWarning("Get QueueClient from ConnectionString: " + _connectionString + " " + queueName);
var qc = QueueClient.CreateFromConnectionString(_connectionString, queueName);
if (qc == null)
{
Trace.TraceError("CreateQueue() failed - queueClient is null");
}
return qc;
//return QueueClient.CreateFromConnectionString(_connectionString, queueName);
}