Exemple #1
0
        public void RabbitMQClientEventBusConfiguration_Ctor_TestParams()
        {
            Assert.Throws <ArgumentException>(() => new RabbitMQClientBusConfiguration("", "", "", ""));
            Assert.Throws <ArgumentException>(() => new RabbitMQClientBusConfiguration("", "testserver:a:a:a:a", "", ""));
            Assert.Throws <ArgumentException>(() => new RabbitMQClientBusConfiguration("test", "testserver:a:a:a:a", "", ""));
            Assert.Throws <ArgumentException>(() => new RabbitMQClientBusConfiguration("test", "testserver:a", "", ""));

            var c = new RabbitMQClientBusConfiguration("test", "testserver:12345", "abc", "abc");

            c.Host.Should().Be("testserver");
            c.Port.Should().Be(12345);
            c.UserName.Should().Be("abc");
            c.Password.Should().Be("abc");
            c.Emiter.Should().Be("test");

            var c2 = new RabbitMQClientBusConfiguration("test", "testserver", "abc", "abc");

            c2.Host.Should().Be("testserver");
            c2.Port.Should().NotHaveValue();
            c2.UserName.Should().Be("abc");
            c2.Password.Should().Be("abc");
            c.Emiter.Should().Be("test");
        }
Exemple #2
0
        /// <summary>
        /// Use RabbitMQ client to publish events and commands to a rabbitMQ instance.
        /// </summary>
        /// <param name="bootstrapper">Bootstrapper instance.</param>
        /// <param name="configuration">Configuration to use RabbitMQ.</param>
        /// <returns>Bootstrapper instance.</returns>
        public static Bootstrapper UseRabbitMQClientBus(this Bootstrapper bootstrapper, RabbitMQClientBusConfiguration configuration = null)
        {
            var service = RabbitMQBootstrappService.Instance;

            service.BootstrappAction += (ctx) =>
            {
                RabbitMQClient.s_configuration = configuration ?? RabbitMQClientBusConfiguration.Default;
                if (ctx.IsServiceRegistered(BootstrapperServiceType.IoC))
                {
                    bootstrapper.AddIoCRegistrations(
                        new TypeRegistration(typeof(RabbitMQEventBus), typeof(IDomainEventBus)),
                        new InstanceTypeRegistration(configuration ?? RabbitMQClientBusConfiguration.Default,
                                                     typeof(RabbitMQClientBusConfiguration), typeof(AbstractBaseConfiguration)));
                    RegisterRabbitClientWithinContainer(bootstrapper);
                }
            };

            if (!bootstrapper.RegisteredServices.Any(s => s == service))
            {
                bootstrapper.AddService(service);
            }
            return(bootstrapper);
        }