Exemplo n.º 1
0
        private static Func <IConnection> CreateConnection(RabbitMQOptions options)
        {
            var factory = new ConnectionFactory
            {
                RequestedConnectionTimeout = options.RequestedConnectionTimeout,
                AutomaticRecoveryEnabled   = true,
            };

            return(() =>
            {
                int length = options.Uris.Length;
                for (int i = 0; i < length; i++)
                {
                    factory.Uri = new Uri(options.Uris[i]);
                    // factory.VirtualHost = options.VirtualHost;
                    try
                    {
                        return factory.CreateConnection();
                    }
                    catch (Exception ex)
                    {
                        if (i == length)
                        {
                            throw new RabbitMQExcepiton("CreateConnection异常!");
                        }
                    }
                }
                return null;
            });
        }
        public RabbitMQConsumerClient(string queueName,
                                      string exchangeName,
                                      string exchangeType,
                                      ConnectionPool connectionPool,
                                      RabbitMQOptions options)
        {
            _queueName       = queueName;
            _connectionPool  = connectionPool;
            _rabbitMQOptions = options;
            _exchangeName    = exchangeName;
            _exchangeType    = exchangeType;

            InitClient();
        }
Exemplo n.º 3
0
        public ConnectionPool(RabbitMQOptions options)
        {
            _maxSize = DefaultPoolSize;

            createConnectionFunc = CreateConnection(options);
        }
Exemplo n.º 4
0
 public RabbitMQConsumerClientFactory(RabbitMQOptions rabbitMQOptions, ConnectionPool pool)
 {
     _rabbitMQOptions = rabbitMQOptions;
     _connectionPool  = pool;
 }