Esempio n. 1
0
 public ScheduleRepository(ScheduleRepositoryConfiguration configuration, IEasyNetQLogger log, Func<DateTime> now)
 {
     this.configuration = configuration;
     this.log = log;
     this.now = now;
     this.dialect = SqlDialectResolver.Resolve(configuration.ProviderName);
 }
Esempio n. 2
0
        public PersistentConnection(IConnectionFactory connectionFactory, IEasyNetQLogger logger)
        {
            this.connectionFactory = connectionFactory;
            this.logger = logger;

            TryToConnect(null);
        }
Esempio n. 3
0
 public SchedulerService(IBus bus, IEasyNetQLogger log, IScheduleRepository scheduleRepository, ISchedulerServiceConfiguration configuration)
 {
     this.bus = bus;
     this.log = log;
     this.scheduleRepository = scheduleRepository;
     this.configuration = configuration;
 }
        public QueueingConsumerFactory(IEasyNetQLogger logger, IConsumerErrorStrategy consumerErrorStrategy)
        {
            this.logger = logger;
            this.consumerErrorStrategy = consumerErrorStrategy;

            // start the subscription callback thread
            // all subscription actions registered with Subscribe or Request
            // run here.
            subscriptionCallbackThread = new Thread(_ =>
            {
                try
                {
                    while(true)
                    {
                        if (disposed) break;

                        HandleMessageDelivery(queue.Take());
                    }
                }
                catch (InvalidOperationException)
                {
                    // InvalidOperationException is thrown when Take is called after
                    // queue.CompleteAdding(), this is signals that this class is being
                    // disposed, so we allow the thread to complete.
                }
            });
            subscriptionCallbackThread.Start();
        }
        public LoggerTrackingParticipant(IEasyNetQLogger logger)
        {
            if(logger == null)
                throw new ArgumentNullException("logger");

            Log = logger;
        }
 public void SetUp()
 {
     var parser = new ConnectionStringParser();
     var configuration = parser.Parse("host=localhost");
     logger = MockRepository.GenerateStub<IEasyNetQLogger>();
     dispatcherFactory = new ConsumerDispatcherFactory(configuration, logger);
 }
        public ConsumerDispatcherFactory(ConnectionConfiguration configuration, IEasyNetQLogger logger)
        {
            Preconditions.CheckNotNull(configuration, "configuration");
            Preconditions.CheckNotNull(logger, "logger");

            dispatcher = new Lazy<IConsumerDispatcher>(() => new ConsumerDispatcher(configuration, logger));
        }
Esempio n. 8
0
        public ConsumerDispatcher(IEasyNetQLogger logger)
        {
            Preconditions.CheckNotNull(logger, "logger");

            internalQueue = new ConcurrentQueue<Action>();
            queue = new BlockingCollection<Action>(internalQueue);

            dispatchThread = new Thread(_ =>
                {
                    try
                    {
                        while (true)
                        {
                            if (disposed) break;

                            queue.Take()();
                        }
                    }
                    catch (InvalidOperationException)
                    {
                        // InvalidOperationException is thrown when Take is called after
                        // queue.CompleteAdding(), this is signals that this class is being
                        // disposed, so we allow the thread to complete.
                    }
                    catch (Exception exception)
                    {
                        logger.ErrorWrite(exception);
                    }
                }) { Name = "EasyNetQ consumer dispatch thread" };
            dispatchThread.Start();
        }
Esempio n. 9
0
        public PersistentConnection(ConnectionFactory connectionFactory, IEasyNetQLogger logger)
        {
            this.connectionFactory = connectionFactory;
            this.logger = logger;
            this.subscribeActions = new ConcurrentBag<Action>();

            TryToConnect(null);
        }
Esempio n. 10
0
        public HandlerRunner(IEasyNetQLogger logger, IConsumerErrorStrategy consumerErrorStrategy)
        {
            Preconditions.CheckNotNull(logger, "logger");
            Preconditions.CheckNotNull(consumerErrorStrategy, "consumerErrorStrategy");

            this.logger = logger;
            this.consumerErrorStrategy = consumerErrorStrategy;
        }
Esempio n. 11
0
 public NackConsumerErrorStrategy(
     IConnectionFactory connectionFactory,
     ISerializer serializer,
     IEasyNetQLogger logger,
     IConventions conventions,
     ITypeNameSerializer typeNameSerializer)
     : base(connectionFactory, serializer, logger, conventions, typeNameSerializer)
 {
 }
 public DefaultConsumerErrorStrategy(
     IConnectionFactory connectionFactory, 
     ISerializer serializer,
     IEasyNetQLogger logger)
 {
     this.connectionFactory = connectionFactory;
     this.serializer = serializer;
     this.logger = logger;
 }
Esempio n. 13
0
        public HandlerRunner(IEasyNetQLogger logger, IConsumerErrorStrategy consumerErrorStrategy, IEventBus eventBus)
        {
            Preconditions.CheckNotNull(logger, "logger");
            Preconditions.CheckNotNull(consumerErrorStrategy, "consumerErrorStrategy");
            Preconditions.CheckNotNull(eventBus, "eventBus");

            this.logger = logger;
            this.consumerErrorStrategy = consumerErrorStrategy;
            this.eventBus = eventBus;
        }
