Exemple #1
0
        public Given_a_PersistentConsumer()
        {
            eventBus          = new EventBus();
            internalConsumers = new List <IInternalConsumer>();

            createConsumerCalled = 0;
            mockBuilder          = new MockBuilder();

            queue     = new Queue(queueName, false);
            onMessage = (body, properties, info) => Task.Factory.StartNew(() => { });

            persistentConnection    = Substitute.For <IPersistentConnection>();
            internalConsumerFactory = Substitute.For <IInternalConsumerFactory>();

            internalConsumerFactory.CreateConsumer().Returns(x =>
            {
                var internalConsumer = Substitute.For <IInternalConsumer>();
                internalConsumers.Add(internalConsumer);
                createConsumerCalled++;
                return(internalConsumer);
            });
            configuration = new ConsumerConfiguration(0);
            consumer      = new PersistentConsumer(
                queue,
                onMessage,
                persistentConnection,
                configuration,
                internalConsumerFactory,
                eventBus);

            AdditionalSetup();
        }
Exemple #2
0
        public ConsumerFactory(IInternalConsumerFactory internalConsumerFactory, IEventBus eventBus)
        {
            Preconditions.CheckNotNull(internalConsumerFactory, "internalConsumerFactory");

            this.internalConsumerFactory = internalConsumerFactory;
            this.eventBus = eventBus;
        }
Exemple #3
0
        public void SetUp()
        {
            eventBus          = new EventBus();
            internalConsumers = new List <IInternalConsumer>();

            createConsumerCalled = 0;
            mockBuilder          = new MockBuilder();

            queue     = new Queue(queueName, false);
            onMessage = (body, properties, info) => Task.Factory.StartNew(() => { });

            persistentConnection = MockRepository.GenerateStub <IPersistentConnection>();

            internalConsumerFactory = MockRepository.GenerateStub <IInternalConsumerFactory>();

            internalConsumerFactory.Stub(x => x.CreateConsumer()).WhenCalled(x =>
            {
                var internalConsumer = MockRepository.GenerateStub <IInternalConsumer>();
                internalConsumers.Add(internalConsumer);
                createConsumerCalled++;
                x.ReturnValue = internalConsumer;
            }).Repeat.Any();

            consumer = new PersistentConsumer(
                queue,
                onMessage,
                persistentConnection,
                internalConsumerFactory,
                eventBus);

            AdditionalSetup();
        }
