public void Trigger_IfClassConstructorHasDependencies_CanUseCustomJobActivator() { // Arrange const string expectedResult = "abc"; Mock <IFactory <string> > resultFactoryMock = new Mock <IFactory <string> >(MockBehavior.Strict); resultFactoryMock.Setup(f => f.Create()).Returns(expectedResult); IFactory <string> resultFactory = resultFactoryMock.Object; Mock <IJobActivator> activatorMock = new Mock <IJobActivator>(MockBehavior.Strict); activatorMock.Setup(a => a.CreateInstance <InstanceCustomActivatorProgram>()) .Returns(() => new InstanceCustomActivatorProgram(resultFactory)); IJobActivator activator = activatorMock.Object; CloudQueueMessage message = new CloudQueueMessage("ignore"); IStorageAccount account = CreateFakeStorageAccount(); IStorageQueue queue = CreateQueue(account, QueueName); queue.AddMessage(new FakeStorageQueueMessage(message)); // Act string result = RunTrigger <string>(account, typeof(InstanceCustomActivatorProgram), (s) => InstanceCustomActivatorProgram.TaskSource = s, activator); // Assert Assert.Same(expectedResult, result); }
public void Table_IfBoundToICollectorPoco_AddInsertsEntity() { // Arrange const string expectedValue = "abc"; IStorageAccount account = CreateFakeStorageAccount(); IStorageQueue triggerQueue = CreateQueue(account, TriggerQueueName); triggerQueue.AddMessage(triggerQueue.CreateMessage(expectedValue)); // Act RunTrigger(account, typeof(BindToICollectorPocoProgram)); // Assert IStorageTableClient client = account.CreateTableClient(); IStorageTable table = client.GetTableReference(TableName); Assert.True(table.Exists()); DynamicTableEntity entity = table.Retrieve <DynamicTableEntity>(PartitionKey, RowKey); Assert.NotNull(entity); Assert.NotNull(entity.Properties); Assert.True(entity.Properties.ContainsKey(PropertyName)); EntityProperty property = entity.Properties[PropertyName]; Assert.NotNull(property); Assert.Equal(EdmType.String, property.PropertyType); Assert.Equal(expectedValue, property.StringValue); }
public Task <IValueProvider> BindAsync(BindingContext context) { string boundQueueName = _path.Bind(context.BindingData); IStorageQueue queue = _client.GetQueueReference(boundQueueName); return(BindQueueAsync(queue, context.ValueContext)); }
public NonNullConverterValueBinder(IStorageQueue queue, IConverter <TInput, IStorageQueueMessage> converter, IMessageEnqueuedWatcher messageEnqueuedWatcher) { _queue = queue; _converter = converter; _messageEnqueuedWatcher = messageEnqueuedWatcher; }
private async Task <IStorageQueue> BuildClientFromQueueAttributeAsync(QueueAttribute attrResolved) { IStorageQueue queue = GetQueue(attrResolved); await queue.CreateIfNotExistsAsync(CancellationToken.None); return(queue); }
public static async Task AddMessageAndCreateIfNotExistsAsync(this IStorageQueue queue, IStorageQueueMessage message, CancellationToken cancellationToken) { if (queue == null) { throw new ArgumentNullException("queue"); } bool isQueueNotFoundException = false; try { await queue.AddMessageAsync(message, cancellationToken); return; } catch (StorageException exception) { if (!exception.IsNotFoundQueueNotFound()) { throw; } isQueueNotFoundException = true; } Debug.Assert(isQueueNotFoundException); await queue.CreateIfNotExistsAsync(cancellationToken); await queue.AddMessageAsync(message, cancellationToken); }
private static IStorageQueue GetQueue(QueueAttribute attrResolved) { var attr = (ResolvedQueueAttribute)attrResolved; IStorageQueue queue = attr.GetQueue(); return(queue); }
public void Table_IfBoundToICollectorJObject_AddInsertsEntity() { // Arrange const string expectedValue = "abc"; IStorageAccount account = CreateFakeStorageAccount(); IStorageQueue triggerQueue = CreateQueue(account, TriggerQueueName); triggerQueue.AddMessage(triggerQueue.CreateMessage(expectedValue)); // Act RunTrigger(account, typeof(BindToICollectorJObjectProgram)); // Assert IStorageTableClient client = account.CreateTableClient(); IStorageTable table = client.GetTableReference(TableName); Assert.True(table.Exists()); DynamicTableEntity entity = table.Retrieve <DynamicTableEntity>(PartitionKey, RowKey); Assert.NotNull(entity); Assert.NotNull(entity.Properties); AssertPropertyValue(entity, "ValueStr", "abcdef"); AssertPropertyValue(entity, "ValueNum", 123); }
public async Task 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 await queue.CreateIfNotExistsAsync(CancellationToken.None); // Assert Assert.True(await sdkQueue.ExistsAsync()); } finally { if (await sdkQueue.ExistsAsync()) { await sdkQueue.DeleteAsync(); } } }
public void QueueTrigger_IfBoundToPocoAndMessageIsNotJson_DoesNotBind() { // Arrange const string content = "not json"; // Not a valid JSON byte sequence. IStorageAccount account = CreateFakeStorageAccount(); IStorageQueue queue = CreateQueue(account, QueueName); IStorageQueueMessage message = queue.CreateMessage(content); queue.AddMessage(message); // Act Exception exception = RunTriggerFailure <Poco>(account, typeof(BindToPocoProgram), (s) => BindToPocoProgram.TaskSource = s); // Assert Assert.IsType <InvalidOperationException>(exception); Assert.Equal("Exception binding parameter 'message'", exception.Message); Exception innerException = exception.InnerException; Assert.IsType <InvalidOperationException>(innerException); const string expectedInnerMessage = "Binding parameters to complex objects (such as 'Poco') uses " + "Json.NET serialization. \r\n1. Bind the parameter type as 'string' instead of 'Poco' to get the raw " + "values and avoid JSON deserialization, or\r\n2. Change the queue payload to be valid json. The JSON " + "parser failed: Unexpected character encountered while parsing value: n. Path '', line 0, position " + "0.\r\n"; Assert.Equal(expectedInnerMessage, innerException.Message); }
private IStorageQueueMessage ConvertStringToCloudQueueMessage(string arg, QueueAttribute attrResolved) { IStorageQueue queue = GetQueue(attrResolved); var msg = queue.CreateMessage(arg); return(msg); }
/// <summary> /// Mockable Constructor /// </summary> public DataStore(IImaging imaging, IContainer container, ITableStorage table, IStorageQueue queue, INaming naming, uint cacheControlDuration = 31536000) { if (null == imaging) { throw new ArgumentNullException("imaging"); } if (null == container) { throw new ArgumentNullException("container"); } if (null == table) { throw new ArgumentNullException("table"); } if (null == queue) { throw new ArgumentNullException("queue"); } if (null == naming) { throw new ArgumentNullException("naming"); } this.imaging = imaging; this.container = container; this.table = table; this.queue = queue; this.naming = naming; this.cacheControlDuration = cacheControlDuration < 0 ? 31536000 : cacheControlDuration; }
public void QueueTrigger_ProvidesPocoComplexPropertyBindingData() { // Arrange Poco expectedChild = new Poco { Value = "abc", Int32Value = 123 }; IStorageAccount account = CreateFakeStorageAccount(); IStorageQueue queue = CreateQueue(account, QueueName); Poco value = new Poco { Child = expectedChild }; string content = JsonConvert.SerializeObject(value, typeof(Poco), settings: null); IStorageQueueMessage message = queue.CreateMessage(content); queue.AddMessage(message); // Act Poco result = RunTrigger <Poco>(account, typeof(BindToPocoComplexPropertyBindingDataProgram), (s) => BindToPocoComplexPropertyBindingDataProgram.TaskSource = s); // Assert AssertEqual(expectedChild, result); }
private static IObjectToTypeConverter <IStorageQueueMessage> CreateConverter(IStorageQueue queue) { return(new CompositeObjectToTypeConverter <IStorageQueueMessage>( new OutputConverter <IStorageQueueMessage>(new IdentityConverter <IStorageQueueMessage>()), new OutputConverter <CloudQueueMessage>(new CloudQueueMessageToStorageQueueMessageConverter()), new OutputConverter <string>(new StringToStorageQueueMessageConverter(queue)))); }
protected override void Init(IDictionary <string, string> arguments, CancellationToken cancellationToken) { var gallery = arguments.GetOrThrow <string>(Arguments.Gallery); var index = arguments.GetOrThrow <string>(Arguments.Index); var packageBaseAddress = arguments.GetOrThrow <string>(Arguments.ContentBaseAddress); var source = arguments.GetOrThrow <string>(Arguments.Source); var requireSignature = arguments.GetOrDefault(Arguments.RequireSignature, false); var verbose = arguments.GetOrDefault(Arguments.Verbose, false); CommandHelpers.AssertAzureStorage(arguments); var monitoringStorageFactory = CommandHelpers.CreateStorageFactory(arguments, verbose); var auditingStorageFactory = CommandHelpers.CreateSuffixedStorageFactory("Auditing", arguments, verbose); var endpointInputs = CommandHelpers.GetEndpointFactoryInputs(arguments); var messageHandlerFactory = CommandHelpers.GetHttpMessageHandlerFactory(TelemetryService, verbose); Logger.LogInformation( "CONFIG gallery: {Gallery} index: {Index} storage: {Storage} auditingStorage: {AuditingStorage} endpoints: {Endpoints}", gallery, index, monitoringStorageFactory, auditingStorageFactory, string.Join(", ", endpointInputs.Select(e => e.Name))); _packageValidator = new PackageValidatorFactory(LoggerFactory) .Create(gallery, index, packageBaseAddress, auditingStorageFactory, endpointInputs, messageHandlerFactory, requireSignature, verbose); _queue = CommandHelpers.CreateStorageQueue <PackageValidatorContext>(arguments, PackageValidatorContext.Version); _statusService = CommandHelpers.GetPackageMonitoringStatusService(arguments, monitoringStorageFactory, LoggerFactory); _notificationService = new LoggerMonitoringNotificationService(LoggerFactory.CreateLogger <LoggerMonitoringNotificationService>()); _regResource = Repository.Factory.GetCoreV3(index).GetResource <RegistrationResourceV3>(cancellationToken); _client = new CollectorHttpClient(messageHandlerFactory()); }
private IStorageQueueMessage ConvertByteArrayToCloudQueueMessage(byte[] arg, QueueAttribute attrResolved) { IStorageQueue queue = GetQueue(attrResolved); var msg = queue.CreateMessage(arg); return(msg); }
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 async Task <IListener> CreateAsync(IFunctionExecutor executor, CancellationToken cancellationToken) { SharedQueueWatcher sharedQueueWatcher = _sharedContextProvider.GetOrCreate <SharedQueueWatcher>( new SharedQueueWatcherFactory(_messageEnqueuedWatcherSetter)); SharedBlobListener sharedBlobListener = _sharedContextProvider.GetOrCreate <SharedBlobListener>( new SharedBlobListenerFactory(_account, _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 = _account.CreateQueueClient(); IStorageBlobClient blobClient = _account.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); IListener queueMessageToTriggerExecutionListener = CreateQueueMessageToTriggerExecutionListener(executor, _sharedContextProvider, sharedQueueWatcher, queueClient, hostBlobTriggerQueue, blobClient, sharedBlobListener.BlobWritterWatcher); IListener compositeListener = new CompositeListener( blobDiscoveryToQueueMessageListener, queueMessageToTriggerExecutionListener); return(compositeListener); }
public void TableEntity_IfBoundToExistingPoco_Binds() { // Arrange const string expectedValue = "abc"; IStorageAccount account = CreateFakeStorageAccount(); IStorageQueue triggerQueue = CreateQueue(account, TriggerQueueName); triggerQueue.AddMessage(triggerQueue.CreateMessage("ignore")); IStorageTable table = CreateTable(account, TableName); Dictionary <string, EntityProperty> properties = new Dictionary <string, EntityProperty> { { "Value", new EntityProperty(expectedValue) } }; table.Insert(new DynamicTableEntity(PartitionKey, RowKey, etag: null, properties: properties)); // Act Poco result = RunTrigger <Poco>(account, typeof(BindToPocoProgram), (s) => BindToPocoProgram.TaskSource = s); // Assert Assert.NotNull(result); Assert.Equal(expectedValue, result.Value); }
public void TableEntity_IfUpdatesPoco_Persists() { // Arrange const string originalValue = "abc"; const string expectedValue = "def"; IStorageAccount account = CreateFakeStorageAccount(); IStorageQueue triggerQueue = CreateQueue(account, TriggerQueueName); triggerQueue.AddMessage(triggerQueue.CreateMessage(expectedValue)); IStorageTable table = CreateTable(account, TableName); Dictionary <string, EntityProperty> originalProperties = new Dictionary <string, EntityProperty> { { "Value", new EntityProperty(originalValue) } }; table.Insert(new DynamicTableEntity(PartitionKey, RowKey, etag: null, properties: originalProperties)); // Act RunTrigger(account, typeof(UpdatePocoProgram)); // Assert DynamicTableEntity entity = table.Retrieve <DynamicTableEntity>(PartitionKey, RowKey); Assert.NotNull(entity); IDictionary <string, EntityProperty> properties = entity.Properties; Assert.NotNull(properties); Assert.True(properties.ContainsKey("Value")); EntityProperty property = properties["Value"]; Assert.NotNull(property); Assert.Equal(EdmType.String, property.PropertyType); Assert.Equal(expectedValue, property.StringValue); }
public void TableEntity_IfBoundToExistingDynamicTableEntity_Binds() { // Arrange const string expectedKey = "abc"; const int expectedValue = 123; IStorageAccount account = CreateFakeStorageAccount(); IStorageQueue triggerQueue = CreateQueue(account, TriggerQueueName); triggerQueue.AddMessage(triggerQueue.CreateMessage("ignore")); IStorageTable table = CreateTable(account, TableName); Dictionary <string, EntityProperty> properties = new Dictionary <string, EntityProperty> { { expectedKey, new EntityProperty(expectedValue) } }; table.Insert(new DynamicTableEntity(PartitionKey, RowKey, etag: null, properties: properties)); // Act DynamicTableEntity result = RunTrigger <DynamicTableEntity>(account, typeof(BindToDynamicTableEntityProgram), (s) => BindToDynamicTableEntityProgram.TaskSource = s); // Assert Assert.NotNull(result); Assert.Equal(PartitionKey, result.PartitionKey); Assert.Equal(RowKey, result.RowKey); Assert.NotNull(result.Properties); Assert.True(result.Properties.ContainsKey(expectedKey)); EntityProperty property = result.Properties[expectedKey]; Assert.NotNull(property); Assert.Equal(EdmType.Int32, property.PropertyType); Assert.Equal(expectedValue, property.Int32Value); }
public void TableEntity_IfUpdatesRowKey_Throws() { // Arrange IStorageAccount account = CreateFakeStorageAccount(); IStorageQueue triggerQueue = CreateQueue(account, TriggerQueueName); triggerQueue.AddMessage(triggerQueue.CreateMessage("ignore")); IStorageTable table = CreateTable(account, TableName); table.Insert(new DynamicTableEntity(PartitionKey, RowKey)); // Act Exception exception = RunTriggerFailure(account, typeof(UpdatePocoRowKeyProgram)); // Assert Assert.NotNull(exception); Assert.IsType <InvalidOperationException>(exception); Assert.Equal("Error while handling parameter entity after function returned:", exception.Message); Exception innerException = exception.InnerException; Assert.NotNull(innerException); Assert.IsType <InvalidOperationException>(innerException); Assert.Equal("When binding to a table entity, the row key must not be changed.", innerException.Message); }
public void TableEntity_IfUpdatesPoco_PersistsUsingNativeTableTypes() { // Arrange byte[] originalValue = new byte[] { 0x12, 0x34 }; byte[] expectedValue = new byte[] { 0x56, 0x78 }; IStorageAccount account = CreateFakeStorageAccount(); IStorageQueue triggerQueue = CreateQueue(account, TriggerQueueName); triggerQueue.AddMessage(triggerQueue.CreateMessage(expectedValue)); IStorageTable table = CreateTable(account, TableName); Dictionary <string, EntityProperty> originalProperties = new Dictionary <string, EntityProperty> { { "Value", new EntityProperty(originalValue) } }; table.Insert(new DynamicTableEntity(PartitionKey, RowKey, etag: null, properties: originalProperties)); // Act RunTrigger(account, typeof(UpdatePocoWithByteArrayValueProgram)); // Assert DynamicTableEntity entity = table.Retrieve <DynamicTableEntity>(PartitionKey, RowKey); Assert.NotNull(entity); IDictionary <string, EntityProperty> properties = entity.Properties; Assert.NotNull(properties); Assert.True(properties.ContainsKey("Value")); EntityProperty property = properties["Value"]; Assert.NotNull(property); Assert.Equal(EdmType.Binary, property.PropertyType); Assert.Equal(expectedValue, property.BinaryValue); }
private static IStorageQueue CreateQueue(IStorageQueueClient client, string queueName) { IStorageQueue queue = client.GetQueueReference(queueName); queue.CreateIfNotExists(); return(queue); }
public void QueueTrigger_IfBoundToPocoAndMessageIsIncompatibleJson_DoesNotBind() { // Arrange const string content = "123"; // A JSON int rather than a JSON object. IStorageAccount account = CreateFakeStorageAccount(); IStorageQueue queue = CreateQueue(account, QueueName); IStorageQueueMessage message = queue.CreateMessage(content); queue.AddMessage(message); // Act Exception exception = RunTriggerFailure <Poco>(account, typeof(BindToPocoProgram), (s) => BindToPocoProgram.TaskSource = s); // Assert Assert.IsType <InvalidOperationException>(exception); Assert.Equal("Exception binding parameter 'message'", exception.Message); Exception innerException = exception.InnerException; Assert.IsType <InvalidOperationException>(innerException); string expectedInnerMessage = "Binding parameters to complex objects (such as 'Poco') uses Json.NET " + "serialization. \r\n1. Bind the parameter type as 'string' instead of 'Poco' to get the raw values " + "and avoid JSON deserialization, or\r\n2. Change the queue payload to be valid json. The JSON parser " + "failed: Error converting value 123 to type '" + typeof(Poco).FullName + "'. Path '', line 1, " + "position 3.\r\n"; Assert.Equal(expectedInnerMessage, innerException.Message); }
public void QueueTrigger_IfDequeueCountReachesMaxDequeueCount_MovesToPoisonQueue() { try { // Arrange const string expectedContents = "abc"; IStorageAccount account = CreateFakeStorageAccount(); IStorageQueue queue = CreateQueue(account, QueueName); queue.AddMessage(queue.CreateMessage(expectedContents)); // Act RunTrigger <object>(account, typeof(MaxDequeueCountProgram), (s) => MaxDequeueCountProgram.TaskSource = s, new string[] { typeof(MaxDequeueCountProgram).FullName + ".PutInPoisonQueue" }); // Assert IStorageAccountProvider storageAccountProvider = new FakeStorageAccountProvider() { StorageAccount = new FakeStorageAccount() }; Assert.Equal(new FakeQueueConfiguration(storageAccountProvider).MaxDequeueCount, MaxDequeueCountProgram.DequeueCount); } finally { MaxDequeueCountProgram.DequeueCount = 0; } }
/// <summary> /// 通过网络服务保存为文件,持久化数据 /// </summary> /// <param name="serverAddr">服务期地址</param> /// <param name="port">端口</param> /// <param name="storageName">保存的名称</param> /// <param name="primaryPropertyName">主键属性的名称,必须是long、int、string类型</param> /// <param name="isAsync">是否异步发送到服务器,同步对于文件写入有保证,异步对于性能有提升</param> public StorageContext(string serverAddr, int port, string storageName, string primaryPropertyName, bool isAsync = false) { var filepath = "./data/" + storageName + ".db"; if (string.IsNullOrEmpty(filepath)) { throw new Exception("filepath is empty"); } if (string.IsNullOrEmpty(primaryPropertyName)) { throw new Exception("primaryPropertyName is empty"); } _propertyInfo = typeof(T).GetProperty(primaryPropertyName, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance); if (_propertyInfo == null) { throw new Exception($"{typeof(T).FullName} can not find property: {primaryPropertyName}"); } if (_propertyInfo.PropertyType != typeof(string) && _propertyInfo.PropertyType != typeof(int) && _propertyInfo.PropertyType != typeof(long) ) { throw new Exception("主键属性必须是long、int、string类型"); } this.StorageName = storageName; _storageQueue = new Net.NetStorageQueue <T>(_dataList, filepath, serverAddr, port, storageName, _propertyInfo, isAsync); }
public QueueListener(IStorageQueue queue, IStorageQueue poisonQueue, ITriggerExecutor <IStorageQueueMessage> triggerExecutor, IWebJobsExceptionHandler exceptionHandler, ILoggerFactory loggerFactory, SharedQueueWatcher sharedWatcher, IQueueConfiguration queueConfiguration, QueueProcessor queueProcessor = null, TimeSpan?maxPollingInterval = null) { if (queueConfiguration == null) { throw new ArgumentNullException("queueConfiguration"); } if (queueConfiguration.BatchSize <= 0) { throw new ArgumentException("BatchSize must be greater than zero."); } if (queueConfiguration.MaxDequeueCount <= 0) { throw new ArgumentException("MaxDequeueCount must be greater than zero."); } _timer = new TaskSeriesTimer(this, exceptionHandler, Task.Delay(0)); _queue = queue; _poisonQueue = poisonQueue; _triggerExecutor = triggerExecutor; _exceptionHandler = exceptionHandler; _queueConfiguration = queueConfiguration; // if the function runs longer than this, the invisibility will be updated // on a timer periodically for the duration of the function execution _visibilityTimeout = TimeSpan.FromMinutes(10); if (sharedWatcher != null) { // Call Notify whenever a function adds a message to this queue. sharedWatcher.Register(queue.Name, this); _sharedWatcher = sharedWatcher; } EventHandler <PoisonMessageEventArgs> poisonMessageEventHandler = _sharedWatcher != null ? OnMessageAddedToPoisonQueue : (EventHandler <PoisonMessageEventArgs>)null; _queueProcessor = queueProcessor ?? CreateQueueProcessor( _queue.SdkObject, _poisonQueue != null ? _poisonQueue.SdkObject : null, loggerFactory, _queueConfiguration, poisonMessageEventHandler); TimeSpan maximumInterval = _queueProcessor.MaxPollingInterval; if (maxPollingInterval.HasValue && maximumInterval > maxPollingInterval.Value) { // enforce the maximum polling interval if specified maximumInterval = maxPollingInterval.Value; } _delayStrategy = new RandomizedExponentialBackoffStrategy(QueuePollingIntervals.Minimum, maximumInterval); }
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; }
public StorageQueue(IStorageQueue queue, IMessageSerializer <T> contentsSerializer, int version) : this(queue, new TypedMessageSerializer <T>( contentsSerializer, new JsonMessageSerializer <TypedMessage>(), version)) { }
public void Setup() { var elements = new StorageElements(); this.container = new Container(elements.Container, connectionString); this.container.CreateIfNotExists().Wait(); this.table = new TableStorage(elements.Table, connectionString); this.table.CreateIfNotExists().Wait(); this.queue = new StorageQueue(elements.Queue, connectionString); this.queue.CreateIfNotExists().Wait(); }
public QueueTriggerBinding(string parameterName, IStorageQueue queue, ITriggerDataArgumentBinding<IStorageQueueMessage> argumentBinding, IQueueConfiguration queueConfiguration, IBackgroundExceptionDispatcher backgroundExceptionDispatcher, IContextSetter<IMessageEnqueuedWatcher> messageEnqueuedWatcherSetter, ISharedContextProvider sharedContextProvider, TextWriter log) { if (queue == null) { throw new ArgumentNullException("queue"); } if (argumentBinding == null) { throw new ArgumentNullException("argumentBinding"); } if (queueConfiguration == null) { throw new ArgumentNullException("queueConfiguration"); } if (backgroundExceptionDispatcher == null) { throw new ArgumentNullException("backgroundExceptionDispatcher"); } if (messageEnqueuedWatcherSetter == null) { throw new ArgumentNullException("messageEnqueuedWatcherSetter"); } if (sharedContextProvider == null) { throw new ArgumentNullException("sharedContextProvider"); } if (log == null) { throw new ArgumentNullException("log"); } _parameterName = parameterName; _queue = queue; _argumentBinding = argumentBinding; _bindingDataContract = CreateBindingDataContract(argumentBinding); _queueConfiguration = queueConfiguration; _backgroundExceptionDispatcher = backgroundExceptionDispatcher; _messageEnqueuedWatcherSetter = messageEnqueuedWatcherSetter; _sharedContextProvider = sharedContextProvider; _log = log; _converter = CreateConverter(queue); }
public QueueValueProvider(IStorageQueue queue, object value, Type valueType) { if (value != null && !valueType.IsAssignableFrom(value.GetType())) { throw new InvalidOperationException("value is not of the correct type."); } _queue = queue; _value = value; _valueType = valueType; }
public QueueListenerFactory(IStorageQueue queue, IQueueConfiguration queueConfiguration, IBackgroundExceptionDispatcher backgroundExceptionDispatcher, IContextSetter<IMessageEnqueuedWatcher> messageEnqueuedWatcherSetter, ISharedContextProvider sharedContextProvider, TraceWriter trace, ITriggeredFunctionExecutor executor) { if (queue == null) { throw new ArgumentNullException("queue"); } if (queueConfiguration == null) { throw new ArgumentNullException("queueConfiguration"); } if (backgroundExceptionDispatcher == null) { throw new ArgumentNullException("backgroundExceptionDispatcher"); } if (messageEnqueuedWatcherSetter == null) { throw new ArgumentNullException("messageEnqueuedWatcherSetter"); } if (sharedContextProvider == null) { throw new ArgumentNullException("sharedContextProvider"); } if (trace == null) { throw new ArgumentNullException("trace"); } if (executor == null) { throw new ArgumentNullException("executor"); } _queue = queue; _poisonQueue = CreatePoisonQueueReference(queue.ServiceClient, queue.Name); _queueConfiguration = queueConfiguration; _backgroundExceptionDispatcher = backgroundExceptionDispatcher; _messageEnqueuedWatcherSetter = messageEnqueuedWatcherSetter; _sharedContextProvider = sharedContextProvider; _trace = trace; _executor = executor; }
public HostMessageListenerFactory(IStorageQueue queue, IQueueConfiguration queueConfiguration, IBackgroundExceptionDispatcher backgroundExceptionDispatcher, TextWriter log, IFunctionIndexLookup functionLookup, IFunctionInstanceLogger functionInstanceLogger, IFunctionExecutor executor) { if (queue == null) { throw new ArgumentNullException("queue"); } if (queueConfiguration == null) { throw new ArgumentNullException("queueConfiguration"); } if (backgroundExceptionDispatcher == null) { throw new ArgumentNullException("backgroundExceptionDispatcher"); } if (log == null) { throw new ArgumentNullException("log"); } if (functionLookup == null) { throw new ArgumentNullException("functionLookup"); } if (functionInstanceLogger == null) { throw new ArgumentNullException("functionInstanceLogger"); } if (executor == null) { throw new ArgumentNullException("executor"); } _queue = queue; _queueConfiguration = queueConfiguration; _backgroundExceptionDispatcher = backgroundExceptionDispatcher; _log = log; _functionLookup = functionLookup; _functionInstanceLogger = functionInstanceLogger; _executor = executor; }
public QueueListener(IStorageQueue queue, IStorageQueue poisonQueue, ITriggerExecutor<IStorageQueueMessage> triggerExecutor, IDelayStrategy delayStrategy, IBackgroundExceptionDispatcher backgroundExceptionDispatcher, TraceWriter trace, SharedQueueWatcher sharedWatcher, IQueueConfiguration queueConfiguration) { if (trace == null) { throw new ArgumentNullException("trace"); } if (queueConfiguration == null) { throw new ArgumentNullException("queueConfiguration"); } if (queueConfiguration.BatchSize <= 0) { throw new ArgumentException("BatchSize must be greater than zero."); } if (queueConfiguration.MaxDequeueCount <= 0) { throw new ArgumentException("MaxDequeueCount must be greater than zero."); } _timer = new TaskSeriesTimer(this, backgroundExceptionDispatcher, Task.Delay(0)); _queue = queue; _poisonQueue = poisonQueue; _triggerExecutor = triggerExecutor; _delayStrategy = delayStrategy; _backgroundExceptionDispatcher = backgroundExceptionDispatcher; _trace = trace; _queueConfiguration = queueConfiguration; if (sharedWatcher != null) { // Call Notify whenever a function adds a message to this queue. sharedWatcher.Register(queue.Name, this); _sharedWatcher = sharedWatcher; } EventHandler poisonMessageEventHandler = _sharedWatcher != null ? OnMessageAddedToPoisonQueue : (EventHandler)null; _queueProcessor = CreateQueueProcessor( _queue.SdkObject, _poisonQueue != null ? _poisonQueue.SdkObject : null, _trace, _queueConfiguration, poisonMessageEventHandler); }
public UpdateQueueMessageVisibilityCommand(IStorageQueue queue, IStorageQueueMessage message, TimeSpan visibilityTimeout, IDelayStrategy speedupStrategy) { if (queue == null) { throw new ArgumentNullException("queue"); } if (message == null) { throw new ArgumentNullException("message"); } if (speedupStrategy == null) { throw new ArgumentNullException("speedupStrategy"); } _queue = queue; _message = message; _visibilityTimeout = visibilityTimeout; _speedupStrategy = speedupStrategy; }
private static ITaskSeriesTimer CreateUpdateMessageVisibilityTimer(IStorageQueue queue, IStorageQueueMessage message, TimeSpan visibilityTimeout, IBackgroundExceptionDispatcher backgroundExceptionDispatcher) { // Update a message's visibility when it is halfway to expiring. TimeSpan normalUpdateInterval = new TimeSpan(visibilityTimeout.Ticks / 2); IDelayStrategy speedupStrategy = new LinearSpeedupStrategy(normalUpdateInterval, TimeSpan.FromMinutes(1)); ITaskSeriesCommand command = new UpdateQueueMessageVisibilityCommand(queue, message, visibilityTimeout, speedupStrategy); return new TaskSeriesTimer(command, backgroundExceptionDispatcher, Task.Delay(normalUpdateInterval)); }
public CompanyQueuer(IStorageQueue queue) :base(10) { this.queue = queue; }
public BlobTriggerQueueWriter(IStorageQueue queue, IMessageEnqueuedWatcher watcher) { _queue = queue; Debug.Assert(watcher != null); _watcher = watcher; }
private static IObjectToTypeConverter<IStorageQueueMessage> CreateConverter(IStorageQueue queue) { return new CompositeObjectToTypeConverter<IStorageQueueMessage>( new OutputConverter<IStorageQueueMessage>(new IdentityConverter<IStorageQueueMessage>()), new OutputConverter<CloudQueueMessage>(new CloudQueueMessageToStorageQueueMessageConverter()), new OutputConverter<string>(new StringToStorageQueueMessageConverter(queue))); }
private Task<IValueProvider> BindQueueAsync(IStorageQueue value, ValueBindingContext context) { return _argumentBinding.BindAsync(value, context); }
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); } }
private async Task<IListener> CreateBlobDiscoveryToQueueMessageListenerAsync(string hostId, SharedBlobListener sharedBlobListener, IStorageBlobClient blobClient, IStorageQueue hostBlobTriggerQueue, IMessageEnqueuedWatcher messageEnqueuedWatcher, CancellationToken cancellationToken) { BlobTriggerExecutor triggerExecutor = new BlobTriggerExecutor(hostId, _functionId, _input, BlobETagReader.Instance, new BlobReceiptManager(blobClient), new BlobTriggerQueueWriter(hostBlobTriggerQueue, messageEnqueuedWatcher)); await sharedBlobListener.RegisterAsync(_container, triggerExecutor, cancellationToken); return new BlobListener(sharedBlobListener); }
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); }