示例#1
0
        private static IConnection GetRabbitMqConnection(MerQureConnection rabbitMqConnection)
        {
            ConnectionFactory connectionFactory = new ConnectionFactory
            {
                AutomaticRecoveryEnabled = rabbitMqConnection.AutomaticRecoveryEnabled,
                TopologyRecoveryEnabled  = rabbitMqConnection.TopologyRecoveryEnabled,
                ClientProvidedName       = rabbitMqConnection.FriendlyName,
                RequestedChannelMax      = rabbitMqConnection.RequestedChannelMax
            };

            if (rabbitMqConnection.ConnectionCluster == null && string.IsNullOrEmpty(rabbitMqConnection.ConnectionString))
            {
                throw new ArgumentException("MerQureConnection should provide a ConnectionCluster or ConnectionString");
            }

            if (rabbitMqConnection.ConnectionCluster != null && !string.IsNullOrEmpty(rabbitMqConnection.ConnectionString))
            {
                throw new ArgumentException("MerQureConnection could not provide a ConnectionCluster and ConnectionString at the same time");
            }

            if (rabbitMqConnection.ConnectionCluster is null)
            {
                connectionFactory.Uri = new Uri(rabbitMqConnection.ConnectionString);
                return(connectionFactory.CreateConnection());
            }
            InitCluster(connectionFactory, rabbitMqConnection.ConnectionCluster);
            return(connectionFactory.CreateConnection(rabbitMqConnection.ConnectionCluster.Nodes));
        }
示例#2
0
 public SharedConnection(IOptions <MerQureConfiguration> options)
 {
     _config            = options.Value.Connection;
     _currentConnection = new Lazy <IConnection>(() => GetRabbitMqConnection(_config));
 }