Esempio n. 1
0
        protected virtual void ConnectToBroker()
        {
            if (Channel == null || Channel.IsClosed)
            {
                var connection = new RMQMessageGatewayConnectionPool(Connection.Name).GetConnection(_connectionFactory);

                _logger.Value.DebugFormat("RMQMessagingGateway: Opening channel to Rabbit MQ on connection {0}",
                                          Connection.AmpqUri.GetSanitizedUri());

                Channel = connection.CreateModel();

                //When AutoClose is true, the last channel to close will also cause the connection to close1. If it is set to
                //true before any channel is created, the connection will close then and there.
                if (connection.AutoClose == false)
                {
                    connection.AutoClose = true;
                }

                _logger.Value.DebugFormat("RMQMessagingGateway: Declaring exchange {0} on connection {1}",
                                          Connection.Exchange.Name, Connection.AmpqUri.GetSanitizedUri());

                //desired state configuration of the exchange
                Channel.DeclareExchangeForConnection(Connection);
            }
        }
        protected virtual void ConnectToBroker()
        {
            if (Channel == null || Channel.IsClosed)
            {
                var connection = new RMQMessageGatewayConnectionPool(Connection.Name, Connection.Heartbeat).GetConnection(_connectionFactory);

                connection.ConnectionBlocked   += HandleBlocked;
                connection.ConnectionUnblocked += HandleUnBlocked;

                _logger.Value.DebugFormat("RMQMessagingGateway: Opening channel to Rabbit MQ on connection {0}",
                                          Connection.AmpqUri.GetSanitizedUri());

                Channel = connection.CreateModel();

                //set the number of messages to fetch -- defaults to 1 unless set on connection, no impact on
                //BasicGet, only works on BasicConsume
                Channel.BasicQos(0, _batchSize, false);

                //When AutoClose is true, the last channel to close will also cause the connection to close. If it is set to
                //true before any channel is created, the connection will close then and there.
                if (connection.AutoClose == false)
                {
                    connection.AutoClose = true;
                }

                _logger.Value.DebugFormat("RMQMessagingGateway: Declaring exchange {0} on connection {1}",
                                          Connection.Exchange.Name, Connection.AmpqUri.GetSanitizedUri());

                //desired state configuration of the exchange
                Channel.DeclareExchangeForConnection(Connection);
            }
        }