Example #1
0
 public static void Main()
 {
     IocContainer.Container = IoC.Container;
       Database.SetInitializer<ContactsContext>(null);
       var mqListener = new RabbitListener {Enabled = true};
       mqListener.Start();
 }
Example #2
0
        protected RabbitListener createListener(IRegistration registration, Exchange exchange)
        {
            // create a channel
            var connection = _connFactory.ConnectTo(exchange);

            // create a listener
            RabbitListener listener = new RabbitListener(registration, exchange, connection);

            listener.OnEnvelopeReceived += dispatcher =>
            {
                Log.Debug("Got an envelope from the RabbitListener: dispatching.");
                // the dispatcher encapsulates the logic of giving the envelope to handlers
                dispatcher.Dispatch();
            };
            listener.OnClose += _listeners.Remove;

            //TODO: Resolve that RabbitListener does not implement OnConnectionError
            //listener.OnConnectionError(new ReconnectOnConnectionErrorCallback(_channelFactory));

            // store the listener
            _listeners.Add(registration, listener);

            // put it on another thread so as not to block this one
            // don't continue on this thread until we've started listening
            ManualResetEvent startEvent     = new ManualResetEvent(false);
            Thread           listenerThread = new Thread(listener.Start);

            listenerThread.Name = string.Format("{0} on {1}:{2}{3}", exchange.QueueName, exchange.HostName, exchange.Port, exchange.VirtualHost);
            listenerThread.Start(startEvent);

            return(listener);
        }
Example #3
0
    public static IApplicationBuilder ConsulRegister(this IApplicationBuilder app)
    {
        Listener = app.ApplicationServices.GetService <RabbitListener>();
        var life = app.ApplicationServices.GetService <IApplicationLifetime>();

        life.ApplicationStarted.Register(OnStarted);
        //press Ctrl+C to reproduce if app is runned in local Kestrel
        life.ApplicationStopping.Register(OnStopping);
        return(app);
    }
Example #4
0
    public static IApplicationBuilder UseRabbitListener(this IApplicationBuilder app)
    {
        Listener = app.ApplicationServices.GetService <RabbitListener>();
        var life = app.ApplicationServices.GetService <IApplicationLifetime>();

        life.ApplicationStarted.Register(OnStarted);
        //press Ctrl+C to reproduce if your app runs in Kestrel as a console app
        life.ApplicationStopping.Register(OnStopping);
        return(app);
    }
Example #5
0
        public virtual void Unregister(IRegistration registration)
        {
            if (_listeners.ContainsKey(registration))
            {
                RabbitListener listener = _listeners[registration];
                listener.Stop();

                _listeners.Remove(registration);
            }
        }
Example #6
0
        public static IApplicationBuilder UseRabbitListener(this IApplicationBuilder app)
        {
            //_generalLedgerListener = app.ApplicationServices.GetService<GeneralLedgerListener>();
            _rabbitListener = app.ApplicationServices.GetService <RabbitListener>();
            //_listener = app.ApplicationServices.GetService<RabbitListener>();

            var lifetime = app.ApplicationServices.GetService <IApplicationLifetime>();

            lifetime.ApplicationStarted.Register(OnStarted);
            lifetime.ApplicationStopping.Register(OnStopping);
            //press Ctrl+C to reproduce if your app runs in Kestrel as a console app
            //lifetime.ApplicationStopping.Register(() => _listener.Deregister());
            // OnStopping();
            return(app);
        }
Example #7
0
        static void Main(string[] args)
        {
            //Set up handler to be fired when console closes
            _handler += new EventHandler(Handler);
            SetConsoleCtrlHandler(_handler, true);

            Console.WriteLine("Initializing Robot...");

            SqlServerDataContext dataContext = new SqlServerDataContext();

            CouchbaseConnector.OpenCouchbaseConnection();

            RabbitListener listener = new RabbitListener(dataContext);

            listener.ReceiveMessageOnQueue("client_browser_info");
            listener.ReceiveMessageOnQueue("client_purchase_info");
            listener.ReceiveMessageOnQueue("client_user_info");
        }
Example #8
0
        public void Register(IRegistration registration)
        {
            Log.Debug("Enter Register");

            // first, get the topology based on the registration info
            RoutingInfo routing = _topologyService.GetRoutingInfo(registration.Info);

            // next, pull out all the producer exchanges
            List <Exchange> exchanges = new List <Exchange>();

            foreach (RouteInfo route in routing.Routes)
            {
                exchanges.Add(route.ConsumerExchange);
            }

            foreach (var exchange in exchanges)
            {
                RabbitListener listener = createListener(registration, exchange);
            }

            Log.Debug("Leave Register");
        }
