Exemplo n.º 1
0
        public static IBus CreateBus()
        {
            var connectionFactory = new InMemoryConnectionFactory();

            var serializer = new JsonSerializer();
            var logger = new ConsoleLogger();
            var conventions = new Conventions();
            var consumerErrorStrategy = new DefaultConsumerErrorStrategy(connectionFactory, serializer, logger, conventions);

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

            return new RabbitBus(
                TypeNameSerializer.Serialize,
                logger,
                conventions,
                advancedBus);
        }
Exemplo n.º 2
0
        public IBus CreateBusWithMockAmqpClient()
        {
            Logger = Logger ?? new ConsoleLogger();
            Model = Model ?? new MockModel();
            Connection = Connection ?? new MockConnection(Model);
            ConnectionFactory = ConnectionFactory ?? new MockConnectionFactory(Connection);
            Serializer = Serializer ?? new JsonSerializer();
            Conventions = Conventions ?? new Conventions();
            ConsumerErrorStrategy = ConsumerErrorStrategy ?? new DefaultConsumerErrorStrategy(ConnectionFactory, Serializer, Logger, Conventions);
            ConsumerFactory = ConsumerFactory ?? new QueueingConsumerFactory(Logger, ConsumerErrorStrategy);
            GetCorrelationId = GetCorrelationId ?? CorrelationIdGenerator.GetCorrelationId;

            var advancedBus = new RabbitAdvancedBus(
                new ConnectionConfiguration(),
                ConnectionFactory,
                TypeNameSerializer.Serialize,
                Serializer,
                ConsumerFactory,
                Logger,
                GetCorrelationId,
                Conventions);

            return new RabbitBus(
                TypeNameSerializer.Serialize,
                Logger,
                Conventions,
                advancedBus);
        }
Exemplo n.º 3
0
        public static IBus CreateBus()
        {
            var connectionFactory = new InMemoryConnectionFactory();

            var serializer            = new JsonSerializer();
            var logger                = new ConsoleLogger();
            var conventions           = new Conventions();
            var consumerErrorStrategy = new DefaultConsumerErrorStrategy(connectionFactory, serializer, logger, conventions);


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

            return(new RabbitBus(
                       TypeNameSerializer.Serialize,
                       logger,
                       conventions,
                       advancedBus));
        }
Exemplo n.º 4
0
        public IBus CreateBusWithMockAmqpClient()
        {
            Logger                = Logger ?? new ConsoleLogger();
            Model                 = Model ?? new MockModel();
            Connection            = Connection ?? new MockConnection(Model);
            ConnectionFactory     = ConnectionFactory ?? new MockConnectionFactory(Connection);
            Serializer            = Serializer ?? new JsonSerializer();
            Conventions           = Conventions ?? new Conventions();
            ConsumerErrorStrategy = ConsumerErrorStrategy ?? new DefaultConsumerErrorStrategy(ConnectionFactory, Serializer, Logger, Conventions);
            ConsumerFactory       = ConsumerFactory ?? new QueueingConsumerFactory(Logger, ConsumerErrorStrategy);
            GetCorrelationId      = GetCorrelationId ?? CorrelationIdGenerator.GetCorrelationId;

            var advancedBus = new RabbitAdvancedBus(
                new ConnectionConfiguration(),
                ConnectionFactory,
                TypeNameSerializer.Serialize,
                Serializer,
                ConsumerFactory,
                Logger,
                GetCorrelationId,
                Conventions);

            return(new RabbitBus(
                       TypeNameSerializer.Serialize,
                       Logger,
                       Conventions,
                       advancedBus));
        }
