/// <summary> /// Deletes the queue. /// </summary> public async Task DeleteQueue() { var startTime = DateTime.UtcNow; if (logger.IsEnabled(LogLevel.Trace)) { logger.Trace("Deleting queue: {0}", QueueName); } try { // that way we don't have first to create the queue to be able later to delete it. if (await queueClient.DeleteIfExistsAsync()) { logger.Info((int)AzureQueueErrorCode.AzureQueue_03, "Deleted Azure Queue {0}", QueueName); } } catch (Exception exc) { ReportErrorAndRethrow(exc, "DeleteQueue", AzureQueueErrorCode.AzureQueue_04); } finally { CheckAlertSlowAccess(startTime, "DeleteQueue"); } }
//------------------------------------------------- // Delete the queue //------------------------------------------------- public async static Task <Azure.Response <bool> > DeleteQueue(string queueName, string connectionString) { // Instantiate a QueueClient which will be used to manipulate the queue QueueClient queueClient = new QueueClient(connectionString, queueName); // Delete the queue return(await queueClient.DeleteIfExistsAsync()); }
public async Task DeleteIfExistsAsync() { await Task.WhenAll( _container.DeleteIfExistsAsync(), _queue.DeleteIfExistsAsync(), _dlQueue.DeleteIfExistsAsync() ).ConfigureAwait(false); }
public async Task Delete() { QueueProperties properties = await client.GetPropertiesAsync(); if (properties.ApproximateMessagesCount == 0) { } await client.DeleteIfExistsAsync(); }
public void Dispose() { // each test will have a different hostId // and therefore a different sharedQueue and poisonQueue var client = _host.GetStorageAccount().CreateQueueServiceClient(); _sharedQueue = client.GetQueueClient("azure-webjobs-shared-" + _host.Services.GetService <IHostIdProvider>().GetHostIdAsync(CancellationToken.None).Result); _poisonQueue = client.GetQueueClient("azure-webjobs-poison-" + _host.Services.GetService <IHostIdProvider>().GetHostIdAsync(CancellationToken.None).Result); _sharedQueue.DeleteIfExistsAsync().Wait(); _poisonQueue.DeleteIfExistsAsync().Wait(); _host.Dispose(); }
static async Task <string> RetrieveNextMessageAsync(QueueClient theQueue) { if (await theQueue.ExistsAsync()) { QueueProperties properties = await theQueue.GetPropertiesAsync(); if (properties.ApproximateMessagesCount > 0) { QueueMessage[] retrievedMessage = await theQueue.ReceiveMessagesAsync(1); string theMessage = retrievedMessage[0].MessageText; await theQueue.DeleteMessageAsync(retrievedMessage[0].MessageId, retrievedMessage[0].PopReceipt); return(theMessage); } else { Console.Write("The queue is empty. Attempt to delete it? (Y/N) "); string response = Console.ReadLine(); if (response.ToUpper() == "Y") { await theQueue.DeleteIfExistsAsync(); return("The queue was deleted."); } else { return("The queue was not deleted."); } } } else { return("The queue does not exist. Add a message to the command line to create the queue and store the message."); } }
static async Task Main(string[] args) { string connectionString = Environment.GetEnvironmentVariable("AZURE_STORAGE_CONNECTION_STRING"); QueueClient queue = new QueueClient(connectionString, "mystoragequeue"); await queue.CreateIfNotExistsAsync(); Console.WriteLine($"Queue created sucessfully"); while (true) { Console.WriteLine("Type A to write message, B to read message or any letter to delete the queue"); string option = Console.ReadLine(); if (option == "A") { Console.WriteLine("what is the message:"); string message = Console.ReadLine(); await queue.SendMessageAsync(message); System.Console.WriteLine("Message sent into the queue "); } else if (option == "B") { QueueMessage[] retrievedMessage = await queue.ReceiveMessagesAsync(); string theMessage = retrievedMessage[0].MessageText; Console.WriteLine($"message: {theMessage}"); } else { await queue.DeleteIfExistsAsync(); Console.WriteLine("The queue was deleted."); } } }
public override bool DeleteStructure() { return(_queue != null && Task.Run(() => _queue.DeleteIfExistsAsync()).Result); }
public Task DeleteQueueIfExists() { return(_queue.DeleteIfExistsAsync()); }