Inheritance: IConnectionFactory
        public void SetUp()
        {
            routingTopology = new ConventionalRoutingTopology();
            receivedMessages = new BlockingCollection<TransportMessage>();

            var config = new ConnectionConfiguration();
            config.ParseHosts("localhost:5672");

            var selectionStrategy = new DefaultClusterHostSelectionStrategy<ConnectionFactoryInfo>();
            var connectionFactory = new ConnectionFactoryWrapper(config, selectionStrategy);
            connectionManager = new RabbitMqConnectionManager(connectionFactory, config);

            unitOfWork = new RabbitMqUnitOfWork
            {
                ConnectionManager = connectionManager,
                UsePublisherConfirms = true,
                MaxWaitTimeForConfirms = TimeSpan.FromSeconds(10)
            };

            sender = new RabbitMqMessageSender
            {
                UnitOfWork = unitOfWork,
                RoutingTopology = routingTopology
            };


            dequeueStrategy = new RabbitMqDequeueStrategy
            {
                ConnectionManager = connectionManager,
                PurgeOnStartup = true
            };

            MakeSureQueueAndExchangeExists(ReceiverQueue);


            MessagePublisher = new RabbitMqMessagePublisher
            {
                UnitOfWork = unitOfWork,
                RoutingTopology = routingTopology
            };
            subscriptionManager = new RabbitMqSubscriptionManager
            {
                ConnectionManager = connectionManager,
                EndpointQueueName = ReceiverQueue,
                RoutingTopology = routingTopology
            };

            dequeueStrategy.Init(Address.Parse(ReceiverQueue), TransactionSettings.Default, m =>
            {
                receivedMessages.Add(m);
                return true;
            }, (s, exception) => { });

            dequeueStrategy.Start(MaximumConcurrency);
        }
Exemple #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, ushort prefetchCount = 1000)
        {
            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);

            return(new RabbitBus(
                       TypeNameSerializer.Serialize,
                       serializer,
                       new QueueingConsumerFactory(logger, consumerErrorStrategy),
                       connectionFactory,
                       logger,
                       CorrelationIdGenerator.GetCorrelationId,
                       null,
                       prefetchCount));
        }
Exemple #3
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);
        }
        static RabbitMqConnectionManager SetupRabbitMqConnectionManager(string connectionString) {
            var config = new ConnectionStringParser().Parse(connectionString);
//            config.OverrideClientProperties();
            var selectionStrategy = new DefaultClusterHostSelectionStrategy<ConnectionFactoryInfo>();
            var connectionFactory = new ConnectionFactoryWrapper(config, selectionStrategy);
            var newConnectionManager = new RabbitMqConnectionManager(connectionFactory, config);
            return newConnectionManager;
        }
Exemple #5
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);
        }