public static void SetSerivceProperties(Constants.ServiceType serviceType, Microsoft.WindowsAzure.Storage.Shared.Protocol.ServiceProperties serviceProperties) { switch (serviceType) { case Constants.ServiceType.Blob: StorageAccount.CreateCloudBlobClient().SetServiceProperties(serviceProperties); break; case Constants.ServiceType.Queue: StorageAccount.CreateCloudQueueClient().SetServiceProperties(serviceProperties); break; case Constants.ServiceType.Table: StorageAccount.CreateCloudTableClient().SetServiceProperties(serviceProperties); break; case Constants.ServiceType.File: FileServiceProperties fileProperties = new FileServiceProperties(); fileProperties.Cors = serviceProperties.Cors; fileProperties.HourMetrics = serviceProperties.HourMetrics; fileProperties.MinuteMetrics = serviceProperties.MinuteMetrics; StorageAccount.CreateCloudFileClient().SetServiceProperties(fileProperties); break; } }
public void CreateExistingQueue() { string QUEUE_NAME = Utility.GenNameString("existing"); // create queue if not exists CloudQueue queue = StorageAccount.CreateCloudQueueClient().GetQueueReference(QUEUE_NAME); queue.CreateIfNotExists(); try { // Refer to: http://msdn.microsoft.com/en-us/library/azure/dd179342.aspx bool canCreateWithSameName = lang == Language.NodeJS; if (canCreateWithSameName) { //--------------New operation-------------- Test.Assert(CommandAgent.NewAzureStorageQueue(QUEUE_NAME), Utility.GenComparisonData("NewAzureStorageQueue", true)); // Verification for returned values Test.Assert(CommandAgent.Output.Count == 1, "Only 1 row returned : {0}", CommandAgent.Output.Count); } else { //--------------New operation-------------- Test.Assert(!CommandAgent.NewAzureStorageQueue(QUEUE_NAME), Utility.GenComparisonData("NewAzureStorageQueue", false)); // Verification for returned values Test.Assert(CommandAgent.Output.Count == 0, "Only 0 row returned : {0}", CommandAgent.Output.Count); CommandAgent.ValidateErrorMessage(MethodBase.GetCurrentMethod().Name, QUEUE_NAME); } } finally { // Recover the environment queue.DeleteIfExists(); } }
public async Task CloudQueueCreate_IfNotExist_CreatesQueue() { // Arrange StorageAccount storageAccount = CreateStorageAccount(); CloudStorageAccount sdkAccount = storageAccount.SdkObject; string queueName = GetQueueName("create-queue"); // Initialize using the SdkAccount directly. CloudQueue sdkQueue = GetQueueReference(sdkAccount, queueName); await sdkQueue.DeleteIfExistsAsync(); Assert.False(await sdkQueue.ExistsAsync()); try { // Make sure that using our StorageAccount uses the underlying SdkAccount CloudQueueClient client = storageAccount.CreateCloudQueueClient(); Assert.NotNull(client); // Guard CloudQueue queue = client.GetQueueReference(queueName); Assert.NotNull(queue); // Guard // Act await queue.CreateIfNotExistsAsync(CancellationToken.None); // Assert Assert.True(await sdkQueue.ExistsAsync()); } finally { if (await sdkQueue.ExistsAsync()) { await sdkQueue.DeleteAsync(); } } }
public QueueClient(string StorageConnectionString, string queueName) { StorageAccount = CloudStorageAccount.Parse(StorageConnectionString); CloudQueueClient = StorageAccount.CreateCloudQueueClient(); CloudQueue = CloudQueueClient.GetQueueReference(queueName); CloudQueue.CreateIfNotExistsAsync(); }
public QueueStoryRead() { StorageAccount = CloudStorageAccount.Parse( CloudConfigurationManager.GetSetting("StorageConnectionString")); QueueClient = StorageAccount.CreateCloudQueueClient(); Queue = QueueClient.GetQueueReference("myqueue"); }
private static async Task<CloudQueue> CreateQueue(StorageAccount account, string queueName) { var client = account.CreateCloudQueueClient(); CloudQueue queue = client.GetQueueReference(queueName); await queue.CreateIfNotExistsAsync(); return queue; }
protected QueueBase(string connectionString, IPolicyRegistry <string> policyRegistry, string policyRegistryKey, CancellationToken cancellationToken) { CancellationToken = cancellationToken; StorageAccount = CloudStorageAccount.Parse(connectionString); QueueClient = StorageAccount.CreateCloudQueueClient(); _cachingPolicy = policyRegistry.Get <ISyncPolicy <CloudQueue> >(policyRegistryKey); }
public CommRepository(StorageAccount storageAccount) { _blobClient = storageAccount.CreateCloudBlobClient(); _cloudTableClient = storageAccount.CreateCloudTableClient(); _cloudQueueClient = storageAccount.CreateCloudQueueClient(); }
public QueueRepository() { var connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["CfCloudStorage"].ConnectionString; StorageAccount = CloudStorageAccount.Parse(connectionString); QueueClient = StorageAccount.CreateCloudQueueClient(); QueueClient.RetryPolicy = RetryPolicies.Retry(4, TimeSpan.Zero); }
private static CloudQueue CreateQueue(StorageAccount account, string queueName) { var client = account.CreateCloudQueueClient(); var queue = client.GetQueueReference(queueName); queue.CreateIfNotExistsAsync().GetAwaiter().GetResult(); return(queue); }
public void EnumerateAllQueues() { //--------------Get operation-------------- Test.Assert(CommandAgent.GetAzureStorageQueue(""), Utility.GenComparisonData("EnumerateAllQueues", false)); // Verification for returned values CommandAgent.OutputValidation(StorageAccount.CreateCloudQueueClient().ListQueues()); }
public AzureQueueMatchmakeEventCallback(IConfiguration configuration) { string connectionString = configuration.GetValue <string>("AzureWebJobsStorage"); StorageAccount storageAccount = StorageAccount.NewFromConnectionString(connectionString); CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient(); _queue = queueClient.GetQueueReference(MatchmakerQueueFunctions.MatchmakerQueueName); }
public CloudClient(string connectionString) { // Create clients TableAccount = CloudStorageAccount.Parse(connectionString); StorageAccount = Microsoft.Azure.Storage.CloudStorageAccount.Parse(connectionString); Table = TableAccount.CreateCloudTableClient(); Blob = StorageAccount.CreateCloudBlobClient(); Queue = StorageAccount.CreateCloudQueueClient(); }
/// <summary> /// Adds the image entity to the queue /// </summary> /// <param name="record">entity to add</param> private async Task AddToQueue(ImageEntity record) { // TODO: should probably be optimized var qc = StorageAccount.CreateCloudQueueClient(); var queue = qc.GetQueueReference("imageprocessingqueue"); await queue.CreateIfNotExistsAsync(); await queue.AddMessageAsync(new Microsoft.WindowsAzure.Storage.Queue.CloudQueueMessage(JsonConvert.SerializeObject(record))); }
public DemoAzureStorageQueueService(ILogger <DemoQueueListenerService> logger, IStorageAccountFactory storageAccountFactory) { Logger = logger; StorageAccountFactory = storageAccountFactory; StorageAccountFactory.LoadStorageAccounts(); StorageAccount = StorageAccountFactory.GetAccount("imageStorage"); CloudQueue = StorageAccount.CreateCloudQueueClient().GetQueueReference("incoming"); }
/// <summary> /// Get a reference to a given queue. If one doesn't exist create it. /// </summary> /// <param name="queueName">Queue name.</param> /// <returns>Reference to the queue.</returns> private CloudQueue GetQueueReference( string queueName) { var queueClient = StorageAccount.CreateCloudQueueClient(); var queue = queueClient.GetQueueReference(queueName.ToLowerInvariant()); queue.CreateIfNotExists(); return(queue); }
public StorageRepository(StorageAccount storageAccount, CosmosClient cosmosClient) { _blobClient = storageAccount.CreateCloudBlobClient(); _cloudTableClient = storageAccount.CreateCloudTableClient(); _cloudQueueClient = storageAccount.CreateCloudQueueClient(); _cosmosClient = cosmosClient; var result = CreateStorageIfNotExists().Result; }
public static void ClearQueues() { CloudQueueClient client = StorageAccount.CreateCloudQueueClient(); string[] queues = { ServerRequestQueue, ServerResponseQueue, WorkerResponseQueue }; foreach (string queueName in queues) { CloudQueue queue = client.GetQueueReference(queueName); queue.CreateIfNotExist(); queue.Clear(); } }
public static bool PollForMessageRawCondition <T>(string queueName, Func <T, bool> action, int visibilityTimeoutSeconds = 30, Func <CloudQueueMessage, bool> condition = null) where T : AzureMessage { CloudQueue queue = StorageAccount.CreateCloudQueueClient().GetQueueReference(queueName); CloudQueueMessage queueMessage; queue.CreateIfNotExist(); queueMessage = queue.GetMessage(new TimeSpan(0, 0, visibilityTimeoutSeconds)); if (queueMessage == null) { return(false); } T message = AzureMessage.FromMessage(queueMessage) as T; if (condition != null && !condition.Invoke(queueMessage)) { // Force the message to become visible on the queue, because we don't want to process it. See AzureHelperTest.AddThenDeleteMessageTest for a demonstration that this works. queue.AddMessage(queueMessage); queue.DeleteMessage(queueMessage); return(false); } if (!action.Invoke(message)) { return(false); } try { queue.DeleteMessage(queueMessage); } catch (StorageClientException e) { // It took too long to process the message and the visibility timeout expired // See http://blog.smarx.com/posts/deleting-windows-azure-queue-messages-handling-exceptions if (e.ExtendedErrorInformation.ErrorCode == "MessageNotFound") { System.Diagnostics.Trace.WriteLine("Visibility timeout expired: " + e); return(false); } else { throw e; } } return(true); }
public async Task MaxDegreeOfParallelism_Queues(int batchSize, int maxExpectedParallelism) { _receivedMessages = 0; _currentSimultaneouslyRunningFunctions = 0; _maxSimultaneouslyRunningFunctions = 0; _numberOfQueueMessages = batchSize * 3; RandomNameResolver nameResolver = new RandomNameResolver(); IHost host = new HostBuilder() .ConfigureDefaultTestHost <ParallelExecutionTests>(b => { b.AddAzureStorage(); }) .ConfigureServices(services => { services.AddSingleton <INameResolver>(nameResolver); services.Configure <QueuesOptions>(o => o.BatchSize = batchSize); }) .Build(); StorageAccount storageAccount = host.GetStorageAccount(); _queueClient = storageAccount.CreateCloudQueueClient(); CloudQueue queue = _queueClient.GetQueueReference(nameResolver.ResolveInString(TestQueueName)); await queue.CreateIfNotExistsAsync(); for (int i = 0; i < _numberOfQueueMessages; i++) { int sleepTimeInSeconds = i % 2 == 0 ? 5 : 1; await queue.AddMessageAsync(new CloudQueueMessage(sleepTimeInSeconds.ToString())); } using (_allMessagesProcessed = new ManualResetEvent(initialState: false)) using (host) { await host.StartAsync(); _allMessagesProcessed.WaitOne(TimeSpan.FromSeconds(90)); await host.StopAsync(); } Assert.Equal(_numberOfQueueMessages, _receivedMessages); Assert.Equal(0, _currentSimultaneouslyRunningFunctions); // the actual value will vary sometimes based on the speed of the machine // running the test. int delta = _maxSimultaneouslyRunningFunctions - maxExpectedParallelism; Assert.True(delta == 0 || delta == 1, $"Expected delta of 0 or 1. Actual: {delta}."); }
public async Task RespondsToEnqueuedItem() { var marker = new MarkerMessage { MarkerId = Guid.NewGuid() }; string json = JsonConvert.SerializeObject(marker); CloudQueueClient queueClient = StorageAccount.CreateCloudQueueClient(); CloudQueue queue = queueClient.GetQueueReference("testqueue"); await queue.AddMessageAsync(new CloudQueueMessage(json)); await marker.Assert(); }
static async Task QueueArgs(string[] args) { CloudQueueClient client = StorageAccount.CreateCloudQueueClient(); CloudQueue queue = client.GetQueueReference(QueueName); await queue.CreateIfNotExistsAsync(); foreach (string arg in args) { Console.Write($"Queueing {arg}..."); await queue.AddMessageAsync(new CloudQueueMessage(arg)); Console.WriteLine(" queued."); } }
public void RemoveNonExistingQueue() { string QUEUE_NAME = Utility.GenNameString("nonexisting"); // Delete the queue if it exists CloudQueue queue = StorageAccount.CreateCloudQueueClient().GetQueueReference(QUEUE_NAME); queue.DeleteIfExists(); //--------------Remove operation-------------- Test.Assert(!CommandAgent.RemoveAzureStorageQueue(QUEUE_NAME), Utility.GenComparisonData("RemoveAzureStorageQueue", false)); // Verification for returned values Test.Assert(CommandAgent.Output.Count == 0, "Only 0 row returned : {0}", CommandAgent.Output.Count); CommandAgent.ValidateErrorMessage(MethodBase.GetCurrentMethod().Name, QUEUE_NAME); }
public static void EnqueueMessage(string queueName, AzureMessage message, bool async = false) { CloudQueue queue = StorageAccount.CreateCloudQueueClient().GetQueueReference(queueName); queue.CreateIfNotExist(); CloudQueueMessage queueMessage = new CloudQueueMessage(message.ToBinary()); if (async) { queue.BeginAddMessage(queueMessage, ar => { }, null); } else { queue.AddMessage(queueMessage); } }
public void SetLoggingVersion() { //Blob service CloudBlobClient blobClient = StorageAccount.CreateCloudBlobClient(); GenericSetLoggingVersion(ServiceType.Blob, () => blobClient.GetServiceProperties()); //Queue service CloudQueueClient queueClient = StorageAccount.CreateCloudQueueClient(); GenericSetLoggingVersion(ServiceType.Queue, () => queueClient.GetServiceProperties()); //Table service CloudTableClient tableClient = StorageAccount.CreateCloudTableClient(); GenericSetLoggingVersion(ServiceType.Table, () => tableClient.GetServiceProperties()); }
/// <summary> /// This method initializes the connector. /// </summary> public override void Initialize() { Client = StorageAccount.CreateCloudQueueClient(); if (RequestOptionsDefault != null) { Client.DefaultRequestOptions = RequestOptionsDefault; } if (ContainerId == null) { ContainerId = AzureStorageHelper.GetEnum <DataCollectionSupport>(Support).StringValue; } ContainerId = StorageServiceBase.ValidateAzureContainerName(ContainerId); Queue = Client.GetQueueReference(ContainerId); Queue.CreateIfNotExistsAsync().Wait(); }
public static void InitializeConnections() { string connectionString = SharedConfig.AzureStorageConnectionString; AzureStorage.StorageAccount = CloudStorageAccount.Parse(connectionString); CloudTableClient tableClient = StorageAccount.CreateCloudTableClient(); AccountTable = tableClient.GetTableReference("account"); AccountTable.CreateIfNotExists(); ActivityTable = tableClient.GetTableReference("activity"); ActivityTable.CreateIfNotExists(); CloudQueueClient queueClient = StorageAccount.CreateCloudQueueClient(); SubscriptionQueue = queueClient.GetQueueReference("subscriptions"); SubscriptionQueue.CreateIfNotExists(); }
public void SetMetricsVersion() { //Blob service CloudBlobClient blobClient = StorageAccount.CreateCloudBlobClient(); GenericSetMetricsVersion(ServiceType.Blob, () => blobClient.GetServiceProperties()); //Queue service CloudQueueClient queueClient = StorageAccount.CreateCloudQueueClient(); GenericSetMetricsVersion(ServiceType.Queue, () => queueClient.GetServiceProperties()); //Table service CloudTableClient tableClient = StorageAccount.CreateCloudTableClient(); GenericSetMetricsVersion(ServiceType.Table, () => tableClient.GetServiceProperties()); //File service GenericSetMetricsVersion(ServiceType.File, () => Utility.GetServiceProperties(StorageAccount, ServiceType.File)); }
public void RemoveQueueWithoutForce() { string QUEUE_NAME = Utility.GenNameString("withoutforce-"); // create queue if not exists CloudQueue queue = StorageAccount.CreateCloudQueueClient().GetQueueReference(QUEUE_NAME); queue.CreateIfNotExists(); try { //--------------Remove operation-------------- Test.Assert(!CommandAgent.RemoveAzureStorageQueue(QUEUE_NAME, false), Utility.GenComparisonData("RemoveAzureStorageQueue", false)); // Verification for returned values Test.Assert(CommandAgent.Output.Count == 0, "Only 0 row returned : {0}", CommandAgent.Output.Count); Test.Assert(CommandAgent.ErrorMessages[0].Contains("A command that prompts the user failed because"), CommandAgent.ErrorMessages[0]); } finally { queue.DeleteIfExists(); } }
public async void QueueStorageTest() { ClearOutput(); WriteLine("-- Testing Queue Storage --"); WriteLine("0. Creating queue client"); // Create a queue client for interacting with the queue service CloudQueueClient queueClient = StorageAccount.CreateCloudQueueClient(); WriteLine("1. Create a queue for the demo"); CloudQueue queue = queueClient.GetQueueReference("samplequeue"); try { await queue.CreateIfNotExistsAsync(); } catch (StorageException) { WriteLine("If you are running with the default configuration please make sure you have started the storage emulator. Press the Windows key and type Azure Storage to select and run it from the list of applications - then restart the sample."); throw; } // Demonstrate basic queue functionality await BasicQueueOperationsAsync(queue); // Demonstrate how to update an enqueued message await UpdateEnqueuedMessageAsync(queue); // Demonstrate advanced functionality such as processing of batches of messages await ProcessBatchOfMessagesAsync(queue); // When you delete a queue it could take several seconds before you can recreate a queue with the same // name - hence to enable you to run the demo in quick succession the queue is not deleted. If you want // to delete the queue uncomment the line of code below. await DeleteQueueAsync(queue); WriteLine("-- Test Complete --"); }