Exemplo n.º 5
0
        public static IAdvancedBus CreateAdvancedBus()
        {
            ConnectionFactory connectFactory = new ConnectionFactory();

            connectFactory.HostName    = "127.0.0.1";
            connectFactory.VirtualHost = "OrderQueue";
            connectFactory.UserName    = "******";
            connectFactory.Password    = "******";


            RabbitAdvancedBus bus = new RabbitAdvancedBus(connectFactory);
        }
        public AdvancedBusEventHandlersTests()
        {
            advancedBusEventHandlers = new AdvancedBusEventHandlers(
                connected: (s, e) => connectedCalled       = true,
                disconnected: (s, e) => disconnectedCalled = true,
                blocked: (s, e) =>
            {
                blockedCalled = true;
                connectionBlockedEventArgs = e;
            },
                unblocked: (s, e) => unBlockedCalled = true,
                messageReturned: (s, e) =>
            {
                messageReturnedCalled    = true;
                messageReturnedEventArgs = e;
            });

            var connectionFactory = Substitute.For <IConnectionFactory>();

            connectionFactory.Succeeded.Returns(true);
            connectionFactory.CreateConnection().Returns(Substitute.For <IConnection>());
            connectionFactory.CurrentHost.Returns(new HostConfiguration());
            connectionFactory.Configuration.Returns(new ConnectionConfiguration());

            eventBus = new EventBus();

            var logger = Substitute.For <IEasyNetQLogger>();
            var persistentConnectionFactory = new PersistentConnectionFactory(logger, connectionFactory, eventBus);

            var advancedBus = new RabbitAdvancedBus(
                connectionFactory,
                Substitute.For <IConsumerFactory>(),
                logger,
                Substitute.For <IClientCommandDispatcherFactory>(),
                Substitute.For <IPublishConfirmationListener>(),
                eventBus,
                Substitute.For <IHandlerCollectionFactory>(),
                Substitute.For <IContainer>(),
                Substitute.For <ConnectionConfiguration>(),
                Substitute.For <IProduceConsumeInterceptor>(),
                Substitute.For <IMessageSerializationStrategy>(),
                Substitute.For <IConventions>(),
                advancedBusEventHandlers,
                persistentConnectionFactory);
        }
        public void SetUp()
        {
            advancedBusEventHandlers = new AdvancedBusEventHandlers(
                connected: (s, e) => connectedCalled       = true,
                disconnected: (s, e) => disconnectedCalled = true,
                blocked: (s, e) =>
            {
                blockedCalled = true;
                connectionBlockedEventArgs = e;
            },
                unblocked: (s, e) => unBlockedCalled = true,
                messageReturned: (s, e) =>
            {
                messageReturnedCalled    = true;
                messageReturnedEventArgs = e;
            });

            var connectionFactory = MockRepository.GenerateStub <IConnectionFactory>();

            connectionFactory.Stub(x => x.Succeeded).Return(true);
            connectionFactory.Stub(x => x.CreateConnection()).Return(MockRepository.GenerateStub <IConnection>());
            connectionFactory.Stub(x => x.CurrentHost).Return(new HostConfiguration());
            connectionFactory.Stub(x => x.Configuration).Return(new ConnectionConfiguration());

            eventBus = new EventBus();

            var logger = MockRepository.GenerateStub <IEasyNetQLogger>();
            var persistentConnectionFactory = new PersistentConnectionFactory(logger, connectionFactory, eventBus);

            var advancedBus = new RabbitAdvancedBus(
                connectionFactory,
                MockRepository.GenerateStub <IConsumerFactory>(),
                logger,
                MockRepository.GenerateStub <IClientCommandDispatcherFactory>(),
                MockRepository.GenerateStub <IPublishConfirmationListener>(),
                eventBus,
                MockRepository.GenerateStub <IHandlerCollectionFactory>(),
                MockRepository.GenerateStub <IContainer>(),
                MockRepository.GenerateStub <ConnectionConfiguration>(),
                MockRepository.GenerateStub <IProduceConsumeInterceptor>(),
                MockRepository.GenerateStub <IMessageSerializationStrategy>(),
                MockRepository.GenerateStub <IConventions>(),
                advancedBusEventHandlers,
                persistentConnectionFactory);
        }
        public AdvancedBusEventHandlersTests()
        {
            var advancedBusEventHandlers = new AdvancedBusEventHandlers(
                (s, e) =>
            {
                connectedCalled    = true;
                connectedEventArgs = e;
            },
                (s, e) =>
            {
                disconnectedCalled    = true;
                disconnectedEventArgs = e;
            },
                (s, e) =>
            {
                blockedCalled    = true;
                blockedEventArgs = e;
            },
                (s, e) => unBlockedCalled = true,
                (s, e) =>
            {
                messageReturnedCalled    = true;
                messageReturnedEventArgs = e;
            }
                );

            eventBus = new EventBus();

            advancedBus = new RabbitAdvancedBus(
                Substitute.For <IPersistentConnection>(),
                Substitute.For <IConsumerFactory>(),
                Substitute.For <IClientCommandDispatcher>(),
                Substitute.For <IPublishConfirmationListener>(),
                eventBus,
                Substitute.For <IHandlerCollectionFactory>(),
                Substitute.For <IServiceResolver>(),
                Substitute.For <ConnectionConfiguration>(),
                Substitute.For <IProduceConsumeInterceptor>(),
                Substitute.For <IMessageSerializationStrategy>(),
                Substitute.For <IConventions>(),
                Substitute.For <IPullingConsumerFactory>(),
                advancedBusEventHandlers
                );
        }
