public void Connect() { if (_channel != null) { return; } _connectionLock.Wait(); try { if (_channel == null) { _connection = _channelPool.GetConnection(); _channel = _connection.CreateModel(); // 声明交换机 _channel.ExchangeDeclare(_clientOption.Exchange, _clientOption.ExchangeType, true); var arguments = new Dictionary <string, object>(); if (_rabbitMQOptions.QueueMessageExpires > 0) { arguments.Add(RabbitMQHeaders.XMessageTTL, _rabbitMQOptions.QueueMessageExpires); } // 声明队列 _channel.QueueDeclare(_clientOption.QueueName, durable: true, exclusive: false, autoDelete: false, arguments: arguments); } } finally { _connectionLock.Release(); } }