///   <summary>
        ///
        ///   </summary>
        /// <param name="connectionString">Format {user}:{password}@{host}:{port}/{virtualHost}</param>
        /// <param name="connectionPerQueue"></param>
        /// <param name="serializer"></param>
        /// <param name="logger"></param>
        /// <param name="heartbeat"></param>
        public RabbitMQClient(string connectionString, ISerializer serializer = null, ILogger logger = null, ushort heartbeat = 60, bool connectionPerQueue = true)
            : this(connectionPerQueue)
        {
            var match = _connectionStringPattern.Match(connectionString);
            if (!match.Success)
            {
                throw new ArgumentException("Expected format: {user}:{password}@{host}:{port}/{virtualHost}", nameof(connectionString));
            }

            _connectionFactory = new ConnectionFactory
            {
                HostName    = match.Groups["host"].Value,
                Port        = int.Parse(match.Groups["port"].Value),
                UserName    = match.Groups["user"].Value,
                Password    = match.Groups["password"].Value,
                VirtualHost = match.Groups["vhost"].Value,
                AutomaticRecoveryEnabled = true,
                RequestedHeartbeat       = heartbeat,
            };

            _rabbitMQConnectionManager = new RabbitMQConnectionManager(_connectionFactory, logger);
            _rabbitMQConnectionManager.CreateConnection("publisher");
            _modelPublisher = _rabbitMQConnectionManager.ConnectionByName("publisher").CreateModel(false);
            _serializer     = serializer ?? new JsonSerializer();
            _logger         = logger;

            _httpClient = GetHttpClient(match.Groups["user"].Value, match.Groups["password"].Value, match.Groups["host"].Value, int.Parse(match.Groups["port"].Value));
        }
        public RabbitMQClient(ConnectionFactory connectionFactory, ISerializer serializer = null, ILogger logger = null, bool connectionPerQueue = true)
            : this(connectionPerQueue)
        {
            _rabbitMQConnectionManager = new RabbitMQConnectionManager(connectionFactory, logger);
            _rabbitMQConnectionManager.CreateConnection("publisher");
            _modelPublisher = _rabbitMQConnectionManager.ConnectionByName("publisher").CreateModel(false);
            _serializer     = serializer ?? new JsonSerializer();
            _logger         = logger;

            _httpClient = GetHttpClient(connectionFactory.UserName, connectionFactory.Password, connectionFactory.HostName, connectionFactory.Port);
        }
 public Task QueueDeclareAsync(string queueName, bool durable         = true, bool exclusive = false, bool autoDelete = false,
                               IDictionary <string, object> arguments = null)
 {
     return(Task.Factory.StartNew(() =>
     {
         _rabbitMQConnectionManager.ConnectionByName("publisher").CreateModel(false).Model.QueueDeclare(queueName, durable, exclusive, autoDelete, arguments);
     }));
 }
        public RabbitMQClient(string hostName, int port, string userName, string password, string virtualHost,
                              ISerializer serializer = null, ILogger logger = null, ushort heartbeat = 60, bool connectionPerQueue = true)
            : this(connectionPerQueue)
        {
            _connectionFactory = new ConnectionFactory
            {
                HostName    = hostName,
                Port        = port,
                UserName    = userName,
                Password    = password,
                VirtualHost = virtualHost,
                AutomaticRecoveryEnabled = true,
                RequestedHeartbeat       = heartbeat,
            };

            _rabbitMQConnectionManager = new RabbitMQConnectionManager(_connectionFactory, logger);
            _rabbitMQConnectionManager.CreateConnection("publisher");
            _modelPublisher = _rabbitMQConnectionManager.ConnectionByName("publisher").CreateModel(false);
            _serializer     = serializer ?? new JsonSerializer();
            _logger         = logger;

            _httpClient = GetHttpClient(userName, password, hostName, port);
        }