Esempio n. 14
0
        public PersistentConnection(IConnectionFactory connectionFactory, IEasyNetQLogger logger)
        {
            Preconditions.CheckNotNull(connectionFactory, "connectionFactory");
            Preconditions.CheckNotNull(logger, "logger");

            this.connectionFactory = connectionFactory;
            this.logger = logger;

            TryToConnect(null);
        }
Esempio n. 15
0
        public PersistentConnection(IConnectionFactory connectionFactory, IEasyNetQLogger logger, IEventBus eventBus)
        {
            Preconditions.CheckNotNull(connectionFactory, "connectionFactory");
            Preconditions.CheckNotNull(logger, "logger");
            Preconditions.CheckNotNull(eventBus, "eventBus");

            this.connectionFactory = connectionFactory;
            this.logger = logger;
            this.eventBus = eventBus;
        }
        public PersistentChannelFactory(IEasyNetQLogger logger, ConnectionConfiguration configuration, IEventBus eventBus)
        {
            Preconditions.CheckNotNull(logger, "logger");
            Preconditions.CheckNotNull(configuration, "configuration");
            Preconditions.CheckNotNull(eventBus, "eventBus");

            this.logger = logger;
            this.configuration = configuration;
            this.eventBus = eventBus;
        }
Esempio n. 17
0
        public PublisherConfirms(ConnectionConfiguration configuration, IEasyNetQLogger logger, IEventBus eventBus) : base (eventBus)
        {
            Preconditions.CheckNotNull(configuration, "configuration");
            Preconditions.CheckNotNull(logger, "logger");
            Preconditions.CheckNotNull(eventBus, "eventBus");

            timeoutSeconds = configuration.Timeout;
            this.logger = logger;

            eventBus.Subscribe<PublishChannelCreatedEvent>(OnPublishChannelCreated);
        }
 public CustomErrorStrategy(
     EasyNetQ.IConnectionFactory connectionFactory,
     ISerializer serializer,
     IEasyNetQLogger logger,
     IConventions conventions,
     ITypeNameSerializer typeNameSerializer)
 {
     this.connectionFactory = connectionFactory;
     this.serializer = serializer;
     this.logger = logger;
     this.conventions = conventions;
     this.typeNameSerializer = typeNameSerializer;
 }
 public MessageBusConsumerErrorStrategy(
     string errorExchangeName,
     IConnectionFactory connectionFactory, 
     ISerializer serializer, 
     IEasyNetQLogger logger, 
     IConventions conventions)
     : base(connectionFactory, serializer, logger, conventions)
 {
     _errorExchangeName = errorExchangeName;
     _connectionFactory = connectionFactory;
     _serializer = serializer;
     _logger = logger;
 }
Esempio n. 20
0
 public SchedulerService(
     IBus bus, 
     IRawByteBus rawByteBus,
     IEasyNetQLogger log, 
     IScheduleRepository scheduleRepository, 
     Func<DateTime> now)
 {
     this.bus = bus;
     this.scheduleRepository = scheduleRepository;
     this.now = now;
     this.rawByteBus = rawByteBus;
     this.log = log;
 }
        public DefaultConsumerErrorStrategy(
            IConnectionFactory connectionFactory, 
            ISerializer serializer,
            IEasyNetQLogger logger,
            IConventions conventions)
        {
            Preconditions.CheckNotNull(conventions, "conventions");

            this.connectionFactory = connectionFactory;
            this.serializer = serializer;
            this.logger = logger;
            this.conventions = conventions;
        }
Esempio n. 22
0
        public MyErrorStrategy(
            IConnectionFactory connectionFactory,
            ISerializer serializer,
            IEasyNetQLogger logger,
            IConventions conventions)
        {
            // Preconditions.CheckNotNull(connectionFactory, "connectionFactory");
            // Preconditions.CheckNotNull(serializer, "serializer");
            // Preconditions.CheckNotNull(logger, "logger");
            // Preconditions.CheckNotNull(conventions, "conventions");

            this.connectionFactory = connectionFactory;
            this.serializer = serializer;
            this.logger = logger;
            this.conventions = conventions;
        }
        public DefaultConsumerErrorStrategy(
            IConnectionFactory connectionFactory, 
            ISerializer serializer,
            IEasyNetQLogger logger,
            IConventions conventions)
        {
            if (conventions == null)
            {
                throw new ArgumentNullException("conventions");
            }

            this.connectionFactory = connectionFactory;
            this.serializer = serializer;
            this.logger = logger;
            this.conventions = conventions;
        }
Esempio n. 24
0
        public RabbitBus(
            SerializeType serializeType,
            IEasyNetQLogger logger,
            IConventions conventions,
            IAdvancedBus advancedBus)
        {
            Preconditions.CheckNotNull(serializeType, "serializeType");
            Preconditions.CheckNotNull(logger, "logger");
            Preconditions.CheckNotNull(conventions, "conventions");
            Preconditions.CheckNotNull(advancedBus, "advancedBus");

            this.serializeType = serializeType;
            this.logger        = logger;
            this.conventions   = conventions;
            this.advancedBus   = advancedBus;

            advancedBus.Connected    += OnConnected;
            advancedBus.Disconnected += OnDisconnected;
        }
        public QueueingConsumerFactory(IEasyNetQLogger logger, IConsumerErrorStrategy consumerErrorStrategy)
        {
            this.logger = logger;
            this.consumerErrorStrategy = consumerErrorStrategy;

            // start the subscription callback thread
            // all subscription actions registered with Subscribe or Request
            // run here.
            subscriptionCallbackThread = new Thread(_ =>
            {
                while(true)
                {
                    if (disposed) break;

                    HandleMessageDelivery(queue.Take());
                }
            });
            subscriptionCallbackThread.Start();
        }
