Exemplo n.º 1
0
        //private readonly string HostName = "localhost";
        //private readonly int Port = 5672;
        //private readonly string UserName = "******";
        //private readonly string Password = "******";
        //private readonly string QueueName = "QueueName";



        public RabbitMqChannelReceivedServer(ILogManager logger, IConfigProvider configProvider, ICommandHandleFactory handleFactory)
        {
            _logger               = logger;
            _rabbitMqConnection   = configProvider?.GetRabbitMqConnection();
            _commandHandleFactory = handleFactory;
            _semaphore            = new SemaphoreSlim(_rabbitMqConnection.MaxExecutingCommands);//并发数
            _logger.Info($"{nameof(RabbitMqChannelReceivedServer)} init");
        }
        //private readonly ILogManager _logManager;

        public RabbitMqHelper(IConfigProvider configProvider)
        {
            _rabbitMqConnection = configProvider.GetRabbitMqConnection();

            //创建连接工厂
            var connectionFactory = new ConnectionFactory //创建连接工厂对象
            {
                HostName = _rabbitMqConnection.HostName,  //IP地址
                Port     = _rabbitMqConnection.Port,      //端口号
                UserName = _rabbitMqConnection.UserName,  //用户账号
                Password = _rabbitMqConnection.Password   //用户密码
            };

            //创建连接
            _connection = connectionFactory.CreateConnection();
            //创建通道
            _channel = _connection.CreateModel();
            //声明交换机
            _channel.ExchangeDeclare(_rabbitMqConnection.ExchangeName, ExchangeType.Topic);
        }
 public RabbitMqChannelWriteClient(ILogManager logManager, IConfigProvider configProvider)
 {
     _logManager         = logManager;
     _rabbitMqConnection = configProvider.GetRabbitMqConnection();
 }