Exemple #4
0
        public ExclusiveConsumer(
            IQueue queue,
            Func <byte[], MessageProperties, MessageReceivedInfo, Task> onMessage,
            IPersistentConnection connection,
            IConsumerConfiguration configuration,
            IInternalConsumerFactory internalConsumerFactory,
            IEventBus eventBus
            )
        {
            Preconditions.CheckNotNull(queue, "queue");
            Preconditions.CheckNotNull(onMessage, "onMessage");
            Preconditions.CheckNotNull(connection, "connection");
            Preconditions.CheckNotNull(internalConsumerFactory, "internalConsumerFactory");
            Preconditions.CheckNotNull(eventBus, "eventBus");
            Preconditions.CheckNotNull(configuration, "configuration");

            this.queue                   = queue;
            this.onMessage               = onMessage;
            this.connection              = connection;
            this.configuration           = configuration;
            this.internalConsumerFactory = internalConsumerFactory;
            this.eventBus                = eventBus;
            timer = new Timer(s =>
            {
                StartConsumer();
                ((Timer)s).Change(10000, -1);
            });
            timer.Change(10000, -1);
        }
        public void SetUp()
        {
            eventBus = new EventBus();
            internalConsumers = new List<IInternalConsumer>();

            createConsumerCalled = 0;
            mockBuilder = new MockBuilder();

            queue = new Queue(queueName, false);
            onMessage = (body, properties, info) => Task.Factory.StartNew(() => { });

            persistentConnection = MockRepository.GenerateStub<IPersistentConnection>();

            internalConsumerFactory = MockRepository.GenerateStub<IInternalConsumerFactory>();

            internalConsumerFactory.Stub(x => x.CreateConsumer()).WhenCalled(x =>
                {
                    var internalConsumer = MockRepository.GenerateStub<IInternalConsumer>();
                    internalConsumers.Add(internalConsumer);
                    createConsumerCalled++;
                    x.ReturnValue = internalConsumer;
                }).Repeat.Any();

            consumer = new PersistentConsumer(
                queue,
                onMessage,
                persistentConnection,
                internalConsumerFactory,
                eventBus);

            AdditionalSetup();
        }
  public ExclusiveConsumer(
      IQueue queue,
      Func<byte[], MessageProperties, MessageReceivedInfo, Task> onMessage,
      IPersistentConnection connection,
      IConsumerConfiguration configuration,
      IInternalConsumerFactory internalConsumerFactory,
      IEventBus eventBus
      )
  {
      Preconditions.CheckNotNull(queue, "queue");
      Preconditions.CheckNotNull(onMessage, "onMessage");
      Preconditions.CheckNotNull(connection, "connection");
      Preconditions.CheckNotNull(internalConsumerFactory, "internalConsumerFactory");
      Preconditions.CheckNotNull(eventBus, "eventBus");
      Preconditions.CheckNotNull(configuration, "configuration");
 
      this.queue = queue;
      this.onMessage = onMessage;
      this.connection = connection;
      this.configuration = configuration;
      this.internalConsumerFactory = internalConsumerFactory;
      this.eventBus = eventBus;
      timer = new Timer(s =>
          {
              StartConsumer();
              ((Timer)s).Change(10000, -1);
          });
      timer.Change(10000, -1);
  }
Exemple #7
0
 public ConsumerFactory(IInternalConsumerFactory internalConsumerFactory, IEventBus eventBus)
 {
     this.internalConsumerFactory = internalConsumerFactory;
     this.eventBus = eventBus;
     consumers     = new ConcurrentDictionary <IConsumer, object>();
     eventBus.Subscribe <StoppedConsumingEvent>(stoppedConsumingEvent =>
     {
         object value;
         consumers.TryRemove(stoppedConsumingEvent.Consumer, out value);
     });
 }
Exemple #8
0
        public ConsumerFactory(IInternalConsumerFactory internalConsumerFactory, IEventBus eventBus)
        {
            Preconditions.CheckNotNull(internalConsumerFactory, "internalConsumerFactory");

            this.internalConsumerFactory = internalConsumerFactory;
            this.eventBus = eventBus;

            eventBus.Subscribe<StoppedConsumingEvent>(stoppedConsumingEvent =>
                {
                    object value;
                    consumers.TryRemove(stoppedConsumingEvent.Consumer, out value);
                });
        }
        public ConsumerFactory(IInternalConsumerFactory internalConsumerFactory, IEventBus eventBus)
        {
            Preconditions.CheckNotNull(internalConsumerFactory, "internalConsumerFactory");

            this.internalConsumerFactory = internalConsumerFactory;
            this.eventBus = eventBus;

            eventBus.Subscribe <StoppedConsumingEvent>(stoppedConsumingEvent =>
            {
                object value;
                consumers.TryRemove(stoppedConsumingEvent.Consumer, out value);
            });
        }
Exemple #10
0
        public ConsumerFactory(IInternalConsumerFactory internalConsumerFactory, IEventBus eventBus)
        {
            Preconditions.CheckNotNull(internalConsumerFactory, "internalConsumerFactory");
            Preconditions.CheckNotNull(eventBus, "eventBus");

            this.internalConsumerFactory = internalConsumerFactory;
            this.eventBus = eventBus;

            eventBus.Subscribe <StoppedConsumingEvent>(e =>
            {
                object value;
                consumers.TryRemove(e.Consumer, out value);
                Console.WriteLine("StoppedConsumingEvent Subscribe : " + e.Consumer.ToString());
            });
        }