Esempio n. 26
0
        public InternalConsumer(
            IHandlerRunner handlerRunner,
            IEasyNetQLogger logger,
            IConsumerDispatcher consumerDispatcher,
            IConventions conventions,
            IConnectionConfiguration connectionConfiguration)
        {
            Preconditions.CheckNotNull(handlerRunner, "handlerRunner");
            Preconditions.CheckNotNull(logger, "logger");
            Preconditions.CheckNotNull(consumerDispatcher, "consumerDispatcher");
            Preconditions.CheckNotNull(conventions, "conventions");
            Preconditions.CheckNotNull(connectionConfiguration, "connectionConfiguration");

            this.handlerRunner           = handlerRunner;
            this.logger                  = logger;
            this.consumerDispatcher      = consumerDispatcher;
            this.conventions             = conventions;
            this.connectionConfiguration = connectionConfiguration;
        }
        public DefaultConsumerErrorStrategy(
            IConnectionFactory connectionFactory, 
            ISerializer serializer,
            IEasyNetQLogger logger,
            IConventions conventions, 
            ITypeNameSerializer typeNameSerializer)
        {
            Preconditions.CheckNotNull(connectionFactory, "connectionFactory");
            Preconditions.CheckNotNull(serializer, "serializer");
            Preconditions.CheckNotNull(logger, "logger");
            Preconditions.CheckNotNull(conventions, "conventions");
            Preconditions.CheckNotNull(typeNameSerializer, "typeNameSerializer");

            this.connectionFactory = connectionFactory;
            this.serializer = serializer;
            this.logger = logger;
            this.conventions = conventions;
            this.typeNameSerializer = typeNameSerializer;
        }
Esempio n. 28
0
        public InternalConsumer(
            IHandlerRunner handlerRunner, 
            IEasyNetQLogger logger, 
            IConsumerDispatcher consumerDispatcher, 
            IConventions conventions, 
            IConnectionConfiguration connectionConfiguration)
        {
            Preconditions.CheckNotNull(handlerRunner, "handlerRunner");
            Preconditions.CheckNotNull(logger, "logger");
            Preconditions.CheckNotNull(consumerDispatcher, "consumerDispatcher");
            Preconditions.CheckNotNull(conventions, "conventions");
            Preconditions.CheckNotNull(connectionConfiguration, "connectionConfiguration");

            this.handlerRunner = handlerRunner;
            this.logger = logger;
            this.consumerDispatcher = consumerDispatcher;
            this.conventions = conventions;
            this.connectionConfiguration = connectionConfiguration;
        }
        public DefaultConsumerErrorStrategy(
            IConnectionFactory connectionFactory,
            ISerializer serializer,
            IEasyNetQLogger logger,
            IConventions conventions,
            ITypeNameSerializer typeNameSerializer)
        {
            Preconditions.CheckNotNull(connectionFactory, "connectionFactory");
            Preconditions.CheckNotNull(serializer, "serializer");
            Preconditions.CheckNotNull(logger, "logger");
            Preconditions.CheckNotNull(conventions, "conventions");
            Preconditions.CheckNotNull(typeNameSerializer, "typeNameSerializer");

            this.connectionFactory  = connectionFactory;
            this.serializer         = serializer;
            this.logger             = logger;
            this.conventions        = conventions;
            this.typeNameSerializer = typeNameSerializer;
        }
Esempio n. 30
0
        public RabbitAdvancedBus(
            IConnectionFactory connectionFactory,
            IConsumerFactory consumerFactory,
            IEasyNetQLogger logger,
            IClientCommandDispatcherFactory clientCommandDispatcherFactory,
            IPublisher publisher,
            IEventBus eventBus,
            IHandlerCollectionFactory handlerCollectionFactory,
            IContainer container,
            IConnectionConfiguration connectionConfiguration,
            IProduceConsumeInterceptor produceConsumeInterceptor,
            IMessageSerializationStrategy messageSerializationStrategy)
        {
            Preconditions.CheckNotNull(connectionFactory, "connectionFactory");
            Preconditions.CheckNotNull(consumerFactory, "consumerFactory");
            Preconditions.CheckNotNull(logger, "logger");
            Preconditions.CheckNotNull(publisher, "publisher");
            Preconditions.CheckNotNull(eventBus, "eventBus");
            Preconditions.CheckNotNull(handlerCollectionFactory, "handlerCollectionFactory");
            Preconditions.CheckNotNull(container, "container");
            Preconditions.CheckNotNull(messageSerializationStrategy, "messageSerializationStrategy");
            Preconditions.CheckNotNull(connectionConfiguration, "connectionConfiguration");
            Preconditions.CheckNotNull(produceConsumeInterceptor, "produceConsumeInterceptor");

            this.consumerFactory              = consumerFactory;
            this.logger                       = logger;
            this.publisher                    = publisher;
            this.eventBus                     = eventBus;
            this.handlerCollectionFactory     = handlerCollectionFactory;
            this.container                    = container;
            this.connectionConfiguration      = connectionConfiguration;
            this.produceConsumeInterceptor    = produceConsumeInterceptor;
            this.messageSerializationStrategy = messageSerializationStrategy;

            connection = new PersistentConnection(connectionFactory, logger, eventBus);

            eventBus.Subscribe <ConnectionCreatedEvent>(e => OnConnected());
            eventBus.Subscribe <ConnectionDisconnectedEvent>(e => OnDisconnected());
            eventBus.Subscribe <ReturnedMessageEvent>(OnMessageReturned);

            clientCommandDispatcher = clientCommandDispatcherFactory.GetClientCommandDispatcher(connection);
        }