Example #9
0
        public void Register(IRegistration registration)
        {
            Log.Debug("Enter Register");

            // first, get the topology based on the registration info
            RoutingInfo routing = this.GetRoutingFromCacheOrService(_routingInfoCache, _topoSvc, registration.Info);

            // next, pull out all the consumer exchanges
            IEnumerable <Exchange> exchanges =
                from route in routing.Routes
                select route.ConsumerExchange;

            foreach (Exchange ex in exchanges)
            {
                IConnection conn = _connFactory.ConnectTo(ex);

                // create a listener
                RabbitListener listener = new RabbitListener(registration, ex, conn);
                listener.OnEnvelopeReceived += this.listener_OnEnvelopeReceived;
                listener.OnClose            += _listeners.Remove;

                // put it on another thread so as not to block this one but
                // don't continue on this thread until we've started listening
                ManualResetEvent startEvent     = new ManualResetEvent(false);
                Thread           listenerThread = new Thread(listener.Start);
                listenerThread.Name = string.Format("{0} on {1}:{2}{3}", ex.QueueName, ex.HostName, ex.Port, ex.VirtualHost);
                listenerThread.Start(startEvent);

                // wait for the RabbitListener to start
                startEvent.WaitOne(new TimeSpan(0, 0, 30));

                // store the listener
                _listeners.Add(registration, listener);
            }

            Log.Debug("Leave Register");
        }
 public SubscribeOnQueueCommandHandler(RabbitListener messageBroker)
 {
     MessageBroker = messageBroker;
 }
 public SendMessageToQueueCommandHandler(RabbitListener messageBroker)
 {
     MessageBroker = messageBroker;
 }
        protected RabbitListener createListener(IRegistration registration, Exchange exchange)
        {
            // create a channel
            var connection = _connFactory.ConnectTo(exchange);

            // create a listener
            RabbitListener listener = new RabbitListener(registration, exchange, connection);
            listener.OnEnvelopeReceived += dispatcher =>
                {
                    Log.Debug("Got an envelope from the RabbitListener: dispatching.");
                    // the dispatcher encapsulates the logic of giving the envelope to handlers
                    dispatcher.Dispatch();
                };
            listener.OnClose += _listeners.Remove;

            //TODO: Resolve that RabbitListener does not implement OnConnectionError
            //listener.OnConnectionError(new ReconnectOnConnectionErrorCallback(_channelFactory));

            // store the listener
            _listeners.Add(registration, listener);

            // put it on another thread so as not to block this one
            // don't continue on this thread until we've started listening
            ManualResetEvent startEvent = new ManualResetEvent(false);
            Thread listenerThread = new Thread(listener.Start);
            listenerThread.Name = string.Format("{0} on {1}:{2}{3}", exchange.QueueName, exchange.HostName, exchange.Port, exchange.VirtualHost);
            listenerThread.Start(startEvent);

            return listener;
        }
        public void Register(IRegistration registration)
        {
            Log.Debug("Enter Register");

            // first, get the topology based on the registration info
            RoutingInfo routing = this.GetRoutingFromCacheOrService(_routingInfoCache, _topoSvc, registration.Info);

            // next, pull out all the consumer exchanges
            IEnumerable<Exchange> exchanges =
                from route in routing.Routes
                select route.ConsumerExchange;

            foreach (Exchange ex in exchanges)
            {
                IConnection conn = _connFactory.ConnectTo(ex);

                // create a listener
                RabbitListener listener = new RabbitListener(registration, ex, conn);
                listener.OnEnvelopeReceived += this.listener_OnEnvelopeReceived;
                listener.OnClose += _listeners.Remove;

                // put it on another thread so as not to block this one but
                // don't continue on this thread until we've started listening
                ManualResetEvent startEvent = new ManualResetEvent(false);
                Thread listenerThread = new Thread(listener.Start);
                listenerThread.Name = string.Format("{0} on {1}:{2}{3}", ex.QueueName, ex.HostName, ex.Port, ex.VirtualHost);
                listenerThread.Start(startEvent);

                // wait for the RabbitListener to start
                startEvent.WaitOne(new TimeSpan(0, 0, 30));

                // store the listener
                _listeners.Add(registration, listener);
            }

            Log.Debug("Leave Register");
        }
Example #14
0
 public RabbitMQController(MessageRepository message, RabbitListener rabbit)
 {
     this._message = message;
     this._rabbit  = rabbit;
 }