Exemple #11
0
 public TransientConsumer(
     IQueue queue,
     Func <byte[], MessageProperties, MessageReceivedInfo, Task> onMessage,
     IPersistentConnection connection,
     IConsumerConfiguration configuration,
     IInternalConsumerFactory internalConsumerFactory,
     IEventBus eventBus)
 {
     this.queue                   = queue;
     this.onMessage               = onMessage;
     this.connection              = connection;
     this.configuration           = configuration;
     this.internalConsumerFactory = internalConsumerFactory;
     this.eventBus                = eventBus;
 }
Exemple #12
0
        /// <summary>
        ///     Creates ConsumerFactory
        /// </summary>
        /// <param name="connection">The connection</param>
        /// <param name="internalConsumerFactory">The internal consumer factory</param>
        /// <param name="eventBus">The event bus</param>
        public ConsumerFactory(
            IPersistentConnection connection,
            IInternalConsumerFactory internalConsumerFactory,
            IEventBus eventBus
            )
        {
            Preconditions.CheckNotNull(internalConsumerFactory, "internalConsumerFactory");
            Preconditions.CheckNotNull(eventBus, "eventBus");

            this.connection = connection;
            this.internalConsumerFactory = internalConsumerFactory;
            this.eventBus = eventBus;

            eventBus.Subscribe <StoppedConsumingEvent>(@event => consumers.Remove(@event.Consumer));
        }
        public TransientConsumer(
            IQueue queue,
            Func <byte[], MessageProperties, MessageReceivedInfo, Task> onMessage,
            IPersistentConnection connection,
            IInternalConsumerFactory internalConsumerFactory)
        {
            Preconditions.CheckNotNull(queue, "queue");
            Preconditions.CheckNotNull(onMessage, "onMessage");
            Preconditions.CheckNotNull(connection, "connection");
            Preconditions.CheckNotNull(internalConsumerFactory, "internalConsumerFactory");

            this.queue      = queue;
            this.onMessage  = onMessage;
            this.connection = connection;
            this.internalConsumerFactory = internalConsumerFactory;
        }
        public PersistentConsumer(
            IQueue queue, 
            Func<byte[], MessageProperties, MessageReceivedInfo, Task> onMessage, 
            IPersistentConnection connection, 
            IInternalConsumerFactory internalConsumerFactory)
        {
            Preconditions.CheckNotNull(queue, "queue");
            Preconditions.CheckNotNull(onMessage, "onMessage");
            Preconditions.CheckNotNull(connection, "connection");
            Preconditions.CheckNotNull(internalConsumerFactory, "internalConsumerFactory");

            this.queue = queue;
            this.onMessage = onMessage;
            this.connection = connection;
            this.internalConsumerFactory = internalConsumerFactory;
        }
        public PersistentMultipleConsumer(
            ICollection <Tuple <IQueue, Func <byte[], MessageProperties, MessageReceivedInfo, Task> > > queueConsumerPairs,
            IPersistentConnection connection,
            IConsumerConfiguration configuration,
            IInternalConsumerFactory internalConsumerFactory,
            IEventBus eventBus)
        {
            Preconditions.CheckNotNull(queueConsumerPairs, nameof(queueConsumerPairs));
            Preconditions.CheckNotNull(connection, nameof(connection));
            Preconditions.CheckNotNull(internalConsumerFactory, nameof(internalConsumerFactory));
            Preconditions.CheckNotNull(eventBus, nameof(eventBus));
            Preconditions.CheckNotNull(configuration, nameof(configuration));

            this.queueConsumerPairs      = queueConsumerPairs;
            this.connection              = connection;
            this.configuration           = configuration;
            this.internalConsumerFactory = internalConsumerFactory;
            this.eventBus = eventBus;
        }
        public PersistentMultipleConsumer(
            IReadOnlyCollection <Tuple <IQueue, MessageHandler> > queueConsumerPairs,
            IPersistentConnection connection,
            ConsumerConfiguration configuration,
            IInternalConsumerFactory internalConsumerFactory,
            IEventBus eventBus
            )
        {
            Preconditions.CheckNotNull(queueConsumerPairs, nameof(queueConsumerPairs));
            Preconditions.CheckNotNull(connection, nameof(connection));
            Preconditions.CheckNotNull(internalConsumerFactory, nameof(internalConsumerFactory));
            Preconditions.CheckNotNull(eventBus, nameof(eventBus));
            Preconditions.CheckNotNull(configuration, nameof(configuration));

            this.queueConsumerPairs      = queueConsumerPairs;
            this.connection              = connection;
            this.configuration           = configuration;
            this.internalConsumerFactory = internalConsumerFactory;
            this.eventBus = eventBus;
        }