Exemplo n.º 9
0
        private void CreateBus(Conventions conventions, IModel model)
        {
            var advancedBus = new RabbitAdvancedBus(
                new ConnectionConfiguration(),
                new MockConnectionFactory(new MockConnection(model)),
                TypeNameSerializer.Serialize,
                new JsonSerializer(),
                new MockConsumerFactory(),
                new MockLogger(),
                CorrelationIdGenerator.GetCorrelationId,
                conventions
                );

            bus = new RabbitBus(
                x => TypeNameSerializer.Serialize(x.GetType()),
                new MockLogger(),
                conventions,
                advancedBus
                );
        }
Exemplo n.º 10
0
        private void CreateBus(Conventions conventions, IModel model)
        {
            var advancedBus = new RabbitAdvancedBus(
                new ConnectionConfiguration(),
                new MockConnectionFactory(new MockConnection(model)),
                TypeNameSerializer.Serialize,
                new JsonSerializer(),
                new MockConsumerFactory(),
                new MockLogger(),
                CorrelationIdGenerator.GetCorrelationId,
                conventions
                );

            bus = new RabbitBus(
                x => TypeNameSerializer.Serialize(x.GetType()),
                new MockLogger(),
                conventions,
                advancedBus
                );
        }
        public void SetUp()
        {
            advancedBusEventHandlers = new AdvancedBusEventHandlers(
                connected: (s, e) => connectedCalled = true,
                disconnected: (s, e) => disconnectedCalled = true,
                blocked: (s, e) =>
                {
                    blockedCalled = true;
                    connectionBlockedEventArgs = e;
                },
                unblocked: (s, e) => unBlockedCalled = true,
                messageReturned: (s, e) =>
                {
                    messageReturnedCalled = true;
                    messageReturnedEventArgs = e;
                });

            var connectionFactory = MockRepository.GenerateStub<IConnectionFactory>();
            connectionFactory.Stub(x => x.Succeeded).Return(true);
            connectionFactory.Stub(x => x.CreateConnection()).Return(MockRepository.GenerateStub<IConnection>());
            connectionFactory.Stub(x => x.CurrentHost).Return(new HostConfiguration());
            connectionFactory.Stub(x => x.Configuration).Return(new ConnectionConfiguration());

            eventBus = new EventBus();

            var advancedBus = new RabbitAdvancedBus(
                connectionFactory,
                MockRepository.GenerateStub<IConsumerFactory>(),
                MockRepository.GenerateStub<IEasyNetQLogger>(),
                MockRepository.GenerateStub<IClientCommandDispatcherFactory>(),
                MockRepository.GenerateStub<IPublishConfirmationListener>(),
                eventBus,
                MockRepository.GenerateStub<IHandlerCollectionFactory>(),
                MockRepository.GenerateStub<IContainer>(),
                MockRepository.GenerateStub<ConnectionConfiguration>(),
                MockRepository.GenerateStub<IProduceConsumeInterceptor>(),
                MockRepository.GenerateStub<IMessageSerializationStrategy>(),
                MockRepository.GenerateStub<IConventions>(),
                advancedBusEventHandlers);
        }
Exemplo n.º 12
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);
        }