Esempio n. 31
0
        public RabbitAdvancedBus(
            IConnectionFactory connectionFactory,
            ISerializer serializer,
            IConsumerFactory consumerFactory,
            IEasyNetQLogger logger,
            Func <string> getCorrelationId,
            IClientCommandDispatcherFactory clientCommandDispatcherFactory,
            IPublisher _publisher,
            IEventBus eventBus,
            ITypeNameSerializer typeNameSerializer,
            IHandlerCollectionFactory handlerCollectionFactory,
            IContainer container)
        {
            Preconditions.CheckNotNull(connectionFactory, "connectionFactory");
            Preconditions.CheckNotNull(serializer, "serializer");
            Preconditions.CheckNotNull(consumerFactory, "consumerFactory");
            Preconditions.CheckNotNull(logger, "logger");
            Preconditions.CheckNotNull(getCorrelationId, "getCorrelationId");
            Preconditions.CheckNotNull(_publisher, "_publisher");
            Preconditions.CheckNotNull(eventBus, "eventBus");
            Preconditions.CheckNotNull(typeNameSerializer, "typeNameSerializer");
            Preconditions.CheckNotNull(handlerCollectionFactory, "handlerCollectionFactory");
            Preconditions.CheckNotNull(container, "container");

            this.serializer               = serializer;
            this.consumerFactory          = consumerFactory;
            this.logger                   = logger;
            this.getCorrelationId         = getCorrelationId;
            this._publisher               = _publisher;
            this.eventBus                 = eventBus;
            this.typeNameSerializer       = typeNameSerializer;
            this.handlerCollectionFactory = handlerCollectionFactory;
            this.container                = container;

            connection = new PersistentConnection(connectionFactory, logger, eventBus);

            eventBus.Subscribe <ConnectionCreatedEvent>(e => OnConnected());
            eventBus.Subscribe <ConnectionDisconnectedEvent>(e => OnDisconnected());
            eventBus.Subscribe <ReturnedMessageEvent>(OnMessageReturned);

            clientCommandDispatcher = clientCommandDispatcherFactory.GetClientCommandDispatcher(connection);
        }
Esempio n. 32
0
        /// <summary>
        /// Creates a new instance of RabbitBus.
        /// </summary>
        /// <param name="connectionString">
        /// The EasyNetQ connection string. Example:
        /// host=192.168.1.1;virtualHost=MyVirtualHost;username=MyUsername;password=MyPassword
        /// 
        /// The following default values will be used if not specified:
        /// host=localhost;virtualHost=/;username=guest;password=guest
        /// </param>
        /// <param name="logger">
        /// An implementation of IEasyNetQLogger to send the log output to.
        /// </param>
        /// <returns>
        /// A new RabbitBus instance.
        /// </returns>
        public static IBus CreateBus(string connectionString, IEasyNetQLogger logger)
        {
            if(connectionString == null)
            {
                throw new ArgumentNullException("connectionString");
            }
            if(logger == null)
            {
                throw new ArgumentNullException("logger");
            }

            var connectionValues = new ConnectionString(connectionString);

            return CreateBus(
                connectionValues.Host,
                connectionValues.VirtualHost,
                connectionValues.UserName,
                connectionValues.Password,
                logger);
        }
Esempio n. 33
0
        public InternalConsumerFactory(
            IHandlerRunner handlerRunner, 
            IEasyNetQLogger logger, 
            IConventions conventions, 
            ConnectionConfiguration connectionConfiguration, 
            IConsumerDispatcherFactory consumerDispatcherFactory, 
            IEventBus eventBus)
        {
            Preconditions.CheckNotNull(handlerRunner, "handlerRunner");
            Preconditions.CheckNotNull(logger, "logger");
            Preconditions.CheckNotNull(conventions, "conventions");
            Preconditions.CheckNotNull(connectionConfiguration, "connectionConfiguration");
            Preconditions.CheckNotNull(consumerDispatcherFactory, "consumerDispatcherFactory");

            this.handlerRunner = handlerRunner;
            this.logger = logger;
            this.conventions = conventions;
            this.connectionConfiguration = connectionConfiguration;
            this.consumerDispatcherFactory = consumerDispatcherFactory;
            this.eventBus = eventBus;
        }
