private async Task ExecuteAsync(CancellationToken cancellationToken) { CloudStorageAccount storageAccount = CloudStorageAccount.Parse(SettingsUtil.GetSettings <string>(SETTINGS.AZURE_STORAGE)); CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient(); CloudQueue queue = queueClient.GetQueueReference(UI_SERVICE_NAME.ToLower()); await queue.CreateIfNotExistsAsync(); while (!cancellationToken.IsCancellationRequested) { // Get the next message CloudQueueMessage retrievedMessage = await queue.GetMessageAsync(); if (retrievedMessage != null) { await handlerContainer.HandleAsync(retrievedMessage.AsString, null); //Process the message in less than 30 seconds, and then delete the message await queue.DeleteMessageAsync(retrievedMessage); } await Task.Delay(TimeSpan.FromSeconds(10), cancellationToken); } }
internal static async Task CleanQueueAsync(string serviceName) { CloudStorageAccount storageAccount = CloudStorageAccount.Parse(SettingsUtil.GetSettings <string>(SETTINGS.AZURE_STORAGE)); CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient(); CloudQueue queue = queueClient.GetQueueReference(serviceName.ToLower()); await queue.CreateIfNotExistsAsync(); await queue.ClearAsync().ConfigureAwait(false); }
public static async Task DeleteFilesAsync() { CloudStorageAccount storageAccount = CloudStorageAccount.Parse(SettingsUtil.GetSettings <string>(SETTINGS.AZURE_STORAGE)); CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient(); // Create a container var cloudBlobContainer = cloudBlobClient.GetContainerReference(CONTAINER_NAME.ToLower()); await cloudBlobContainer.CreateIfNotExistsAsync().ConfigureAwait(false); await cloudBlobContainer.DeleteAsync(); }
public static async Task <IEnumerable <IListBlobItem> > ListFilesAsync() { CloudStorageAccount storageAccount = CloudStorageAccount.Parse(SettingsUtil.GetSettings <string>(SETTINGS.AZURE_STORAGE)); CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient(); // Create a container var cloudBlobContainer = cloudBlobClient.GetContainerReference(CONTAINER_NAME.ToLower()); await cloudBlobContainer.CreateIfNotExistsAsync().ConfigureAwait(false); var blobList = await cloudBlobContainer.ListBlobsSegmentedAsync(string.Empty, true, BlobListingDetails.None, int.MaxValue, null, null, null); return(blobList.Results); }
public static async Task <bool> DeleteBlob(string bigPropertyWrapperSerialized) { var jsonSerializer = new JSONSerializer(); var wrapper = jsonSerializer.Deserialize(bigPropertyWrapperSerialized, typeof(BigPropertyWrapper)) as BigPropertyWrapper; CloudStorageAccount storageAccount = CloudStorageAccount.Parse(SettingsUtil.GetSettings <string>(SETTINGS.AZURE_STORAGE)); CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient(); // Create a container var cloudBlobContainer = cloudBlobClient.GetContainerReference(CONTAINER_NAME.ToLower()); await cloudBlobContainer.CreateIfNotExistsAsync().ConfigureAwait(false); CloudBlockBlob blockBlob = cloudBlobContainer.GetBlockBlobReference(wrapper.FileName); return(await blockBlob.DeleteIfExistsAsync()); }
internal static async Task <IEnumerable <string> > ReadEveryMessageFromQueueAsync(string serviceName) { CloudStorageAccount storageAccount = CloudStorageAccount.Parse(SettingsUtil.GetSettings <string>(SETTINGS.AZURE_STORAGE)); CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient(); CloudQueue queue = queueClient.GetQueueReference(serviceName.ToLower()); await queue.CreateIfNotExistsAsync(); var messages = await queue.GetMessagesAsync(30); if (messages != null) { return(messages.Select(m => m.AsString)); } else { return(null); } }
internal static async Task <string> ReadOneMessageFromQueueAsync(string serviceName) { CloudStorageAccount storageAccount = CloudStorageAccount.Parse(SettingsUtil.GetSettings <string>(SETTINGS.AZURE_STORAGE)); CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient(); CloudQueue queue = queueClient.GetQueueReference(serviceName.ToLower()); await queue.CreateIfNotExistsAsync(); var message = await queue.GetMessageAsync().ConfigureAwait(false); if (message != null) { await queue.DeleteMessageAsync(message); return(message.AsString); } else { return(null); } }
public static async Task <string> StoreDataInBlob <T>(T property) { var jsonSerializer = new JSONSerializer(); var wrapper = new BigPropertyWrapper(); CloudStorageAccount storageAccount = CloudStorageAccount.Parse(SettingsUtil.GetSettings <string>(SETTINGS.AZURE_STORAGE)); CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient(); var fileName = Guid.NewGuid().ToString("N").ToLower() + ".afbus"; // Create a container var cloudBlobContainer = cloudBlobClient.GetContainerReference(CONTAINER_NAME.ToLower()); await cloudBlobContainer.CreateIfNotExistsAsync().ConfigureAwait(false); CloudBlockBlob blockBlob = cloudBlobContainer.GetBlockBlobReference(fileName); await blockBlob.UploadTextAsync(jsonSerializer.Serialize(property)); wrapper.PropertyType = typeof(T).AssemblyQualifiedName; wrapper.FileName = blockBlob.Name; return(jsonSerializer.Serialize(wrapper)); }
public void Bus_PublishAsync_EventHub_Nominal() { var id = Guid.NewGuid(); bool testOk = false; var message = new TestMessage() { SomeData = id.ToString() }; var serializer = new JSONSerializer(); var publisher = new AzureEventHubPublishTransport(serializer); IBus bus = new Bus(serializer, new AzureStorageQueueSendTransport(serializer), publisher); bus.Context = new AFBusMessageContext(); bus.PublishAsync(message, TOPICNAME).Wait(); var eventProcessorHost = new EventProcessorHost(TOPICNAME, PartitionReceiver.DefaultConsumerGroupName, SettingsUtil.GetSettings <string>(SETTINGS.AZURE_EVENTHUB), SettingsUtil.GetSettings <string>(SETTINGS.AZURE_STORAGE), "eventhubcontainer"); // Registers the Event Processor Host and starts receiving messages var readingTask = eventProcessorHost.RegisterEventProcessorFactoryAsync(new AzureStreamProcessorFactory(stringMessage => { var finalMessageEnvelope = JsonConvert.DeserializeObject <AFBusMessageEnvelope>(stringMessage, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.Objects, TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple }); var finalMessage = JsonConvert.DeserializeObject <TestMessage>(finalMessageEnvelope.Body, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.Objects, TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple }); testOk = testOk || (id.ToString() == finalMessage.SomeData); })); Task.Delay(5000).Wait(); // Disposes of the Event Processor Host eventProcessorHost.UnregisterEventProcessorAsync().Wait(); Assert.IsTrue(testOk); }