public void Run( [ServiceBusTrigger("%ServiceBusQueue%")] string message) { Console.WriteLine($"Message: {message}"); _logger.LogInformation($"Message: {message}"); _consumer.Consume(message.FromJson <Message <Cat> >()); }
private IMessageConsumer <MessageEx> CreateAndStartUiMessageConsumer(MsmqRouterFactory factory) { IMessageSource <MessageEx> messageSource = factory.CreateSource(UiCommandInputQueue, false); IMessageConsumer <MessageEx> consumer = factory.CreateConsumer(messageSource); switch (RoutableTransportMode) { case RoutableTransportMode.OnSite: consumer.Consume(Handle); break; case RoutableTransportMode.OnDemand: consumer.Consume(HandleAsync); break; } return(consumer); }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { try { await _messageConsumer.Consume(_configurationSection.GetSection("MessageTypes")["NotificationMessages"], stoppingToken); } catch (Exception e) { _notificationMessageLogger.LogError(e.StackTrace); } }
public void DenyWhileChangingOfRunningMessageConsumer() { IMessageSource <TestMessage> source = MessageGenerator.CreateSource(TestRouterHelper.SourceName, TestRouterHelper.MessagesCountToGenerate); var factory = new TestRouterFactory(new Waiter(waitablesCount: 1), messages => messages.CheckOrder(TestRouterHelper.Sequence(0, TestRouterHelper.MessagesCountToGenerate))); using (IMessageConsumer <TestMessage> consumer = factory.CreateConsumer(source)) { consumer.Consume(TestRouterHelper.HandleMessage); consumer.While = null; } }
public void CheckOrderTest() { IMessageSource <TestMessage> source = MessageGenerator.CreateSource(TestRouterHelper.SourceName, TestRouterHelper.MessagesCountToGenerate); var waiter = new Waiter(waitablesCount: 1); var factory = new TestRouterFactory(waiter, messages => messages.CheckOrder(TestRouterHelper.Sequence(0, TestRouterHelper.MessagesCountToGenerate))); using (IMessageConsumer <TestMessage> consumer = factory.CreateConsumer(source)) { consumer.Consume(TestRouterHelper.HandleMessage); waiter.Wait(true); } }
/// <summary> /// Send to event subscriber /// </summary> /// <param name="message"></param> /// <param name="list"></param> public void SendMessage(string message, MType type, params object[] list) { MessageImpl m = new MessageImpl(type, message); consumerList[type]?.Consume(m); if (type == MType.Critical) { criticalConsumer?.Consume(m); Console.WriteLine("Critical Error....\nRaising alarm.... \nCallingHandler...."); criticalMessageHandler.HandleCriticalState(); } }
public void SwallowExceptionTest() { const int errorMessageIndex = 5; var waiter = new Waiter(waitablesCount: 1); IMessageSource <TestMessage> source = MessageGenerator.CreateSource(TestRouterHelper.SourceName, TestRouterHelper.MessagesCountToGenerate, errorMessageIndex, swallowException: true); var factory = new TestRouterFactory(waiter, messages => messages.CheckOrder(TestRouterHelper.SequenceExcluding(0, TestRouterHelper.MessagesCountToGenerate, errorMessageIndex))); using (IMessageConsumer <TestMessage> consumer = factory.CreateConsumer(source)) { consumer.Consume(TestRouterHelper.HandleMessage); waiter.Wait(true); } }
public void CheckIsRunningTest() { IMessageSource <TestMessage> source = MessageGenerator.CreateSource(TestRouterHelper.SourceName, TestRouterHelper.MessagesCountToGenerate); var waiter = new Waiter(waitablesCount: 1); var factory = new TestRouterFactory(waiter, messages => {}); using (IMessageConsumer <TestMessage> consumer = factory.CreateConsumer(source)) { consumer.IsRunning.Should(Be.False); consumer.Consume(TestRouterHelper.HandleMessage); consumer.IsRunning.Should(Be.True); waiter.Wait(); consumer.IsRunning.Should(Be.True); } }
public void ChildrenOrderTest() { const int sourcesCount = 5; IMessageSource <TestMessage> source = MessageGenerator.CreateCompositeSource(TestRouterHelper.SourceName, sourcesCount, TestRouterHelper.MessagesCountToGenerate); var waiter = new Waiter(sourcesCount); var factory = new TestRouterFactory(waiter, messages => messages.CheckOrder(TestRouterHelper.Sequence(0, TestRouterHelper.MessagesCountToGenerate))); using (IMessageConsumer <TestMessage> router = factory.CreateRouter(source, factory, m => m.Tag)) { router.Consume(TestRouterHelper.HandleMessage); waiter.Wait(true); // we compare to 55, not 50, because each source has stop message at the end. ((TestMessageRouter)router).ReceiveCallCount.Should(Be.EqualTo(55)); } }
private Child Create(string sourceName) { Interlocked.Increment(ref _childrenCount); IMessageSource <TMessage> source = _producerConsumerFactory.CreateSource(sourceName, true); IMessageConsumer <TMessage> consumer = _producerConsumerFactory.CreateConsumer(source); IMessageProducer <TMessage> producer = _producerConsumerFactory.CreateProducer(source); consumer.AddObserver(new DisposeProducerOnCompleteObserver(producer, _log)); consumer.Consume(_handleMessage); return(new Child { Source = source, Consumer = consumer, Producer = producer }); }
public void RouterShouldHandleMessagesIfTagIsNotProvided() { IMessageSource <TestMessage> source = MessageGenerator.CreateSource(string.Empty, 5); var waiter = new Waiter(1); var factory = new TestRouterFactory(waiter, messages => { }); using (IMessageConsumer <TestMessage> router = factory.CreateRouter(source, factory, m => m.Tag)) { var messagesHandled = 0; waiter.Register(router); router.While = m => TestMessage.IsNotStopMessage(string.Empty, m); router.Consume(message => messagesHandled++); waiter.Wait(true); messagesHandled.Should(Be.EqualTo(6)); //Do not receive message from queue, if router handles message by itself. Let the handle logic do this. ((TestMessageRouter)router).ReceiveCallCount.Should(Be.EqualTo(0)); } }
protected void Register(IMessageConsumer consumer, IMessageProducer producer) { consumer.Consume(producer.Produce()); _store.Add(consumer, producer); }
public void OnDataReceived(object sender, Message <T> message) { _logger.LogInformation($"{message.Command}, {message.Type}, {message.Entity.ToJson()}"); _consumer.Consume(message); }
public List <Device> Consume() { return(_messageConsumer.Consume()); }