Esempio n. 34
0
        /// <summary>
        /// Creates a new instance of RabbitBus.
        /// </summary>
        /// <param name="connectionString">
        /// The EasyNetQ connection string. Example:
        /// host=192.168.1.1;virtualHost=MyVirtualHost;username=MyUsername;password=MyPassword
        ///
        /// The following default values will be used if not specified:
        /// host=localhost;virtualHost=/;username=guest;password=guest
        /// </param>
        /// <param name="logger">
        /// An implementation of IEasyNetQLogger to send the log output to.
        /// </param>
        /// <returns>
        /// A new RabbitBus instance.
        /// </returns>
        public static IBus CreateBus(string connectionString, IEasyNetQLogger logger, ushort prefetchCount = 1000)
        {
            if (connectionString == null)
            {
                throw new ArgumentNullException("connectionString");
            }
            if (logger == null)
            {
                throw new ArgumentNullException("logger");
            }

            var connectionValues = new ConnectionString(connectionString);

            return(CreateBus(
                       connectionValues.Host,
                       connectionValues.VirtualHost,
                       connectionValues.UserName,
                       connectionValues.Password,
                       logger,
                       prefetchCount));
        }
Esempio n. 35
0
        public InternalConsumerFactory(
            IHandlerRunner handlerRunner,
            IEasyNetQLogger logger,
            IConventions conventions,
            ConnectionConfiguration connectionConfiguration,
            IConsumerDispatcherFactory consumerDispatcherFactory,
            IEventBus eventBus)
        {
            Preconditions.CheckNotNull(handlerRunner, "handlerRunner");
            Preconditions.CheckNotNull(logger, "logger");
            Preconditions.CheckNotNull(conventions, "conventions");
            Preconditions.CheckNotNull(connectionConfiguration, "connectionConfiguration");
            Preconditions.CheckNotNull(consumerDispatcherFactory, "consumerDispatcherFactory");

            this.handlerRunner             = handlerRunner;
            this.logger                    = logger;
            this.conventions               = conventions;
            this.connectionConfiguration   = connectionConfiguration;
            this.consumerDispatcherFactory = consumerDispatcherFactory;
            this.eventBus                  = eventBus;
        }
Esempio n. 36
0
        public QueueingConsumerFactory(IEasyNetQLogger logger, IConsumerErrorStrategy consumerErrorStrategy)
        {
            this.logger = logger;
            this.consumerErrorStrategy = consumerErrorStrategy;

            // start the subscription callback thread
            // all subscription actions registered with Subscribe or Request
            // run here.
            subscriptionCallbackThread = new Thread(_ =>
            {
                while (true)
                {
                    if (disposed)
                    {
                        break;
                    }

                    try
                    {
                        BasicDeliverEventArgs deliverEventArgs;
                        lock (sharedQueueLock)
                        {
                            deliverEventArgs = (BasicDeliverEventArgs)sharedQueue.Dequeue();
                        }
                        if (deliverEventArgs != null)
                        {
                            HandleMessageDelivery(deliverEventArgs);
                        }
                    }
                    catch (EndOfStreamException)
                    {
                        // do nothing here, EOS fired when queue is closed
                        // Looks like the connection has gone away, so wait a little while
                        // before continuing to poll the queue
                        Thread.Sleep(10);
                    }
                }
            });
            subscriptionCallbackThread.Start();
        }
Esempio n. 37
0
        public RabbitBus(
            SerializeType serializeType,
            IEasyNetQLogger logger,
            IConventions conventions,
            IAdvancedBus advancedBus,
            IPublishExchangeDeclareStrategy publishExchangeDeclareStrategy)
        {
            Preconditions.CheckNotNull(serializeType, "serializeType");
            Preconditions.CheckNotNull(logger, "logger");
            Preconditions.CheckNotNull(conventions, "conventions");
            Preconditions.CheckNotNull(advancedBus, "advancedBus");
            Preconditions.CheckNotNull(publishExchangeDeclareStrategy, "publishExchangeDeclareStrategy");

            this.serializeType = serializeType;
            this.logger        = logger;
            this.conventions   = conventions;
            this.advancedBus   = advancedBus;
            this.publishExchangeDeclareStrategy = publishExchangeDeclareStrategy;

            advancedBus.Connected    += OnConnected;
            advancedBus.Disconnected += OnDisconnected;
        }
Esempio n. 38
0
        public RabbitBus(
            IEasyNetQLogger logger,
            IConventions conventions,
            IAdvancedBus advancedBus,
            IPublishExchangeDeclareStrategy publishExchangeDeclareStrategy,
            IRpc rpc)
        {
            Preconditions.CheckNotNull(logger, "logger");
            Preconditions.CheckNotNull(conventions, "conventions");
            Preconditions.CheckNotNull(advancedBus, "advancedBus");
            Preconditions.CheckNotNull(publishExchangeDeclareStrategy, "publishExchangeDeclareStrategy");
            Preconditions.CheckNotNull(rpc, "rpc");

            this.logger      = logger;
            this.conventions = conventions;
            this.advancedBus = advancedBus;
            this.publishExchangeDeclareStrategy = publishExchangeDeclareStrategy;
            this.rpc = rpc;

            advancedBus.Connected    += OnConnected;
            advancedBus.Disconnected += OnDisconnected;
        }
