public RabbitMqMessageBus(  IDependencyResolver resolver, 
                                    RabbitMqScaleoutConfiguration configuration, 
                                    RabbitConnectionBase advancedConnectionInstance = null)
            : base(resolver, configuration)
        {
	        if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            _rabbitConnectionBase = advancedConnectionInstance ?? new EasyNetQRabbitConnection(configuration);
            _rabbitConnectionBase.OnDisconnectionAction = OnConnectionLost;
            _rabbitConnectionBase.OnReconnectionAction = ConnectToRabbit;
            _rabbitConnectionBase.OnMessageReceived = wrapper => Receivingbuffer.Add(wrapper);

            ConnectToRabbit();

            Task.Factory.StartNew(()=>
            {
	            while (true)
	            {
		            foreach (var message in Receivingbuffer.GetConsumingEnumerable())
		            {
			            try
			            {
				            OnReceived(0, message.Id, message.ScaleoutMessage);
			            }
			            catch
			            {
				            OnConnectionLost();
			            }
		            }
	            }
            });
        }
Beispiel #2
0
        public RabbitMqMessageBus(IDependencyResolver resolver,
                                  RabbitMqScaleoutConfiguration configuration,
                                  RabbitConnectionBase advancedConnectionInstance = null)
            : base(resolver, configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            _rabbitConnectionBase = advancedConnectionInstance ?? new RabbitConnection(configuration);
            _rabbitConnectionBase.OnDisconnectionAction = OnConnectionLost;
            _rabbitConnectionBase.OnReconnectionAction  = ConnectToRabbit;
            _rabbitConnectionBase.OnMessageReceived     = wrapper => Receivingbuffer.Add(wrapper);

            ConnectToRabbit();

            Task.Factory.StartNew(() =>
            {
                while (true)
                {
                    foreach (var message in Receivingbuffer.GetConsumingEnumerable())
                    {
                        try
                        {
                            OnReceived(0, message.Id, message.ScaleoutMessage);
                        }
                        catch
                        {
                            OnConnectionLost();
                        }
                    }
                }
            });
        }
        public RabbitMqMessageBus(  IDependencyResolver resolver, 
                                    RabbitMqScaleoutConfiguration configuration, 
                                    RabbitConnectionBase advancedConnectionInstance = null)
            : base(resolver, configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }
            _configuration = configuration;

            if (advancedConnectionInstance != null)
            {
                advancedConnectionInstance.OnDisconnectionAction = OnConnectionLost;
                advancedConnectionInstance.OnReconnectionAction = ConnectToRabbit;
                advancedConnectionInstance.OnMessageRecieved =
                    wrapper => OnReceived(0, wrapper.Id, wrapper.ScaleoutMessage);

                _rabbitConnectionBase = advancedConnectionInstance;
            }
            else
            {
                _rabbitConnectionBase = new EasyNetQRabbitConnection(_configuration)
                                            {
                                                OnDisconnectionAction = OnConnectionLost,
                                                OnReconnectionAction = ConnectToRabbit,
                                                OnMessageRecieved = ForwardOnReceivedMessage
                                            };
            }
            _messageIdentifierGenerator = new UniqueMessageIdentifierGenerator();
            ConnectToRabbit();
        }
        public RabbitMqMessageBus(  IDependencyResolver resolver, 
                                    RabbitMqScaleoutConfiguration configuration, 
                                    RabbitConnectionBase advancedConnectionInstance = null)
            : base(resolver, configuration)
        {

            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }
            _configuration = configuration;

            var traceManager = resolver.Resolve<ITraceManager>();
            _trace = traceManager["SignalR.RabbitMQ." + typeof(RabbitMqMessageBus).Name];

            if (advancedConnectionInstance != null)
            {
                advancedConnectionInstance.OnDisconnectionAction = OnConnectionLost;
                advancedConnectionInstance.OnReconnectionAction = ConnectToRabbit;
                advancedConnectionInstance.OnMessageRecieved =
                    wrapper => _recievingbuffer.Add(wrapper);

                _rabbitConnectionBase = advancedConnectionInstance;
            }
            else
            {
                _rabbitConnectionBase = new EasyNetQRabbitConnection(_configuration)
                                            {
                                                OnDisconnectionAction = OnConnectionLost,
                                                OnReconnectionAction = ConnectToRabbit,
                                                OnMessageRecieved = wrapper => _recievingbuffer.Add(wrapper)
                                            };
            }

            ConnectToRabbit();

            _recievingworkerTask = Task.Factory.StartNew(()=>
            {
                while (true)
                {
                    foreach (var message in _recievingbuffer.GetConsumingEnumerable())
                    {
                        try
                        {
                            OnReceived(0, message.Id, message.ScaleoutMessage);
                        }
                        catch
                        {
                            OnConnectionLost();
                        }
                    }
                }
            });
        }
