public FakeStorageQueue(MemoryQueueStore store, string queueName, IStorageQueueClient parent) { _store = store; _queueName = queueName; _parent = parent; _sdkObject = new CloudQueue(new Uri("http://localhost/" + queueName)); }
private static IStorageQueue CreateQueue(IStorageAccount account, string queueName) { IStorageQueueClient client = account.CreateQueueClient(); IStorageQueue queue = client.GetQueueReference(queueName); queue.CreateIfNotExists(); return queue; }
public async Task <IBinding> TryCreateAsync(BindingProviderContext context) { ParameterInfo parameter = context.Parameter; QueueAttribute queueAttribute = parameter.GetCustomAttribute <QueueAttribute>(inherit: false); if (queueAttribute == null) { return(null); } string queueName = Resolve(queueAttribute.QueueName); IBindableQueuePath path = BindableQueuePath.Create(queueName); path.ValidateContractCompatibility(context.BindingDataContract); IArgumentBinding <IStorageQueue> argumentBinding = _innerProvider.TryCreate(parameter); if (argumentBinding == null) { throw new InvalidOperationException("Can't bind Queue to type '" + parameter.ParameterType + "'."); } IStorageAccount account = await _accountProvider.GetStorageAccountAsync(context.CancellationToken); IStorageQueueClient client = account.CreateQueueClient(); IBinding binding = new QueueBinding(parameter.Name, argumentBinding, client, path); return(binding); }
public void CloudQueueCreate_IfNotExist_CreatesQueue() { // Arrange CloudStorageAccount sdkAccount = CreateSdkAccount(); string queueName = GetQueueName("create-queue"); CloudQueue sdkQueue = CreateSdkQueue(sdkAccount, queueName); try { IStorageAccount product = CreateProductUnderTest(sdkAccount); IStorageQueueClient client = product.CreateQueueClient(); Assert.NotNull(client); // Guard IStorageQueue queue = client.GetQueueReference(queueName); Assert.NotNull(queue); // Guard // Act queue.CreateIfNotExistsAsync(CancellationToken.None).GetAwaiter().GetResult(); // Assert Assert.True(sdkQueue.Exists()); } finally { if (sdkQueue.Exists()) { sdkQueue.Delete(); } } }
public async Task <IListener> CreateAsync(CancellationToken cancellationToken) { SharedQueueWatcher sharedQueueWatcher = _sharedContextProvider.GetOrCreate <SharedQueueWatcher>( new SharedQueueWatcherFactory(_messageEnqueuedWatcherSetter)); SharedBlobListener sharedBlobListener = _sharedContextProvider.GetOrCreate <SharedBlobListener>( new SharedBlobListenerFactory(_hostAccount, _backgroundExceptionDispatcher, _blobWrittenWatcherSetter)); // Note that these clients are intentionally for the storage account rather than for the dashboard account. // We use the storage, not dashboard, account for the blob receipt container and blob trigger queues. IStorageQueueClient queueClient = _hostAccount.CreateQueueClient(); IStorageBlobClient blobClient = _hostAccount.CreateBlobClient(); string hostId = await _hostIdProvider.GetHostIdAsync(cancellationToken); string hostBlobTriggerQueueName = HostQueueNames.GetHostBlobTriggerQueueName(hostId); IStorageQueue hostBlobTriggerQueue = queueClient.GetQueueReference(hostBlobTriggerQueueName); IListener blobDiscoveryToQueueMessageListener = await CreateBlobDiscoveryToQueueMessageListenerAsync( hostId, sharedBlobListener, blobClient, hostBlobTriggerQueue, sharedQueueWatcher, cancellationToken); // Important: We're using the "data account" here, which is the account that the // function the listener is for is targeting. This is the account that will be used // to read the trigger blob. IStorageBlobClient userBlobClient = _dataAccount.CreateBlobClient(); IListener queueMessageToTriggerExecutionListener = CreateQueueMessageToTriggerExecutionListener( _sharedContextProvider, sharedQueueWatcher, queueClient, hostBlobTriggerQueue, userBlobClient, sharedBlobListener.BlobWritterWatcher); IListener compositeListener = new CompositeListener( blobDiscoveryToQueueMessageListener, queueMessageToTriggerExecutionListener); return(compositeListener); }
public async Task <ITriggerBinding> TryCreateAsync(TriggerBindingProviderContext context) { ParameterInfo parameter = context.Parameter; QueueTriggerAttribute queueTrigger = parameter.GetCustomAttribute <QueueTriggerAttribute>(inherit: false); if (queueTrigger == null) { return(null); } string queueName = Resolve(queueTrigger.QueueName); queueName = NormalizeAndValidate(queueName); ITriggerDataArgumentBinding <IStorageQueueMessage> argumentBinding = InnerProvider.TryCreate(parameter); if (argumentBinding == null) { throw new InvalidOperationException( "Can't bind QueueTrigger to type '" + parameter.ParameterType + "'."); } IStorageAccount account = await _accountProvider.GetStorageAccountAsync(context.CancellationToken); IStorageQueueClient client = account.CreateQueueClient(); IStorageQueue queue = client.GetQueueReference(queueName); ITriggerBinding binding = new QueueTriggerBinding(parameter.Name, queue, argumentBinding, _queueConfiguration, _backgroundExceptionDispatcher, _messageEnqueuedWatcherSetter, _sharedContextProvider, _log); return(binding); }
public StorageQueueMessagePump(IStorageQueueClient storageQueueClient, IProcessingSettings settings, ILog log) { _storageQueueClient = storageQueueClient; _settings = settings; _log = log; _maxConcurrent = new SemaphoreSlim(_settings.MaxConcurrentCalls); }
public SharedBlobQueueListenerFactory( SharedQueueWatcher sharedQueueWatcher, IStorageQueueClient queueClient, IStorageQueue hostBlobTriggerQueue, IStorageBlobClient blobClient, IQueueConfiguration queueConfiguration, IBackgroundExceptionDispatcher backgroundExceptionDispatcher, TextWriter log, IBlobWrittenWatcher blobWrittenWatcher) { if (sharedQueueWatcher == null) { throw new ArgumentNullException("sharedQueueWatcher"); } if (queueClient == null) { throw new ArgumentNullException("queueClient"); } if (hostBlobTriggerQueue == null) { throw new ArgumentNullException("hostBlobTriggerQueue"); } if (blobClient == null) { throw new ArgumentNullException("blobClient"); } if (queueConfiguration == null) { throw new ArgumentNullException("queueConfiguration"); } if (backgroundExceptionDispatcher == null) { throw new ArgumentNullException("backgroundExceptionDispatcher"); } if (log == null) { throw new ArgumentNullException("log"); } if (blobWrittenWatcher == null) { throw new ArgumentNullException("blobWrittenWatcher"); } _sharedQueueWatcher = sharedQueueWatcher; _queueClient = queueClient; _hostBlobTriggerQueue = hostBlobTriggerQueue; _blobClient = blobClient; _queueConfiguration = queueConfiguration; _backgroundExceptionDispatcher = backgroundExceptionDispatcher; _log = log; _blobWrittenWatcher = blobWrittenWatcher; }
private static IObjectToTypeConverter <IStorageQueue> CreateConverter(IStorageQueueClient client, IBindableQueuePath path) { return(new CompositeObjectToTypeConverter <IStorageQueue>( new OutputConverter <IStorageQueue>(new IdentityConverter <IStorageQueue>()), new OutputConverter <CloudQueue>(new CloudQueueToStorageQueueConverter()), new OutputConverter <string>(new StringToStorageQueueConverter(client, path)))); }
private static IObjectToTypeConverter<IStorageQueue> CreateConverter(IStorageQueueClient client, IBindableQueuePath path) { return new CompositeObjectToTypeConverter<IStorageQueue>( new OutputConverter<IStorageQueue>(new IdentityConverter<IStorageQueue>()), new OutputConverter<CloudQueue>(new CloudQueueToStorageQueueConverter()), new OutputConverter<string>(new StringToStorageQueueConverter(client, path))); }
public static string GetAccountName(IStorageQueueClient client) { if (client == null) { return(null); } return(StorageClient.GetAccountName(client.Credentials)); }
private async Task Initialize() { var queueName = AutoMessageMapper.GetQueueName <T>(); _storageQueueClient = new StorageQueueClient(_storageOptions, queueName); await _storageQueueClient.CreateIfNotExistsAsync().ConfigureAwait(false); _messagePump = new StorageQueueMessagePump(_storageQueueClient, Settings, _hostConfiguration.Log); }
public static string GetAccountName(IStorageQueueClient client) { if (client == null) { return null; } return StorageClient.GetAccountName(client.Credentials); }
// Test that the credentials are valid and classify the account.Type as one of StorageAccountTypes private static async Task ValidateCredentialsAsyncCore(IStorageAccount account, CancellationToken cancellationToken) { // Verify the credentials are correct. // Have to actually ping a storage operation. IStorageBlobClient client = account.CreateBlobClient(); try { // This can hang for a long time if the account name is wrong. // If will fail fast if the password is incorrect. await client.GetServicePropertiesAsync(cancellationToken); } catch (OperationCanceledException) { throw; } catch (Exception e) { var storageException = e as StorageException; var isDevStoreAccount = GetIsDevStoreAccountFromCloudStorageAccount(account.SdkObject); if (storageException?.RequestInformation?.HttpStatusCode == 400 && storageException?.RequestInformation?.ExtendedErrorInformation?.ErrorCode == "InvalidQueryParameterValue") { // Premium storage accounts do not support the GetServicePropertiesAsync call, and respond with a 400 'InvalidQueryParameterValue'. // If we see this error response classify the account as a premium account account.Type = StorageAccountType.Premium; return; } else if (isDevStoreAccount) { // If using the storage emulator, it might not be running throw new InvalidOperationException(Constants.CheckAzureStorageEmulatorMessage, e); } else { // If not a recognized error, the credentials are invalid string message = String.Format(CultureInfo.CurrentCulture, "Invalid storage account '{0}'. Please make sure your credentials are correct.", account.Credentials.AccountName); throw new InvalidOperationException(message, e); } } IStorageQueueClient queueClient = account.CreateQueueClient(); IStorageQueue queue = queueClient.GetQueueReference("name"); try { await queue.ExistsAsync(cancellationToken); } catch (StorageException exception) when(IsBlobOnlyStorageException(exception)) { account.Type = StorageAccountType.BlobOnly; } }
public QueueBinding(string parameterName, IArgumentBinding <IStorageQueue> argumentBinding, IStorageQueueClient client, IBindableQueuePath path) { _parameterName = parameterName; _argumentBinding = argumentBinding; _client = client; _accountName = QueueClient.GetAccountName(client); _path = path; _converter = CreateConverter(client, path); }
public QueueBinding(string parameterName, IArgumentBinding<IStorageQueue> argumentBinding, IStorageQueueClient client, IBindableQueuePath path) { _parameterName = parameterName; _argumentBinding = argumentBinding; _client = client; _accountName = QueueClient.GetAccountName(client); _path = path; _converter = CreateConverter(client, path); }
private async Task ValidateCredentialsAsyncCore(IStorageAccount account, bool isPrimaryAccount, CancellationToken cancellationToken) { // Verify the credentials are correct. // Have to actually ping a storage operation. IStorageBlobClient client = account.CreateBlobClient(); try { // This can hang for a long time if the account name is wrong. // If will fail fast if the password is incorrect. await client.GetServicePropertiesAsync(cancellationToken); } catch (OperationCanceledException) { throw; } catch { string message = String.Format(CultureInfo.CurrentCulture, "Invalid storage account '{0}'. Please make sure your credentials are correct.", account.Credentials.AccountName); throw new InvalidOperationException(message); } if (isPrimaryAccount) { // Primary storage accounts require Queues IStorageQueueClient queueClient = account.CreateQueueClient(); IStorageQueue queue = queueClient.GetQueueReference("name"); try { await queue.ExistsAsync(cancellationToken); _primaryCredentials = account.Credentials; } catch (OperationCanceledException) { throw; } catch (StorageException exception) { WebException webException = exception.GetBaseException() as WebException; if (webException != null && webException.Status == WebExceptionStatus.NameResolutionFailure) { string message = String.Format(CultureInfo.CurrentCulture, "Invalid storage account '{0}'. Primary storage accounts must be general " + "purpose accounts and not restricted blob storage accounts.", account.Credentials.AccountName); throw new InvalidOperationException(message); } throw; } } }
public FakeQueueProcessor(QueueProcessorFactoryContext context, IStorageAccount storageAccount) : base(context) { // map the queue names from the context to fake queues IStorageQueueClient client = storageAccount.CreateQueueClient(); _queue = client.GetQueueReference(context.Queue.Name); if (context.PoisonQueue != null) { _poisonQueue = client.GetQueueReference(context.PoisonQueue.Name); } }
public SharedBlobQueueListenerFactory( SharedQueueWatcher sharedQueueWatcher, IStorageQueueClient queueClient, IStorageQueue hostBlobTriggerQueue, IQueueConfiguration queueConfiguration, IWebJobsExceptionHandler exceptionHandler, TraceWriter trace, IBlobWrittenWatcher blobWrittenWatcher) { if (sharedQueueWatcher == null) { throw new ArgumentNullException("sharedQueueWatcher"); } if (queueClient == null) { throw new ArgumentNullException("queueClient"); } if (hostBlobTriggerQueue == null) { throw new ArgumentNullException("hostBlobTriggerQueue"); } if (queueConfiguration == null) { throw new ArgumentNullException("queueConfiguration"); } if (exceptionHandler == null) { throw new ArgumentNullException("exceptionHandler"); } if (trace == null) { throw new ArgumentNullException("trace"); } if (blobWrittenWatcher == null) { throw new ArgumentNullException("blobWrittenWatcher"); } _sharedQueueWatcher = sharedQueueWatcher; _queueClient = queueClient; _hostBlobTriggerQueue = hostBlobTriggerQueue; _queueConfiguration = queueConfiguration; _exceptionHandler = exceptionHandler; _trace = trace; _blobWrittenWatcher = blobWrittenWatcher; }
// [Queue] has some pre-existing behavior where the storage account can be specified outside of the [Queue] attribute. // The storage account is pulled from the ParameterInfo (which could pull in a [Storage] attribute on the container class) // Resolve everything back down to a single attribute so we can use the binding helpers. // This pattern should be rare since other extensions can just keep everything directly on the primary attribute. private async Task <QueueAttribute> CollectAttributeInfo(QueueAttribute attrResolved, ParameterInfo parameter, INameResolver nameResolver) { // Look for [Storage] attribute and squirrel over IStorageAccount account = await _accountProvider.GetStorageAccountAsync(parameter, CancellationToken.None, nameResolver); StorageClientFactoryContext clientFactoryContext = new StorageClientFactoryContext { Parameter = parameter }; IStorageQueueClient client = account.CreateQueueClient(clientFactoryContext); return(new ResolvedQueueAttribute(attrResolved.QueueName, client)); }
private void RegisterWithSharedBlobQueueListenerAsync( SharedBlobQueueListener sharedBlobQueueListener, IStorageBlobClient blobClient, IStorageQueueClient queueClient) { BlobQueueRegistration registration = new BlobQueueRegistration { Executor = _executor, BlobClient = blobClient, QueueClient = queueClient }; sharedBlobQueueListener.Register(_functionId, registration); }
private IListener CreateQueueMessageToTriggerExecutionListener(IFunctionExecutor executor, ISharedContextProvider sharedContextProvider, SharedQueueWatcher sharedQueueWatcher, IStorageQueueClient queueClient, IStorageQueue hostBlobTriggerQueue, IStorageBlobClient blobClient, IBlobWrittenWatcher blobWrittenWatcher) { SharedBlobQueueListener sharedListener = sharedContextProvider.GetOrCreate <SharedBlobQueueListener>( new SharedBlobQueueListenerFactory(executor, sharedQueueWatcher, queueClient, hostBlobTriggerQueue, blobClient, _queueConfiguration, _backgroundExceptionDispatcher, _log, blobWrittenWatcher)); sharedListener.Register(_functionId, _instanceFactory); return(new BlobListener(sharedListener)); }
public void Queue_IfBoundToCloudQueue_BindsAndCreatesQueue() { // Arrange IStorageAccount account = CreateFakeStorageAccount(); IStorageQueueClient client = account.CreateQueueClient(); IStorageQueue triggerQueue = CreateQueue(client, TriggerQueueName); triggerQueue.AddMessage(triggerQueue.CreateMessage("ignore")); // Act CloudQueue result = RunTrigger <CloudQueue>(account, typeof(BindToCloudQueueProgram), (s) => BindToCloudQueueProgram.TaskSource = s); // Assert Assert.NotNull(result); Assert.Equal(QueueName, result.Name); IStorageQueue queue = client.GetQueueReference(QueueName); Assert.True(queue.Exists()); }
public TestFixture() { DefaultStorageAccountProvider accountProvider = new DefaultStorageAccountProvider(); var task = accountProvider.GetStorageAccountAsync(CancellationToken.None); task.Wait(); IStorageQueueClient client = task.Result.CreateQueueClient(); QueueClient = client.SdkObject; string queueName = string.Format("{0}-{1}", TestQueuePrefix, Guid.NewGuid()); Queue = client.GetQueueReference(queueName).SdkObject; Queue.CreateIfNotExistsAsync(CancellationToken.None).Wait(); string poisonQueueName = string.Format("{0}-poison", queueName); PoisonQueue = client.GetQueueReference(poisonQueueName).SdkObject; PoisonQueue.CreateIfNotExistsAsync(CancellationToken.None).Wait(); }
private async Task HandleItemsAsync(IStorageQueueClient queueClient, IDocumentTypedCollectionClient <ActivityFeedQueueItem> documentClient) { var messages = await queueClient.DequeueMessagesAsync <ActivityFeedQueueItem>("activityfeed-items", batchSize : 10); if (messages.IsEmpty) { return; } foreach (var message in messages) { logger.LogDebug($"Handling {nameof(ActivityFeedQueueItem)}s"); message.Created = DateTime.UtcNow; await documentClient.CreateAsync(message); } await messages.DeleteBatch(); logger.LogInformation("ActivityFeedQueueItem messages handled and deleted."); }
public async Task <ITriggerBinding> TryCreateAsync(TriggerBindingProviderContext context) { ParameterInfo parameter = context.Parameter; var queueTrigger = TypeUtility.GetResolvedAttribute <QueueTriggerAttribute>(context.Parameter); if (queueTrigger == null) { return(null); } string queueName = Resolve(queueTrigger.QueueName); queueName = NormalizeAndValidate(queueName); ITriggerDataArgumentBinding <IStorageQueueMessage> argumentBinding = InnerProvider.TryCreate(parameter); if (argumentBinding == null) { throw new InvalidOperationException( "Can't bind QueueTrigger to type '" + parameter.ParameterType + "'."); } IStorageAccount account = await _accountProvider.GetStorageAccountAsync(queueTrigger, context.CancellationToken, _nameResolver); // requires storage account with queue support account.AssertTypeOneOf(StorageAccountType.GeneralPurpose); StorageClientFactoryContext clientFactoryContext = new StorageClientFactoryContext { Parameter = parameter }; IStorageQueueClient client = account.CreateQueueClient(clientFactoryContext); IStorageQueue queue = client.GetQueueReference(queueName); ITriggerBinding binding = new QueueTriggerBinding(parameter.Name, queue, argumentBinding, _queueConfiguration, _exceptionHandler, _messageEnqueuedWatcherSetter, _sharedContextProvider, _loggerFactory); return(binding); }
private static IStorageQueue CreatePoisonQueueReference(IStorageQueueClient client, string name) { Debug.Assert(client != null); // Only use a corresponding poison queue if: // 1. The poison queue name would be valid (adding "-poison" doesn't make the name too long), and // 2. The queue itself isn't already a poison queue. if (name == null || name.EndsWith(poisonQueueSuffix, StringComparison.Ordinal)) { return(null); } string possiblePoisonQueueName = name + poisonQueueSuffix; if (!QueueClient.IsValidQueueName(possiblePoisonQueueName)) { return(null); } return(client.GetQueueReference(possiblePoisonQueueName)); }
// initialize following fields async // _triggerExecutor --> register messageHandler // _sharedQueuelistener --> dequeue messages and call messageHandler // _sharedQueueWriter --> enqueue messages internal async Task InitializeAsync(CancellationToken cancellationToken) { if (_state != State.Created) { // only initialized once, since _state is incremental throw new InvalidOperationException(ErrorMessage(State.Created, _state)); } // concurrent dictionary that we can register messageHandler _triggerExecutor = new SharedQueueExecutor(); try { IStorageQueueClient primaryQueueClient = (await _accountProvider.GetStorageAccountAsync(cancellationToken)).CreateQueueClient(); string hostId = await _hostIdProvider.GetHostIdAsync(cancellationToken); // one host level shared queue // queue is not created here, only after 1st message added IStorageQueue sharedQueue = primaryQueueClient.GetQueueReference(HostQueueNames.GetHostSharedQueueName(hostId)); // default host level poison queue IStorageQueue sharedPoisonQueue = primaryQueueClient.GetQueueReference(HostQueueNames.GetHostSharedPoisonQueueName(hostId)); // queueWatcher will update queueListener's polling interval when queueWriter performes an enqueue operation SharedQueueWatcher sharedQueueWatcher = _sharedContextProvider.GetOrCreateInstance <SharedQueueWatcher>( new SharedQueueWatcherFactory(_messageEnqueuedWatcherSetter)); _sharedQueueWriter = new SharedQueueWriter(sharedQueue, sharedQueueWatcher); // use default poisonQueue setup _sharedQueuelistener = new QueueListener(sharedQueue, sharedPoisonQueue, _triggerExecutor, _exceptionHandler, _loggerFactory, sharedQueueWatcher, _queueConfiguration); } catch (Exception ex) { // initialization exception will fail all registrations _initializationEx = ex; } _state = State.Initialized; }
private IListener CreateQueueMessageToTriggerExecutionListener( ISharedContextProvider sharedContextProvider, SharedQueueWatcher sharedQueueWatcher, IStorageQueueClient queueClient, IStorageQueue hostBlobTriggerQueue, IStorageBlobClient blobClient, IBlobWrittenWatcher blobWrittenWatcher) { SharedBlobQueueListener sharedListener = sharedContextProvider.GetOrCreate <SharedBlobQueueListener>( new SharedBlobQueueListenerFactory(sharedQueueWatcher, queueClient, hostBlobTriggerQueue, _queueConfiguration, _backgroundExceptionDispatcher, _trace, blobWrittenWatcher)); BlobQueueRegistration registration = new BlobQueueRegistration { Executor = _executor, BlobClient = blobClient }; sharedListener.Register(_functionId, registration); return(new BlobListener(sharedListener)); }
public TestFixture() { Mock <IServiceProvider> services = new Mock <IServiceProvider>(MockBehavior.Strict); StorageClientFactory clientFactory = new StorageClientFactory(); services.Setup(p => p.GetService(typeof(StorageClientFactory))).Returns(clientFactory); DefaultStorageAccountProvider accountProvider = new DefaultStorageAccountProvider(services.Object); var task = accountProvider.GetStorageAccountAsync(CancellationToken.None); IStorageQueueClient client = task.Result.CreateQueueClient(); QueueClient = client.SdkObject; string queueName = string.Format("{0}-{1}", TestQueuePrefix, Guid.NewGuid()); Queue = client.GetQueueReference(queueName).SdkObject; Queue.CreateIfNotExistsAsync(null, null, CancellationToken.None).Wait(); string poisonQueueName = string.Format("{0}-poison", queueName); PoisonQueue = client.GetQueueReference(poisonQueueName).SdkObject; PoisonQueue.CreateIfNotExistsAsync(null, null, CancellationToken.None).Wait(); }
public void Queue_IfBoundToICollectorCloudQueueMessage_AddEnqueuesMessage() { // Arrange string expectedContent = Guid.NewGuid().ToString(); IStorageAccount account = CreateFakeStorageAccount(); IStorageQueueClient client = account.CreateQueueClient(); IStorageQueue triggerQueue = CreateQueue(client, TriggerQueueName); triggerQueue.AddMessage(triggerQueue.CreateMessage(expectedContent)); // Act RunTrigger <object>(account, typeof(BindToICollectorCloudQueueMessageProgram), (s) => BindToICollectorCloudQueueMessageProgram.TaskSource = s); // Assert IStorageQueue queue = client.GetQueueReference(QueueName); IEnumerable <IStorageQueueMessage> messages = queue.GetMessages(messageCount: 10); Assert.NotNull(messages); Assert.Equal(1, messages.Count()); IStorageQueueMessage message = messages.Single(); Assert.Equal(expectedContent, message.AsString); }
public async Task CloudQueueAddMessage_AddsMessage() { // Arrange CloudStorageAccount sdkAccount = CreateSdkAccount(); string queueName = GetQueueName("add-message"); CloudQueue sdkQueue = CreateSdkQueue(sdkAccount, queueName); await sdkQueue.CreateIfNotExistsAsync(); try { string expectedContent = "hello"; IStorageAccount product = CreateProductUnderTest(sdkAccount); IStorageQueueClient client = product.CreateQueueClient(); Assert.NotNull(client); // Guard IStorageQueue queue = client.GetQueueReference(queueName); Assert.NotNull(queue); // Guard IStorageQueueMessage message = queue.CreateMessage(expectedContent); Assert.NotNull(message); // Guard // Act queue.AddMessageAsync(message, CancellationToken.None).GetAwaiter().GetResult(); // Assert CloudQueueMessage sdkMessage = await sdkQueue.GetMessageAsync(); Assert.NotNull(sdkMessage); Assert.Equal(expectedContent, sdkMessage.AsString); } finally { await sdkQueue.DeleteAsync(); } }
/// <summary>Initializes a new instance of the <see cref="StorageQueue"/> class.</summary> /// <param name="parent">The parent queue client.</param> /// <param name="sdk">The SDK queue to wrap.</param> public StorageQueue(IStorageQueueClient parent, CloudQueue sdk) { _parent = parent; _sdk = sdk; }
private static IStorageQueue CreatePoisonQueueReference(IStorageQueueClient client, string name) { Debug.Assert(client != null); // Only use a corresponding poison queue if: // 1. The poison queue name would be valid (adding "-poison" doesn't make the name too long), and // 2. The queue itself isn't already a poison queue. if (name == null || name.EndsWith(poisonQueueSuffix, StringComparison.Ordinal)) { return null; } string possiblePoisonQueueName = name + poisonQueueSuffix; if (!QueueClient.IsValidQueueName(possiblePoisonQueueName)) { return null; } return client.GetQueueReference(possiblePoisonQueueName); }
private IListener CreateQueueMessageToTriggerExecutionListener( ISharedContextProvider sharedContextProvider, SharedQueueWatcher sharedQueueWatcher, IStorageQueueClient queueClient, IStorageQueue hostBlobTriggerQueue, IStorageBlobClient blobClient, IBlobWrittenWatcher blobWrittenWatcher) { SharedBlobQueueListener sharedListener = sharedContextProvider.GetOrCreate<SharedBlobQueueListener>( new SharedBlobQueueListenerFactory(sharedQueueWatcher, queueClient, hostBlobTriggerQueue, blobClient, _queueConfiguration, _backgroundExceptionDispatcher, _log, blobWrittenWatcher)); sharedListener.Register(_functionId, _executor); return new BlobListener(sharedListener); }