public void Constructor_IConnectionFactoryNullInput_ArgumentNullException()
        {
            //Arrange
            Rabbit.IConnectionFactory connectionFactory = null;

            //Act
            var action = new Action(() => new RabbitMQConnectionFactory(connectionFactory));

            //Assert
            Assert.Throws <ArgumentNullException>(nameof(connectionFactory), action);
        }
Exemple #2
0
        public ConnectionFactoryWrapper(string connectionString, IConnectionStringParser Parser)
        {
            ConnectionString = connectionString;

            Configuration = Parser.Parse(ConnectionString);  //new ConnectionConfiguration();


            var connectionFactory = new ConnectionFactory
            {
                UseBackgroundThreadsForIO = Configuration.UseBackgroundThreads,
                AutomaticRecoveryEnabled  = false,
                TopologyRecoveryEnabled   = false
            };

            if (Configuration.AMQPConnectionString != null)
            {
                connectionFactory.Uri = Configuration.AMQPConnectionString;
            }

            connectionFactory.HostName = Configuration.Host;

            // if (Configuration.VirtualHost == "/")
            connectionFactory.VirtualHost = Configuration.VirtualHost;

            //if (Configuration.UserName == "guest")
            connectionFactory.UserName = Configuration.UserName;

            // if (Configuration.Password == "guest")
            connectionFactory.Password = Configuration.Password;

            // if (Configuration.Port == -1)
            connectionFactory.Port = Configuration.Port;

            if (Configuration.Ssl.Enabled)
            {
                connectionFactory.Ssl = Configuration.Ssl;
            }

            //Prefer SSL configurations per each host but fall back to ConnectionConfiguration's SSL configuration for backwards compatibility
            //else if (Configuration.Ssl.Enabled)
            //  connectionFactory.Ssl = Configuration.Ssl;

            connectionFactory.RequestedHeartbeat = Configuration.RequestedHeartbeat;
            connectionFactory.ClientProperties   = Configuration.ClientProperties;
            connectionFactory.AuthMechanisms     = Configuration.AuthMechanisms;
            _connectionFactory = connectionFactory;
        }
        protected AbstractConnectionFactory(
            RabbitMQ.Client.IConnectionFactory rabbitConnectionFactory,
            AbstractConnectionFactory publisherConnectionFactory,
            ILogger logger = null)
        {
            if (rabbitConnectionFactory == null)
            {
                throw new ArgumentNullException(nameof(rabbitConnectionFactory));
            }

            _rabbitConnectionFactory   = rabbitConnectionFactory;
            PublisherConnectionFactory = publisherConnectionFactory;
            _logger          = logger;
            RecoveryListener = new DefaultRecoveryListener(logger);
            BlockedListener  = new DefaultBlockedListener(logger);
            Name             = GetType().Name + "@" + GetHashCode();
        }
        static void Main(string[] args)
        {
            if (doMongoInsert)
            {
                Console.WriteLine($"Listening for events from rabbit :)");

                _connectionFactory = new ConnectionFactory {
                    HostName = "localhost"
                };
                _connection = _connectionFactory.CreateConnection();

                _mongoSetting    = new MongoSetting();
                _mongoRepository = new MongoRepository(_mongoSetting);

                var sub = new Subscriber(_connection, _mongoRepository);
            }

            Console.WriteLine($"Mode to process set to : {doMongoInsert}");
            Console.Read();
        }
        protected AbstractConnectionFactory(
            RabbitMQ.Client.IConnectionFactory rabbitConnectionFactory,
            AbstractConnectionFactory publisherConnectionFactory,
            ILoggerFactory loggerFactory = null)
        {
            if (rabbitConnectionFactory == null)
            {
                throw new ArgumentNullException(nameof(rabbitConnectionFactory));
            }

            _loggerFactory             = loggerFactory;
            _logger                    = _loggerFactory?.CreateLogger(GetType());
            _rabbitConnectionFactory   = rabbitConnectionFactory;
            _connectionListener        = new CompositeConnectionListener(_loggerFactory?.CreateLogger <CompositeConnectionListener>());
            _channelListener           = new CompositeChannelListener(_loggerFactory?.CreateLogger <CompositeConnectionListener>());
            PublisherConnectionFactory = publisherConnectionFactory;
            RecoveryListener           = new DefaultRecoveryListener(_loggerFactory?.CreateLogger <DefaultRecoveryListener>());
            BlockedListener            = new DefaultBlockedListener(_loggerFactory?.CreateLogger <DefaultBlockedListener>());
            ServiceName                = GetType().Name + "@" + GetHashCode();
        }
        public RabbitMQConnectionFactory(string connectionString)
        {
            if (string.IsNullOrWhiteSpace(connectionString))
            {
                throw new ArgumentNullException(nameof(connectionString));
            }

            if (Uri.TryCreate(connectionString, UriKind.Absolute, out var connectionUri))
            {
                if (!connectionUri.Scheme.Equals("amqp"))
                {
                    throw new ArgumentException("The specified connection URI has the wrong scheme.", nameof(connectionString));
                }
            }
            else
            {
                throw new ArgumentException("The specified connection string is not a valid URI.", nameof(connectionString));
            }

            _connectionFactory = new Rabbit.ConnectionFactory
            {
                Uri = connectionUri
            };
        }
        protected override AbstractConnectionFactory CreateConnectionFactory(RC.IConnectionFactory mockConnectionFactory, ILoggerFactory loggerFactory)
        {
            var scf = new SingleConnectionFactory(mockConnectionFactory, loggerFactory);

            return(scf);
        }
 protected abstract AbstractConnectionFactory CreateConnectionFactory(R.IConnectionFactory mockConnectionFactory, ILogger logger);
Exemple #9
0
 public SingleConnectionFactory(RabbitMQ.Client.IConnectionFactory rabbitConnectionFactory, ILoggerFactory loggerFactory = null)
     : base(rabbitConnectionFactory, loggerFactory)
 {
     ServiceName = DEFAULT_SERVICE_NAME;
 }
 protected AbstractConnectionFactory(
     RabbitMQ.Client.IConnectionFactory rabbitConnectionFactory,
     ILogger logger = null)
     : this(rabbitConnectionFactory, null, logger)
 {
 }
 public RabbitMQConnectionFactory(Rabbit.IConnectionFactory connectionFactory)
 {
     _connectionFactory = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory));
 }
 public SingleConnectionFactory(RabbitMQ.Client.IConnectionFactory rabbitConnectionFactory)
     : base(rabbitConnectionFactory)
 {
 }