Beispiel #5
0
        public RabbitMqMessageBus(IDependencyResolver resolver,
                                  RabbitMqScaleoutConfiguration configuration,
                                  RabbitConnectionBase advancedConnectionInstance = null)
            : base(resolver, configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }
            _configuration = configuration;

            var traceManager = resolver.Resolve <ITraceManager>();

            _trace = traceManager["SignalR.RabbitMQ." + typeof(RabbitMqMessageBus).Name];

            if (advancedConnectionInstance != null)
            {
                advancedConnectionInstance.OnDisconnectionAction = OnConnectionLost;
                advancedConnectionInstance.OnReconnectionAction  = ConnectToRabbit;
                advancedConnectionInstance.OnMessageRecieved     =
                    wrapper => _recievingbuffer.Add(wrapper);

                _rabbitConnectionBase = advancedConnectionInstance;
            }
            else
            {
                _rabbitConnectionBase = new EasyNetQRabbitConnection(_configuration)
                {
                    OnDisconnectionAction = OnConnectionLost,
                    OnReconnectionAction  = ConnectToRabbit,
                    OnMessageRecieved     = wrapper => _recievingbuffer.Add(wrapper)
                };
            }

            ConnectToRabbit();

            _recievingworkerTask = Task.Factory.StartNew(() =>
            {
                while (true)
                {
                    foreach (var message in _recievingbuffer.GetConsumingEnumerable())
                    {
                        try
                        {
                            OnReceived(0, message.Id, message.ScaleoutMessage);
                        }
                        catch
                        {
                            OnConnectionLost();
                        }
                    }
                }
            });
        }
        private static IDependencyResolver RegisterBus(IDependencyResolver resolver, RabbitMqScaleoutConfiguration configuration, RabbitConnectionBase advancedConnectionInstance = null)
        {
            RabbitMqMessageBus bus = null;
            var initialized = false;
            var syncLock = new object();
            Func<RabbitMqMessageBus> busFactory = () => new RabbitMqMessageBus(resolver, configuration, advancedConnectionInstance);

            resolver.Register(typeof (IMessageBus), () => LazyInitializer.EnsureInitialized(ref bus, ref initialized, ref syncLock, busFactory));
            
            return resolver;
        }
        public static IDependencyResolver UseRabbitMqAdvanced(this IDependencyResolver resolver, RabbitConnectionBase myConnection, RabbitMqScaleoutConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            var bus = new Lazy<RabbitMqMessageBus>(() => new RabbitMqMessageBus(resolver, configuration, myConnection));
            resolver.Register(typeof(IMessageBus), () => bus.Value);

            return resolver;
        }
Beispiel #8
0
        public static IDependencyResolver UseRabbitMqAdvanced(this IDependencyResolver resolver, RabbitConnectionBase myConnection, RabbitMqScaleoutConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            var bus = new Lazy <RabbitMqMessageBus>(() => new RabbitMqMessageBus(resolver, configuration, myConnection));

            resolver.Register(typeof(IMessageBus), () => bus.Value);

            return(resolver);
        }
        private static IDependencyResolver RegisterBus(IDependencyResolver resolver, RabbitMqScaleoutConfiguration configuration, RabbitConnectionBase advancedConnectionInstance = null)
        {
            RabbitMqMessageBus bus = null;
            var initialized        = false;
            var syncLock           = new object();
            Func <RabbitMqMessageBus> busFactory = () => new RabbitMqMessageBus(resolver, configuration, advancedConnectionInstance);

            resolver.Register(typeof(IMessageBus), () => LazyInitializer.EnsureInitialized(ref bus, ref initialized, ref syncLock, busFactory));

            return(resolver);
        }
 public static IDependencyResolver UseRabbitMqAdvanced(this IDependencyResolver resolver, RabbitConnectionBase myConnection, RabbitMqScaleoutConfiguration configuration)
 {
     return(RegisterBus(resolver, configuration, myConnection));
 }
 public static IDependencyResolver UseRabbitMqAdvanced(this IDependencyResolver resolver, RabbitConnectionBase myConnection, RabbitMqScaleoutConfiguration configuration)
 {
     return RegisterBus(resolver, configuration, myConnection);
 }