public static RawRabbitConfiguration Parse(string connectionString)
        {
            var cfg = new RawRabbitConfiguration();

            var brokersMatch = _brokers.Match(connectionString);
            var brokerStrs = brokersMatch.Groups["brokers"].Value.Split(',');

            foreach (var broker in brokerStrs)
            {
                int port;
                var brokerMatch = _broker.Match(broker);
                var brokerCfg = new BrokerConfiguration
                {
                    Hostname = brokerMatch.Groups["host"].Value,
                    VirtualHost = brokerMatch.Groups["vhost"].Value,
                    Port = int.TryParse(brokerMatch.Groups["port"].Value, out port) ? port : default(int),
                    Username = brokerMatch.Groups["user"].Value,
                    Password = brokerMatch.Groups["password"].Value,
                };
                cfg.Brokers.Add(brokerCfg);
            }

            var reqMatch = _requestTimeout.Match(connectionString);
            var timeoutGrp = reqMatch.Groups["timeout"];
            if (timeoutGrp.Success)
            {
                cfg.RequestTimeout = TimeSpan.FromSeconds(int.Parse(timeoutGrp.Value));
            }

            return cfg;
        }
Пример #2
0
 public SingleNodeBroker(BrokerConfiguration config = null)
 {
     config = config ?? BrokerConfiguration.Local;
     _factory = new ConnectionFactory
     {
         HostName = config.Hostname,
         VirtualHost = config.VirtualHost,
         Password = config.Password,
         UserName = config.Username
     };
     _connection = _factory.CreateConnection();
 }
        public IDictionary<string, object> GetClientProperties(RawRabbitConfiguration cfg = null, BrokerConfiguration brokerCfg = null)
        {
            var props = new Dictionary<string, object>
            {
                { "client_api", "RawRabbit" },
                { "client_version", typeof(BusClient).Assembly.GetName().Version.ToString() },
                { "client_directory", typeof(BusClient).Assembly.CodeBase},
                { "client_connected", DateTime.UtcNow.ToString("u") },
                { "client_server", Environment.MachineName },
            };
            if (brokerCfg != null)
            {
                props.Add("broker_username", brokerCfg.Username);
            }
            if (cfg != null)
            {
                props.Add("request_timeout", cfg.RequestTimeout.ToString("g"));
            }

            return props;
        }
 private static List<BrokerConfiguration> GetBrokers(IConfiguration root)
 {
     var result = new List<BrokerConfiguration>();
     var continueParsing = true;
     var index = 0;
     while (continueParsing)
     {
         int port;
         var broker = new BrokerConfiguration
         {
             Hostname = root[$"Data:RawRabbit:Brokers:{index}:Hostname"],
             VirtualHost = root[$"Data:RawRabbit:Brokers:{index}:VirtualHost"],
             Port = int.TryParse(root[$"Data:RawRabbit:Brokers:{index}:Port"], out port) ? port : default(int),
             Username = root[$"Data:RawRabbit:Brokers:{index}:Username"],
             Password = root[$"Data:RawRabbit:Brokers:{index}:Password"]
         };
         if (string.IsNullOrWhiteSpace(broker.Hostname))
         {
             continueParsing = false;
             continue;
         }
         result.Add(broker);
         index++;
     }
     return result;
 }