Esempio n. 39
0
        public RabbitAdvancedBus(
            IConnectionFactory connectionFactory,
            ISerializer serializer,
            IConsumerFactory consumerFactory,
            IEasyNetQLogger logger,
            Func <string> getCorrelationId,
            IMessageValidationStrategy messageValidationStrategy,
            IClientCommandDispatcherFactory clientCommandDispatcherFactory,
            IPublisherConfirms publisherConfirms,
            IEventBus eventBus,
            ITypeNameSerializer typeNameSerializer)
        {
            Preconditions.CheckNotNull(connectionFactory, "connectionFactory");
            Preconditions.CheckNotNull(serializer, "serializer");
            Preconditions.CheckNotNull(consumerFactory, "consumerFactory");
            Preconditions.CheckNotNull(logger, "logger");
            Preconditions.CheckNotNull(getCorrelationId, "getCorrelationId");
            Preconditions.CheckNotNull(messageValidationStrategy, "messageValidationStrategy");
            Preconditions.CheckNotNull(publisherConfirms, "publisherConfirms");
            Preconditions.CheckNotNull(eventBus, "eventBus");
            Preconditions.CheckNotNull(typeNameSerializer, "typeNameSerializer");

            this.serializer                = serializer;
            this.consumerFactory           = consumerFactory;
            this.logger                    = logger;
            this.getCorrelationId          = getCorrelationId;
            this.messageValidationStrategy = messageValidationStrategy;
            this.publisherConfirms         = publisherConfirms;
            this.eventBus                  = eventBus;
            this.typeNameSerializer        = typeNameSerializer;

            connection = new PersistentConnection(connectionFactory, logger, eventBus);

            eventBus.Subscribe <ConnectionCreatedEvent>(e => OnConnected());
            eventBus.Subscribe <ConnectionDisconnectedEvent>(e => OnDisconnected());

            clientCommandDispatcher = clientCommandDispatcherFactory.GetClientCommandDispatcher(connection);
        }
Esempio n. 40
0
        public ConsumerDispatcher(IEasyNetQLogger logger)
        {
            Preconditions.CheckNotNull(logger, "logger");

            queue = new BlockingCollection<Action>();

            dispatchThread = new Thread(_ =>
                {
                    Action action;
                    while(!disposed && queue.TryTake(out action, -1))
                    {
                        try
                        {
                            action();
                        }
                        catch (Exception exception)
                        {
                            logger.ErrorWrite(exception);
                        }
                    }
                }) { Name = "EasyNetQ consumer dispatch thread" };
            dispatchThread.Start();
        }
Esempio n. 41
0
        public ConsumerDispatcher(IEasyNetQLogger logger)
        {
            Preconditions.CheckNotNull(logger, "logger");

            internalQueue = new ConcurrentQueue <Action>();
            queue         = new BlockingCollection <Action>(internalQueue);

            dispatchThread = new Thread(_ =>
            {
                try
                {
                    while (true)
                    {
                        if (disposed)
                        {
                            break;
                        }

                        queue.Take()();
                    }
                }
                catch (InvalidOperationException)
                {
                    // InvalidOperationException is thrown when Take is called after
                    // queue.CompleteAdding(), this is signals that this class is being
                    // disposed, so we allow the thread to complete.
                }
                catch (Exception exception)
                {
                    logger.ErrorWrite(exception);
                }
            })
            {
                Name = "EasyNetQ consumer dispatch thread"
            };
            dispatchThread.Start();
        }
        public QueueingConsumerFactory(IEasyNetQLogger logger, IConsumerErrorStrategy consumerErrorStrategy)
        {
            this.logger = logger;
            this.consumerErrorStrategy = consumerErrorStrategy;

            // start the subscription callback thread
            // all subscription actions registered with Subscribe or Request
            // run here.
            subscriptionCallbackThread = new Thread(_ =>
            {
                while(true)
                {
                    if (disposed) break;

                    try
                    {
                        BasicDeliverEventArgs deliverEventArgs;
                        lock (sharedQueueLock)
                        {
                            deliverEventArgs = (BasicDeliverEventArgs)sharedQueue.Dequeue();
                        }
                        if(deliverEventArgs != null)
                        {
                            HandleMessageDelivery(deliverEventArgs);
                        }
                    }
                    catch (EndOfStreamException)
                    {
                        // do nothing here, EOS fired when queue is closed
                        // Looks like the connection has gone away, so wait a little while
                        // before continuing to poll the queue
                        Thread.Sleep(10);
                    }
                }
            });
            subscriptionCallbackThread.Start();
        }
Esempio n. 43
0
 public ConsumerErrorStrategy(IConnectionFactory connectionFactory, ISerializer serializer, IEasyNetQLogger logger, IConventions conventions, ITypeNameSerializer typeNameSerializer)
     : base(connectionFactory, serializer, logger, conventions, typeNameSerializer)
 {
 }
