Esempio n. 1
0
        public RabbitConnection(string receiveQueue, string receiveExchange, string routingKey, RabbitServerSetting setting, Func <RabbitConnection, object, BasicDeliverEventArgs, Task> receiveAction)
        {
            _receiveQueue    = receiveQueue ?? throw new ArgumentNullException("The queue must be declare!");
            _receiveExchange = receiveExchange ?? throw new ArgumentNullException("The exchange must be declare!");
            _setting         = setting ?? throw new ArgumentNullException("The rabbitmq host setting must be declare!");
            _receiveAction   = receiveAction ?? throw new ArgumentNullException("The receive action must be declare!");
            _routingKey      = routingKey ?? "#";

            _logger         = ObjectContainer.Resolve <ILoggerFactory>().Create <RabbitConnection>();
            _jsonSerializer = ObjectContainer.Resolve <IJsonSerializer>();
        }
Esempio n. 2
0
        private List <RabbitServerSetting> DecodeServer(RabbitServerSetting serverSetting)
        {
            if (serverSetting == null)
            {
                return(null);
            }
            var servers = new List <RabbitServerSetting>();

            foreach (var item in serverSetting.TypeName.Split(';'))
            {
                var server = serverSetting.Clone();
                server.TypeName = item;
                servers.Add(server);
                if (server.TypeName.Equals(RabbitServerSetting.Public_Server_Key))
                {
                    DefaultServer = server;
                }
            }
            return(servers);
        }
Esempio n. 3
0
        public static IConnection CreateNewConnection(RabbitServerSetting setting)
        {
            var factory = new ConnectionFactory()
            {
                HostName                 = setting.Host,
                UserName                 = setting.UserName,
                Password                 = setting.Password,
                RequestedHeartbeat       = setting.RequestedHeartbeat,
                AutomaticRecoveryEnabled = true
            };

            if (!string.IsNullOrWhiteSpace(setting.VirtualHost))
            {
                factory.VirtualHost = setting.VirtualHost;
            }
            if (setting.Port > 0)
            {
                factory.Port = setting.Port;
            }
            return(factory.CreateConnection());
        }
Esempio n. 4
0
        private void DecodeServers()
        {
            _servers = new List <RabbitServerSetting>();
            foreach (var item in Servers)
            {
                if (!item.TypeName.Contains(";"))
                {
                    if (item.TypeName.Equals(RabbitServerSetting.Public_Server_Key))
                    {
                        DefaultServer = item;
                    }
                    _servers.Add(item);
                    continue;
                }

                var decodeServers = DecodeServer(item);
                if (decodeServers == null || decodeServers.Count == 0)
                {
                    continue;
                }
                _servers.AddRange(decodeServers);
            }
        }