public IServiceBus CreateServiceBus(MassTransitConnectionDescriptor connectionDescriptor, IQueueStrategy queueStrategy, IReadOnlyList<Action<SubscriptionBusServiceConfigurator>> subscriptions)
        {
            return ServiceBusFactory.New(bus =>
            {
                var receiveUri = new Uri(connectionDescriptor.Host, queueStrategy.GetQueueName());

                bus.UseRabbitMq(r =>
                {
                    r.ConfigureHost(receiveUri, h =>
                    {
                        h.SetUsername(connectionDescriptor.UserName);
                        h.SetPassword(connectionDescriptor.Password);
                    });
                });

                bus.ReceiveFrom(receiveUri);
                bus.UseJsonSerializer();
                bus.SetConcurrentConsumerLimit(_concurrencyLimit);

                foreach (var subscription in subscriptions)
                    bus.Subscribe(subscription);

                bus.Validate();
            });
        }
 public RabbitMqServiceBusFactory(MassTransitConnectionDescriptor connectionDescriptor, RabbitMqOptions rabbitMqOptions)
 {
     if (connectionDescriptor == null)
         throw new ArgumentNullException(nameof(connectionDescriptor));
     if (rabbitMqOptions == null)
         throw new ArgumentNullException(nameof(rabbitMqOptions));
     _connectionDescriptor = connectionDescriptor;
     _rabbitMqOptions = rabbitMqOptions;
 }
Beispiel #3
0
 public MassTransitBusEngine(MassTransitConnectionDescriptor connectionDescriptor, MassTransitOptions options)
 {
     if (connectionDescriptor == null)
     {
         throw new ArgumentNullException(nameof(connectionDescriptor));
     }
     if (options == null)
     {
         throw new ArgumentNullException(nameof(options));
     }
     _connectionDescriptor = connectionDescriptor;
     _options = options;
     _logger  = _options.LoggerFactory.CreateLogger(nameof(MassTransitBusEngine));
 }
        public void Initialize()
        {
            fixture = new Fixture();

            commandQueueName = fixture.Create<string>();
            eventQueueName = fixture.Create<string>();

            mockLoggerFactory = new Mock<ILoggerFactory>();
            mockLogger = new Mock<ILogger>();

            mockLoggerFactory.Setup(p => p.CreateLogger(It.IsAny<string>())).Returns(() => mockLogger.Object);

            mockContextManager = new Mock<IContextManager>();

            mockCommandErrorStrategy = new Mock<IErrorStrategy>();
            mockCommandQueueStrategy = new Mock<IQueueStrategy>();
            mockCommandServiceBus = new Mock<IServiceBus>();

            mockEventErrorStrategy = new Mock<IErrorStrategy>();
            mockEventQueueStrategy = new Mock<IQueueStrategy>();
            mockEventServiceBus = new Mock<IServiceBus>();
            
            mockServiceBusFactory = new Mock<IServiceBusFactory>();
            mockServiceBusFactory.Setup(p => p.CreateServiceBus(It.IsAny<MassTransitConnectionDescriptor>(), mockCommandQueueStrategy.Object, It.IsAny<IReadOnlyList<Action<SubscriptionBusServiceConfigurator>>>())).Returns(mockCommandServiceBus.Object);
            mockServiceBusFactory.Setup(p => p.CreateServiceBus(It.IsAny<MassTransitConnectionDescriptor>(), mockEventQueueStrategy.Object, It.IsAny<IReadOnlyList<Action<SubscriptionBusServiceConfigurator>>>())).Returns(mockEventServiceBus.Object);

            mockCommandQueueStrategy.Setup(p => p.GetQueueName()).Returns(commandQueueName);
            mockEventQueueStrategy.Setup(p => p.GetQueueName()).Returns(eventQueueName);

            options = new MassTransitOptions
            {
                LoggerFactory = mockLoggerFactory.Object,
                CommandErrorStrategy = mockCommandErrorStrategy.Object,
                CommandQueueStrategy = mockCommandQueueStrategy.Object,
                EventErrorStrategy = mockEventErrorStrategy.Object,
                EventQueueStrategy = mockEventQueueStrategy.Object,
                ServiceBusFactory = mockServiceBusFactory.Object,
                ContextManager = mockContextManager.Object
            };

            var host = fixture.Create<Uri>();
            var userName = fixture.Create<string>();
            var password = fixture.Create<string>();

            connectionDescriptor = new MassTransitConnectionDescriptor(host, userName, password);
        }
        public IServiceBus CreateServiceBus(MassTransitConnectionDescriptor connectionDescriptor, IQueueStrategy queueStrategy, IReadOnlyList<Action<SubscriptionBusServiceConfigurator>> subscriptions)
        {
            UriBuilder builder = new UriBuilder(connectionDescriptor.Host) {Scheme = "loopback"};

            return ServiceBusFactory.New(bus =>
            {
                var receiveUri = new Uri(builder.Uri, queueStrategy.GetQueueName());

                bus.ReceiveFrom(receiveUri);
                bus.UseJsonSerializer();

                foreach (var subscription in subscriptions)
                    bus.Subscribe(subscription);

                bus.Validate();

            });
        }
Beispiel #6
0
 public MassTransitBusEngine(MassTransitConnectionDescriptor connectionDescriptor) : this(connectionDescriptor, new MassTransitOptions())
 {
 }