Esempio n. 44
0
 public BusThatSendsConfirmations(IConnectionFactory connectionFactory, IConsumerFactory consumerFactory, IEasyNetQLogger logger,
                                  IClientCommandDispatcherFactory clientCommandDispatcherFactory, IPublishConfirmationListener confirmationListener, IEventBus eventBus,
                                  IHandlerCollectionFactory handlerCollectionFactory, IContainer container, ConnectionConfiguration connectionConfiguration,
                                  IProduceConsumeInterceptor produceConsumeInterceptor, IMessageSerializationStrategy messageSerializationStrategy, IConventions conventions,
                                  AdvancedBusEventHandlers advancedBusEventHandlers) : base(connectionFactory, consumerFactory, logger, clientCommandDispatcherFactory,
                                                                                            confirmationListener, eventBus, handlerCollectionFactory, container, connectionConfiguration, produceConsumeInterceptor, messageSerializationStrategy,
                                                                                            conventions, advancedBusEventHandlers)
 {
 }
Esempio n. 45
0
 public static IPublisher CreatePublisher(IConnectionConfiguration configuration, IEasyNetQLogger logger, IEventBus eventBus)
 {
     return(configuration.PublisherConfirms
                ? (IPublisher) new PublisherConfirms(configuration, logger, eventBus)
                : new PublisherBasic(eventBus));
 }
Esempio n. 46
0
 public HandlerCollectionFactory(IEasyNetQLogger logger)
 {
     this.logger = logger;
 }
Esempio n. 47
0
        /// <summary>
        /// Creates a new instance of RabbitBus
        /// </summary>
        /// <param name="hostName">
        /// The RabbitMQ broker.
        /// </param>
        /// <param name="virtualHost">
        /// The RabbitMQ virtualHost.
        /// </param>
        /// <param name="username">
        /// The username to use to connect to the RabbitMQ broker.
        /// </param>
        /// <param name="password">
        /// The password to use to connect to the RabbitMQ broker.
        /// </param>
        /// <param name="logger">
        /// The logger to use.
        /// </param>
        /// <returns>
        /// A new RabbitBus instance.
        /// </returns>
        public static IBus CreateBus(string hostName, string virtualHost, string username, string password, IEasyNetQLogger logger, ushort prefetchCount = 1000)
        {
            if (hostName == null)
            {
                throw new ArgumentNullException("hostName");
            }
            if (virtualHost == null)
            {
                throw new ArgumentNullException("virtualHost");
            }
            if (username == null)
            {
                throw new ArgumentNullException("username");
            }
            if (password == null)
            {
                throw new ArgumentNullException("password");
            }
            if (logger == null)
            {
                throw new ArgumentNullException("logger");
            }

            var connectionFactory = new ConnectionFactoryWrapper(new ConnectionFactory
            {
                HostName    = hostName,
                VirtualHost = virtualHost,
                UserName    = username,
                Password    = password
            });

            var serializer = new JsonSerializer();

            var consumerErrorStrategy = new DefaultConsumerErrorStrategy(connectionFactory, serializer, logger);

            return(new RabbitBus(
                       TypeNameSerializer.Serialize,
                       serializer,
                       new QueueingConsumerFactory(logger, consumerErrorStrategy),
                       connectionFactory,
                       logger,
                       CorrelationIdGenerator.GetCorrelationId,
                       null,
                       prefetchCount));
        }
Esempio n. 48
0
        public RabbitAdvancedBus(
            IConnectionFactory connectionFactory,
            IConsumerFactory consumerFactory,
            IEasyNetQLogger logger,
            IClientCommandDispatcherFactory clientCommandDispatcherFactory,
            IPublishConfirmationListener confirmationListener,
            IEventBus eventBus,
            IHandlerCollectionFactory handlerCollectionFactory,
            IContainer container,
            ConnectionConfiguration connectionConfiguration,
            IProduceConsumeInterceptor produceConsumeInterceptor,
            IMessageSerializationStrategy messageSerializationStrategy,
            IConventions conventions,
            AdvancedBusEventHandlers advancedBusEventHandlers,
            IPersistentConnectionFactory persistentConnectionFactory)
        {
            Preconditions.CheckNotNull(connectionFactory, "connectionFactory");
            Preconditions.CheckNotNull(consumerFactory, "consumerFactory");
            Preconditions.CheckNotNull(logger, "logger");
            Preconditions.CheckNotNull(eventBus, "eventBus");
            Preconditions.CheckNotNull(handlerCollectionFactory, "handlerCollectionFactory");
            Preconditions.CheckNotNull(container, "container");
            Preconditions.CheckNotNull(messageSerializationStrategy, "messageSerializationStrategy");
            Preconditions.CheckNotNull(connectionConfiguration, "connectionConfiguration");
            Preconditions.CheckNotNull(produceConsumeInterceptor, "produceConsumeInterceptor");
            Preconditions.CheckNotNull(conventions, "conventions");
            Preconditions.CheckNotNull(advancedBusEventHandlers, "advancedBusEventHandlers");
            Preconditions.CheckNotNull(persistentConnectionFactory, "persistentConnectionFactory");

            this.consumerFactory              = consumerFactory;
            this.logger                       = logger;
            this.confirmationListener         = confirmationListener;
            this.eventBus                     = eventBus;
            this.handlerCollectionFactory     = handlerCollectionFactory;
            this.container                    = container;
            this.connectionConfiguration      = connectionConfiguration;
            this.produceConsumeInterceptor    = produceConsumeInterceptor;
            this.messageSerializationStrategy = messageSerializationStrategy;
            this.conventions                  = conventions;

            this.eventBus.Subscribe <ConnectionCreatedEvent>(e => OnConnected());
            if (advancedBusEventHandlers.Connected != null)
            {
                Connected += advancedBusEventHandlers.Connected;
            }
            this.eventBus.Subscribe <ConnectionDisconnectedEvent>(e => OnDisconnected());
            if (advancedBusEventHandlers.Disconnected != null)
            {
                Disconnected += advancedBusEventHandlers.Disconnected;
            }
            this.eventBus.Subscribe <ConnectionBlockedEvent>(OnBlocked);
            if (advancedBusEventHandlers.Blocked != null)
            {
                Blocked += advancedBusEventHandlers.Blocked;
            }
            this.eventBus.Subscribe <ConnectionUnblockedEvent>(e => OnUnblocked());
            if (advancedBusEventHandlers.Unblocked != null)
            {
                Unblocked += advancedBusEventHandlers.Unblocked;
            }
            this.eventBus.Subscribe <ReturnedMessageEvent>(OnMessageReturned);
            if (advancedBusEventHandlers.MessageReturned != null)
            {
                MessageReturned += advancedBusEventHandlers.MessageReturned;
            }

            connection = persistentConnectionFactory.CreateConnection();
            clientCommandDispatcher = clientCommandDispatcherFactory.GetClientCommandDispatcher(connection);
            connection.Initialize();
        }
