Beispiel #1
0
 private IConsumerErrorStrategy CreateDefaultConsumerErrorStrategy()
 {
     var fallbackStrategy = new DefaultConsumerErrorStrategy(_connectionFactory, _serializer, _logger);
     return new RetryConsumerErrorStrategy(_connectionFactory, fallbackStrategy, _logger);
 }
Beispiel #2
0
        /// <summary>
        /// Creates a new instance of RabbitBus
        /// </summary>
        /// <param name="hostName">
        /// The RabbitMQ broker.
        /// </param>
        /// <param name="virtualHost">
        /// The RabbitMQ virtualHost.
        /// </param>
        /// <param name="username">
        /// The username to use to connect to the RabbitMQ broker.
        /// </param>
        /// <param name="password">
        /// The password to use to connect to the RabbitMQ broker.
        /// </param>
        /// <param name="logger">
        /// The logger to use.
        /// </param>
        /// <returns>
        /// A new RabbitBus instance.
        /// </returns>
        public static IBus CreateBus(string hostName, string virtualHost, string username, string password, IEasyNetQLogger logger)
        {
            if(hostName == null)
            {
                throw new ArgumentNullException("hostName");
            }
            if(virtualHost == null)
            {
                throw new ArgumentNullException("virtualHost");
            }
            if(username == null)
            {
                throw new ArgumentNullException("username");
            }
            if(password == null)
            {
                throw new ArgumentNullException("password");
            }
            if(logger == null)
            {
                throw new ArgumentNullException("logger");
            }

            var connectionFactory = new ConnectionFactoryWrapper(new ConnectionFactory
            {
                HostName = hostName,
                VirtualHost = virtualHost,
                UserName = username,
                Password = password
            });

            var serializer = new JsonSerializer();

            var consumerErrorStrategy = new DefaultConsumerErrorStrategy(connectionFactory, serializer, logger);

            var conventions = new Conventions();

            var advancedBus = new RabbitAdvancedBus(
                connectionFactory,
                TypeNameSerializer.Serialize,
                serializer,
                new QueueingConsumerFactory(logger, consumerErrorStrategy),
                logger,
                CorrelationIdGenerator.GetCorrelationId,
                conventions);

            return new RabbitBus(
                TypeNameSerializer.Serialize,
                logger,
                conventions,
                advancedBus);
        }
Beispiel #3
0
        /// <summary>
        /// Creates a new instance of RabbitBus
        /// </summary>
        /// <param name="hostName">
        /// The RabbitMQ broker.
        /// </param>
        /// <param name="hostPort">
        /// The RabbitMQ broker port.
        /// </param>
        /// <param name="virtualHost">
        /// The RabbitMQ virtualHost.
        /// </param>
        /// <param name="username">
        /// The username to use to connect to the RabbitMQ broker.
        /// </param>
        /// <param name="password">
        /// The password to use to connect to the RabbitMQ broker.
        /// </param>
        /// <param name="logger">
        /// The logger to use.
        /// </param>
        /// <returns>
        /// A new RabbitBus instance.
        /// </returns>
        public static IBus CreateBus(string hostName, string hostPort, string virtualHost, string username, string password, IEasyNetQLogger logger)
        {
            if(hostName == null)
            {
                throw new ArgumentNullException("hostName");
            }
            if (hostPort == null)
            {
                throw new ArgumentNullException("hostPort");
            }
            if(virtualHost == null)
            {
                throw new ArgumentNullException("virtualHost");
            }
            if(username == null)
            {
                throw new ArgumentNullException("username");
            }
            if(password == null)
            {
                throw new ArgumentNullException("password");
            }
            if(logger == null)
            {
                throw new ArgumentNullException("logger");
            }

            var port = 0;
            if (!Int32.TryParse(hostPort, out port))
            {
                throw new FormatException("hostPort must be a valid 32-bit interger.");
            }

            var connectionFactory = new ConnectionFactoryWrapper(new ConnectionFactory
            {
                HostName = hostName,
                Port = port,
                VirtualHost = virtualHost,
                UserName = username,
                Password = password
            });

            var serializer = new JsonSerializer();

            var consumerErrorStrategy = new DefaultConsumerErrorStrategy(connectionFactory, serializer, logger);

            var conventions = new Conventions();

            return new RabbitBus(
                TypeNameSerializer.Serialize,
                serializer,
                new QueueingConsumerFactory(logger, consumerErrorStrategy),
                connectionFactory,
                logger,
                CorrelationIdGenerator.GetCorrelationId,
                conventions);
        }