예제 #1
0
        public async Task GetMetrics_ReturnsExpectedResult()
        {
            var queuesOptions = new QueuesOptions();
            Mock <ITriggerExecutor <QueueMessage> > mockTriggerExecutor = new Mock <ITriggerExecutor <QueueMessage> >(MockBehavior.Strict);
            var           queueProcessorFactory = new DefaultQueueProcessorFactory();
            var           queueProcessor        = QueueListenerFactory.CreateQueueProcessor(Fixture.Queue, null, _loggerFactory, queueProcessorFactory, queuesOptions, null);
            QueueListener listener = new QueueListener(Fixture.Queue, null, mockTriggerExecutor.Object, new WebJobsExceptionHandler(null),
                                                       _loggerFactory, null, queuesOptions, queueProcessor, new FunctionDescriptor {
                Id = "TestFunction"
            });

            var metrics = await listener.GetMetricsAsync();

            Assert.AreEqual(0, metrics.QueueLength);
            Assert.AreEqual(TimeSpan.Zero, metrics.QueueTime);
            Assert.AreNotEqual(default(DateTime), metrics.Timestamp);

            // add some test messages
            for (int i = 0; i < 5; i++)
            {
                await Fixture.Queue.SendMessageAsync($"Message {i}");
            }

            await Task.Delay(TimeSpan.FromSeconds(5));

            metrics = await listener.GetMetricsAsync();

            Assert.AreEqual(5, metrics.QueueLength);
            Assert.True(metrics.QueueTime.Ticks > 0);
            Assert.AreNotEqual(default(DateTime), metrics.Timestamp);

            // verify non-generic interface works as expected
            metrics = (QueueTriggerMetrics)(await((IScaleMonitor)listener).GetMetricsAsync());
            Assert.AreEqual(5, metrics.QueueLength);
        }
예제 #2
0
 public PrinterMessageProvider(
     QueueListenerFactory listenerFactory,
     IMappingEngine mappingEngine)
 {
     _listenerFactory = listenerFactory;
     _mappingEngine = mappingEngine;
 }
 public PrinterMessageProvider(
     QueueListenerFactory listenerFactory,
     IMappingEngine mappingEngine)
 {
     _listenerFactory = listenerFactory;
     _mappingEngine   = mappingEngine;
 }
        public Task <IListener> CreateListenerAsync(ListenerFactoryContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            var factory = new QueueListenerFactory(_queue, _queueConfiguration, _exceptionHandler,
                                                   _messageEnqueuedWatcherSetter, _sharedContextProvider, _loggerFactory, context.Executor);

            return(factory.CreateAsync(context.CancellationToken));
        }
예제 #5
0
        public Task <IListener> CreateListenerAsync(ListenerFactoryContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var factory = new QueueListenerFactory(_queueServiceClient, _queue, _queueOptions, _exceptionHandler,
                                                   _messageEnqueuedWatcherSetter, _loggerFactory, context.Executor, _queueProcessorFactory, context.Descriptor);

            return(factory.CreateAsync(context.CancellationToken));
        }
예제 #6
0
        public async Task StartAsync()
        {
            var factory = new QueueListenerFactory();

            foreach (var definition in queueDefinitions)
            {
                var listener = await definition.CreateAsync(factory, Handle, exceptionHandler);

                listeners.Add(listener);
                await listener.StartAsync();
            }
        }
예제 #7
0
 private SyncAsyncEventHandler <QueueMessageDecodingFailedEventArgs> CreateMessageDecodingFailedHandler(QueueServiceClient nonEncodingQueueServiceClient)
 {
     return(async(QueueMessageDecodingFailedEventArgs args) =>
     {
         // This event is raised only in async paths hence args.IsRunningSynchronously is ignored.
         if (args.ReceivedMessage != null)
         {
             var queueClient = args.Queue;
             var poisonQueueClient = QueueListenerFactory.CreatePoisonQueueReference(nonEncodingQueueServiceClient, queueClient.Name);
             var queueProcessor = QueueListenerFactory.CreateQueueProcessor(queueClient, poisonQueueClient, _loggerFactory, _queueProcessorFactory, _queuesOptions, _messageEnqueuedWatcher);
             await queueProcessor.HandlePoisonMessageAsync(args.ReceivedMessage, args.CancellationToken).ConfigureAwait(false);
         }
     });
 }
예제 #8
0
        public IFunctionDefinition CreateFunctionDefinition(IReadOnlyDictionary <string, IBinding> nonTriggerBindings,
                                                            IFunctionInvoker invoker, FunctionDescriptor functionDescriptor)
        {
            ITriggeredFunctionBinding <IStorageQueueMessage> functionBinding =
                new TriggeredFunctionBinding <IStorageQueueMessage>(_parameterName, this, nonTriggerBindings);
            ITriggeredFunctionInstanceFactory <IStorageQueueMessage> instanceFactory =
                new TriggeredFunctionInstanceFactory <IStorageQueueMessage>(functionBinding, invoker,
                                                                            functionDescriptor);
            IListenerFactory listenerFactory = new QueueListenerFactory(_queue, _queueConfiguration,
                                                                        _backgroundExceptionDispatcher, _messageEnqueuedWatcherSetter, _sharedContextProvider, _log,
                                                                        instanceFactory);

            return(new FunctionDefinition(instanceFactory, listenerFactory));
        }