Exemple #17
0
        public PersistentConsumer(
            IQueue queue,
            MessageHandler onMessage,
            ConsumerConfiguration configuration,
            IInternalConsumerFactory internalConsumerFactory,
            IEventBus eventBus
            )
        {
            Preconditions.CheckNotNull(queue, "queue");
            Preconditions.CheckNotNull(onMessage, "onMessage");
            Preconditions.CheckNotNull(internalConsumerFactory, "internalConsumerFactory");
            Preconditions.CheckNotNull(eventBus, "eventBus");
            Preconditions.CheckNotNull(configuration, "configuration");

            this.queue                   = queue;
            this.onMessage               = onMessage;
            this.configuration           = configuration;
            this.internalConsumerFactory = internalConsumerFactory;
            this.eventBus                = eventBus;
        }
Exemple #18
0
        public PersistentConsumer(
            IQueue queue,
            Func <byte[], MessageProperties, MessageReceivedInfo, Task> onMessage,
            IPersistentConnection connection,
            IConsumerConfiguration configuration,
            IInternalConsumerFactory internalConsumerFactory,
            IEventBus eventBus)
        {
            Preconditions.CheckNotNull(queue, "queue");
            Preconditions.CheckNotNull(onMessage, "onMessage");
            Preconditions.CheckNotNull(connection, "connection");
            Preconditions.CheckNotNull(internalConsumerFactory, "internalConsumerFactory");
            Preconditions.CheckNotNull(eventBus, "eventBus");
            Preconditions.CheckNotNull(configuration, "configuration");

            this.queue                   = queue;
            this.onMessage               = onMessage;
            this.connection              = connection;
            this.configuration           = configuration;
            this.internalConsumerFactory = internalConsumerFactory;
            this.eventBus                = eventBus;
        }
        public TransientConsumer(
            IQueue queue, 
            Func<byte[], MessageProperties, MessageReceivedInfo, Task> onMessage, 
            IPersistentConnection connection, 
            IConsumerConfiguration configuration,
            IInternalConsumerFactory internalConsumerFactory, 
            IEventBus eventBus)
        {
            Preconditions.CheckNotNull(queue, "queue");
            Preconditions.CheckNotNull(onMessage, "onMessage");
            Preconditions.CheckNotNull(connection, "connection");
            Preconditions.CheckNotNull(internalConsumerFactory, "internalConsumerFactory");
            Preconditions.CheckNotNull(eventBus, "eventBus");
            Preconditions.CheckNotNull(configuration, "configuration");

            this.queue = queue;
            this.onMessage = onMessage;
            this.connection = connection;
            this.configuration = configuration;
            this.internalConsumerFactory = internalConsumerFactory;
            this.eventBus = eventBus;
        }
Exemple #20
0
        public ConsumerFactory(IInternalConsumerFactory internalConsumerFactory)
        {
            Preconditions.CheckNotNull(internalConsumerFactory, "internalConsumerFactory");

            this.internalConsumerFactory = internalConsumerFactory;
        }
Exemple #21
0
        public ConsumerFactory(IInternalConsumerFactory internalConsumerFactory)
        {
            Preconditions.CheckNotNull(internalConsumerFactory, "internalConsumerFactory");

            this.internalConsumerFactory = internalConsumerFactory;
        }