Пример #1
0
 public void Register(IMessageConsumer <TestMessage> messageConsumer)
 {
     messageConsumer.AddObserver(new Observer <TestMessage>(() =>
     {
         if (Interlocked.Decrement(ref _waitablesCount) == 0)
         {
             _waitEvent.Set();
         }
     }));
 }
Пример #2
0
        public void DenyMonitorChangingOfRunningMessageConsumer()
        {
            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.AddObserver(null);
            }
        }
        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
            });
        }