public async Task MessageSample() { // Instantiate a new QueueServiceClient using a connection string. QueueServiceClient queueServiceClient = new QueueServiceClient(TestConfigurations.DefaultTargetTenant.ConnectionString); // Instantiate a new QueueClient QueueClient queueClient = queueServiceClient.GetQueueClient($"myqueue2-{Guid.NewGuid()}"); try { // Create your new Queue in the service await queueClient.CreateAsync(); // Instantiate a new MessagesClient // Enqueue a message to the queue Response <EnqueuedMessage> enqueueResponse = await queueClient.EnqueueMessageAsync("my message"); // Peek message Response <IEnumerable <PeekedMessage> > peekResponse = await queueClient.PeekMessagesAsync(); // Update message await queueClient.UpdateMessageAsync("new message", enqueueResponse.Value.MessageId, enqueueResponse.Value.PopReceipt); // Dequeue message Response <IEnumerable <DequeuedMessage> > dequeueResponse = await queueClient.DequeueMessagesAsync(); // Delete Message await queueClient.DeleteMessageAsync(enqueueResponse.Value.MessageId, dequeueResponse.Value.First().PopReceipt); } finally { // Delete your Queue in the service await queueClient.DeleteAsync(); } }
public async Task ErrorsAsync() { // Get a connection string to our Azure Storage account string connectionString = ConnectionString; // Get a reference to a queue named "sample-queue" and then create it QueueClient queue = new QueueClient(connectionString, Randomize("sample-queue")); await queue.CreateAsync(); try { // Try to create the queue again await queue.CreateAsync(); } catch (RequestFailedException ex) when(ex.ErrorCode == QueueErrorCode.QueueAlreadyExists) { // Ignore any errors if the queue already exists } catch (RequestFailedException ex) { Assert.Fail($"Unexpected error: {ex}"); } // Clean up after the test when we're finished await queue.DeleteAsync(); }
public async Task QueueSample() { // Instantiate a new QueueServiceClient using a connection string. QueueServiceClient queueServiceClient = new QueueServiceClient(TestConfigurations.DefaultTargetTenant.ConnectionString); // Instantiate a new QueueClient QueueClient queueClient = queueServiceClient.GetQueueClient($"myqueue-{Guid.NewGuid()}"); try { // Create your new Queue in the service await queueClient.CreateAsync(); // List Queues await foreach (QueueItem queue in queueServiceClient.GetQueuesAsync()) { Console.WriteLine(queue.Name); } } finally { // Delete your Queue in the service await queueClient.DeleteAsync(); } }
public async Task EnqueueAsync() { // Get a connection string to our Azure Storage account. You can // obtain your connection string from the Azure Portal (click // Access Keys under Settings in the Portal Storage account blade) // or using the Azure CLI with: // // az storage account show-connection-string --name <account_name> --resource-group <resource_group> // // And you can provide the connection string to your application // using an environment variable. string connectionString = ConnectionString; // Get a reference to a queue named "sample-queue" and then create it QueueClient queue = new QueueClient(connectionString, Randomize("sample-queue")); await queue.CreateAsync(); try { // Add a message to our queue await queue.SendMessageAsync("Hello, Azure!"); // Verify we uploaded one message Assert.AreEqual(1, (await queue.PeekMessagesAsync(10)).Value.Count()); } finally { // Clean up after the test when we're finished await queue.DeleteAsync(); } }
public static async Task DeleteQueue(QueueClient queueClient) { Console.WriteLine("\nPress Enter key to delete the queue..."); Console.ReadLine(); // Clean up Console.WriteLine($"Deleting queue: {queueClient.Name}"); await queueClient.DeleteAsync(); Console.WriteLine("Done"); }
public async Task Delete(string queueName) { var queueClient = new QueueClient(Options.ConnectionString, queueName); if (await queueClient.ExistsAsync()) { await queueClient.DeleteAsync(); } WriteLine($"Queue deleted: '{queueClient.Name}'"); }
public async Task DequeueAndUpdateAsync() { // Get a connection string to our Azure Storage account. string connectionString = ConnectionString; // Get a reference to a queue named "sample-queue" and then create it QueueClient queue = new QueueClient(connectionString, Randomize("sample-queue")); await queue.CreateAsync(); try { // Add several messages to the queue await queue.SendMessageAsync("first"); await queue.SendMessageAsync("second"); await queue.SendMessageAsync("third"); // Get the messages from the queue with a short visibility timeout List <QueueMessage> messages = new List <QueueMessage>(); foreach (QueueMessage message in (await queue.ReceiveMessagesAsync(10, TimeSpan.FromSeconds(1))).Value) { // Tell the service we need a little more time to process the message UpdateReceipt changedMessage = await queue.UpdateMessageAsync( message.MessageId, message.PopReceipt, message.MessageText, TimeSpan.FromSeconds(5)); messages.Add(message.Update(changedMessage)); } // Wait until the visibility window times out await Task.Delay(TimeSpan.FromSeconds(1.5)); // Ensure the messages aren't visible yet Assert.AreEqual(0, (await queue.ReceiveMessagesAsync(10)).Value.Count()); // Finish processing the messages foreach (QueueMessage message in messages) { // Tell the service we need a little more time to process the message await queue.DeleteMessageAsync(message.MessageId, message.PopReceipt); } } finally { // Clean up after the test when we're finished await queue.DeleteAsync(); } }
public async Task DequeueAsync() { // Get a connection string to our Azure Storage account. string connectionString = ConnectionString; // Get a reference to a queue named "sample-queue" and then create it QueueClient queue = new QueueClient(connectionString, Randomize("sample-queue")); await queue.CreateAsync(); try { // Add several messages to the queue await queue.SendMessageAsync("first"); await queue.SendMessageAsync("second"); await queue.SendMessageAsync("third"); await queue.SendMessageAsync("fourth"); await queue.SendMessageAsync("fifth"); // Get the messages from the queue List <string> messages = new List <string>(); foreach (QueueMessage message in (await queue.ReceiveMessagesAsync(maxMessages: 10)).Value) { // "Process" the message messages.Add(message.MessageText); // Let the service know we finished with the message and // it can be safely deleted. await queue.DeleteMessageAsync(message.MessageId, message.PopReceipt); } // Verify the messages Assert.AreEqual(5, messages.Count); Assert.Contains("first", messages); Assert.Contains("second", messages); Assert.Contains("third", messages); Assert.Contains("fourth", messages); Assert.Contains("fifth", messages); } finally { // Clean up after the test when we're finished await queue.DeleteAsync(); } }
public async Task Sample01b_HelloWorldAsync_ErrorsAsync() { string queueName = Randomize("sample-queue"); QueueClient queue = new QueueClient(ConnectionString, queueName); try { await queue.CreateAsync(); await Sample01b_HelloWorldAsync.ErrorsAsync(ConnectionString, queueName); } finally { await queue.DeleteAsync(); } }
public async Task Sample01b_HelloWorldAsync_SendMessageAsync() { string queueName = Randomize("sample-queue"); QueueClient queue = new QueueClient(ConnectionString, queueName); try { await Sample01b_HelloWorldAsync.SendMessageAsync(ConnectionString, queueName); // Verify we uploaded one message Assert.AreEqual(1, (await queue.PeekMessagesAsync(10)).Value.Length); } finally { await queue.DeleteAsync(); } }
public async Task <bool> QueueAsync() { // <snippet_AsyncQueue> // Get the connection string from app settings string connectionString = ConfigurationManager.AppSettings["StorageConnectionString"]; // Instantiate a QueueClient which will be used to create and manipulate the queue QueueClient queueClient = new QueueClient(connectionString, "myqueue"); // Create the queue if it doesn't already exist await queueClient.CreateIfNotExistsAsync(); if (await queueClient.ExistsAsync()) { Console.WriteLine($"Queue '{queueClient.Name}' created"); } else { Console.WriteLine($"Queue '{queueClient.Name}' exists"); } // Async enqueue the message await queueClient.SendMessageAsync("Hello, World"); Console.WriteLine($"Message added"); // Async receive the message QueueMessage[] retrievedMessage = await queueClient.ReceiveMessagesAsync(); Console.WriteLine($"Retrieved message with content '{retrievedMessage[0].MessageText}'"); // Async delete the message await queueClient.DeleteMessageAsync(retrievedMessage[0].MessageId, retrievedMessage[0].PopReceipt); Console.WriteLine($"Deleted message: '{retrievedMessage[0].MessageText}'"); // Async delete the queue await queueClient.DeleteAsync(); Console.WriteLine($"Deleted queue: '{queueClient.Name}'"); // </snippet_AsyncQueue> return(true); }
public async Task PeekAsync() { // Get a connection string to our Azure Storage account. string connectionString = ConnectionString; // Get a reference to a queue named "sample-queue" and then create it QueueClient queue = new QueueClient(connectionString, Randomize("sample-queue")); await queue.CreateAsync(); try { // Add several messages to the queue await queue.EnqueueMessageAsync("first"); await queue.EnqueueMessageAsync("second"); await queue.EnqueueMessageAsync("third"); await queue.EnqueueMessageAsync("fourth"); await queue.EnqueueMessageAsync("fifth"); // Get the messages from the queue List <string> messages = new List <string>(); foreach (PeekedMessage message in (await queue.PeekMessagesAsync(maxMessages: 10)).Value) { // Inspect the message messages.Add(message.MessageText); } // Verify the messages Assert.AreEqual(5, messages.Count); Assert.Contains("first", messages); Assert.Contains("second", messages); Assert.Contains("third", messages); Assert.Contains("fourth", messages); Assert.Contains("fifth", messages); } finally { // Clean up after the test when we're finished await queue.DeleteAsync(); } }
public async Task Sample01b_HelloWorldAsync_PeekMesssagesAsync() { string queueName = Randomize("sample-queue"); QueueClient queue = new QueueClient(ConnectionString, queueName); try { await queue.CreateAsync(); await Sample01b_HelloWorldAsync.PeekMesssagesAsync(ConnectionString, queueName); // Verify we haven't emptied the queue Assert.Less(0, (await queue.PeekMessagesAsync()).Value.Length); } finally { await queue.DeleteAsync(); } }
public async Task Sample01b_HelloWorldAsync_ReceiveMessagesAsync() { string queueName = Randomize("sample-queue"); QueueClient queue = new QueueClient(ConnectionString, queueName); try { await queue.CreateAsync(); await Sample01b_HelloWorldAsync.ReceiveMessagesAsync(ConnectionString, queueName); // Verify we processed all the messages Assert.AreEqual(0, (await queue.PeekMessagesAsync()).Value.Length); } finally { await queue.DeleteAsync(); } }
public async Task QueueSample() { // Instantiate a new QueueServiceClient using a connection string. QueueServiceClient queueServiceClient = new QueueServiceClient(TestConfigurations.DefaultTargetTenant.ConnectionString); // Instantiate a new QueueClient QueueClient queueClient = queueServiceClient.GetQueueClient("myqueue"); try { // Create your new Queue in the service await queueClient.CreateAsync(); // List Queues Response <QueuesSegment> listResponse = await queueServiceClient.ListQueuesSegmentAsync(); } finally { // Delete your Queue in the service await queueClient.DeleteAsync(); } }
static async Task DeleteQueueAsync(string connectionString, string queueName) { QueueServiceClient serviceClient = new QueueServiceClient(connectionString); QueueClient queue = serviceClient.GetQueueClient(queueName); await queue.DeleteAsync(); }
static async Task Main(string[] args) { //Storage Access Connection String string connectionString = Environment.GetEnvironmentVariable("AZURE_STORAGE_CONNECTION_STRING"); //CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString); //CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient(); //CloudQueue queue = queueClient.GetQueueReference("mystoragequeue"); // Create a unique name for the queue string queueName = "quickstartqueues-" + Guid.NewGuid().ToString(); Console.WriteLine($"Creating queue: {queueName}"); // Instantiate a QueueClient which will be // used to create and manipulate the queue QueueClient queueClient = new QueueClient(connectionString, queueName); // Create the queue await queueClient.CreateAsync(); Console.WriteLine("\nAdding messages to the queue..."); // Send several messages to the queue await queueClient.SendMessageAsync("First message"); await queueClient.SendMessageAsync("Second message"); // Save the receipt so we can update this message later SendReceipt receipt = await queueClient.SendMessageAsync("Third message"); Console.WriteLine("\nPeek at the messages in the queue..."); // Peek at messages in the queue PeekedMessage[] peekedMessages = await queueClient.PeekMessagesAsync(maxMessages : 10); foreach (PeekedMessage peekedMessage in peekedMessages) { // Display the message Console.WriteLine($"Message: {peekedMessage.MessageText}"); } Console.WriteLine("\nUpdating the third message in the queue..."); // Update a message using the saved receipt from sending the message await queueClient.UpdateMessageAsync(receipt.MessageId, receipt.PopReceipt, "Third message has been updated"); Console.WriteLine("\nReceiving messages from the queue..."); // Get messages from the queue QueueMessage[] messages = await queueClient.ReceiveMessagesAsync(maxMessages : 10); Console.WriteLine("\nPress Enter key to 'process' messages and delete them from the queue..."); Console.ReadLine(); // Process and delete messages from the queue foreach (QueueMessage message in messages) { // "Process" the message Console.WriteLine($"Message: {message.MessageText}"); // Let the service know we're finished with // the message and it can be safely deleted. await queueClient.DeleteMessageAsync(message.MessageId, message.PopReceipt); } Console.WriteLine("\nPress Enter key to delete the queue..."); Console.ReadLine(); // Clean up Console.WriteLine($"Deleting queue: {queueClient.Name}"); await queueClient.DeleteAsync(); Console.WriteLine("Done"); }
public static async Task DeleteAsync(string account, string key, string queueName) { QueueClient queueClient = new QueueClient(Client.GetConnectionString(account, key), queueName); await queueClient.DeleteAsync(); }