Esempio n. 49
0
        public static IBus CreateBus(IEasyNetQLogger easyNetQLogger)
        {
            var connectionString = System.Configuration.ConfigurationManager.AppSettings ["RabbitMQ"];

            return(RabbitHutch.CreateBus(connectionString, x => x.Register <IEasyNetQLogger>(_ => easyNetQLogger)));
        }
Esempio n. 50
0
 public ExceptionlessConsumerErrorStrategy(IConnectionFactory connectionFactory, ISerializer serializer, IEasyNetQLogger logger, IConventions conventions, ITypeNameSerializer typeNameSerializer, IErrorMessageSerializer errorMessageSerializer, ExceptionlessClient client = null, Action <EventBuilder, ConsumerExecutionContext> intercept = null)
     : base(connectionFactory, serializer, logger, conventions, typeNameSerializer, errorMessageSerializer)
 {
     _client    = client ?? ExceptionlessClient.Default;
     _intercept = intercept;
 }
Esempio n. 51
0
 public BasicConsumer(Action <BasicConsumer> cancelled, IConsumerDispatcher consumerDispatcher, IQueue queue, IEventBus eventBus, IHandlerRunner handlerRunner, Func <byte[], MessageProperties, MessageReceivedInfo, Task> onMessage, IEasyNetQLogger logger, IModel model)
 {
     Queue                   = queue;
     OnMessage               = onMessage;
     this.cancelled          = cancelled;
     this.consumerDispatcher = consumerDispatcher;
     this.eventBus           = eventBus;
     this.handlerRunner      = handlerRunner;
     this.logger             = logger;
     Model                   = model;
 }
Esempio n. 52
0
 public PersistentConnectionFactory(IEasyNetQLogger logger, IConnectionFactory connectionFactory, IEventBus eventBus)
 {
     this.logger            = logger;
     this.connectionFactory = connectionFactory;
     this.eventBus          = eventBus;
 }
Esempio n. 53
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PollyHandlerRunner"/> class.
 /// </summary>
 /// <param name="logger">A reference to an EasyNetQ logger implementation.</param>
 /// <param name="consumerErrorStrategy">A reference to a consumer error strategy.</param>
 /// <param name="eventBus">A reference to an event bus.</param>
 /// <param name="policy">A reference to the policy within which message consumers will be executed.</param>
 public PollyHandlerRunner(IEasyNetQLogger logger, IConsumerErrorStrategy consumerErrorStrategy, IEventBus eventBus, Policy policy)
     : base(logger, consumerErrorStrategy, eventBus)
 {
     _logger = logger ?? throw new ArgumentNullException(nameof(logger));
     _policy = policy ?? throw new ArgumentNullException(nameof(policy));
 }
 public DeadLetterStrategy(IConnectionFactory connectionFactory, ISerializer serializer, IEasyNetQLogger logger, IConventions conventions, ITypeNameSerializer typeNameSerializer, IErrorMessageSerializer errorMessageSerializer)
     : base(connectionFactory, serializer, logger, conventions, typeNameSerializer, errorMessageSerializer)
 {
 }
Esempio n. 55
0
        public ConsumerDispatcherFactory(IEasyNetQLogger logger)
        {
            Preconditions.CheckNotNull(logger, "logger");

            dispatcher = new Lazy <IConsumerDispatcher>(() => new ConsumerDispatcher(logger));
        }
 public PublisherService(IBus bus, IEasyNetQLogger log)
 {
     this.bus = bus;
     this.log = log;
 }
Esempio n. 57
0
 public void SetUp()
 {
     logger            = MockRepository.GenerateStub <IEasyNetQLogger>();
     dispatcherFactory = new ConsumerDispatcherFactory(logger);
 }