Пример #1
0
            public void should_validate()
            {
                const string producerConfig =
                    @"<endpoints>
                            <endpoint name=""producer"" connectionString=""amqp://localhost/integration"">
                                <outgoing>
                                    <route key=""a"" label=""msg.a"" />
                                </outgoing>
                            </endpoint>
                        </endpoints>";

                const string consumerConfig =
                    @"<endpoints>
                            <endpoint name=""consumer"" connectionString=""amqp://localhost/integration"">
                                <incoming>
                                    <on key=""a"" label=""msg.a"" react=""BooHandler"" type=""BooMessage"" validate=""BooValidator"" />
                                </incoming>
                            </endpoint>
                        </endpoints>";

                var handler = new ConcreteHandlerOf <BooMessage>();

                IKernel kernel = new StandardKernel();

                kernel.Bind <IConsumerOf <BooMessage> >()
                .ToConstant(handler)
                .InSingletonScope()
                .Named("BooHandler");
                kernel.Bind <IMessageValidatorOf <BooMessage> >()
                .To <BooPayloadValidator>()
                .InSingletonScope()
                .Named("BooValidator");

                DependencyResolverFunc dependencyResolver = (name, type) => kernel.Get(type, name);

                this.StartBus(
                    "consumer",
                    cfg =>
                {
                    var section = new XmlEndpointsSection(consumerConfig);
                    new AppConfigConfigurator(section, dependencyResolver).Configure("consumer", cfg);
                });

                IBus producer = this.StartBus(
                    "producer",
                    cfg =>
                {
                    var section = new XmlEndpointsSection(producerConfig);
                    new AppConfigConfigurator(section, dependencyResolver).Configure("producer", cfg);
                });

                producer.Emit("msg.a", new { Num = 13 });

                handler.Received.WaitOne(3.Seconds())
                .Should()
                .BeFalse();
            }
Пример #2
0
            public void should_receive()
            {
                string producerConfig = string.Format(
                    @"<endpoints>
                            <endpoint name=""producer"" connectionString=""{0}{1}"">
                                <outgoing>
                                    <route key=""a"" label=""msg.a"" />
                                </outgoing>
                            </endpoint>
                        </endpoints>",
                    this.AmqpConnection,
                    this.VhostName);

                string consumerConfig = string.Format(
                    @"<endpoints>
                            <endpoint name=""consumer"" connectionString=""{0}{1}"">
                                <incoming>
                                    <on key=""a"" label=""msg.a"" react=""DynamicHandler"" />
                                </incoming>
                            </endpoint>
                        </endpoints>",
                    this.AmqpConnection,
                    this.VhostName);

                var handler = new ConcreteHandlerOf <ExpandoObject>();

                IKernel kernel = new StandardKernel();

                kernel.Bind <IConsumerOf <ExpandoObject> >().
                ToConstant(handler).
                Named("DynamicHandler");

                DependencyResolverFunc dependencyResolver = (name, type) => kernel.Get(type, name);

                this.StartBus(
                    "consumer",
                    cfg =>
                {
                    var section = new XmlEndpointsSection(consumerConfig);
                    new AppConfigConfigurator(section, dependencyResolver).Configure("consumer", cfg);
                });

                IBus producer = this.StartBus(
                    "producer",
                    cfg =>
                {
                    var section = new XmlEndpointsSection(producerConfig);
                    new AppConfigConfigurator(section, dependencyResolver).Configure("producer", cfg);
                });

                producer.Emit("msg.a", new { This = "That" });

                handler.Received.WaitOne(5.Seconds()).
                Should().
                BeTrue();
            }
Пример #3
0
            public void should_validate()
            {
                string producerConfig = string.Format(
                    @"<endpoints>
                            <endpoint name=""producer"" connectionString=""{0}{1}"">
                                <outgoing>
                                    <route key=""a"" label=""msg.a"" />
                                </outgoing>
                            </endpoint>
                        </endpoints>",
                    this.AmqpConnection,
                    this.VhostName);

                string consumerConfig = string.Format(
                    @"<endpoints>
                            <endpoint name=""consumer"" connectionString=""{0}{1}"">
                                <validators>
                                    <add name=""ValidatorGroup"" group=""true"" />
                                </validators>
                                <incoming>
                                    <on key=""a"" label=""msg.a"" react=""BooHandler"" type=""BooMessage"" />
                                </incoming>
                            </endpoint>
                        </endpoints>",
                    this.AmqpConnection,
                    this.VhostName);

                var handler = new ConcreteHandlerOf <BooMessage>();

                IKernel kernel = new StandardKernel();

                kernel.Bind <IConsumerOf <BooMessage> >()
                .ToConstant(handler)
                .InSingletonScope()
                .Named("BooHandler");
                kernel.Bind <IMessageValidator>()
                .To <BooPayloadValidator>()
                .InSingletonScope();
                kernel.Bind <IMessageValidator>()
                .To <FooPayloadValidator>()
                .InSingletonScope();

                kernel.Bind <MessageValidatorGroup>()
                .ToSelf()
                .InSingletonScope()
                .Named("ValidatorGroup")
                .WithConstructorArgument("validators", ctx => ctx.Kernel.GetAll <IMessageValidator>());

                DependencyResolverFunc dependencyResolver = (name, type) => kernel.Get(type, name);

                this.StartBus(
                    "consumer",
                    cfg =>
                {
                    var section = new XmlEndpointsSection(consumerConfig);
                    new AppConfigConfigurator(section, dependencyResolver).Configure("consumer", cfg);
                });

                IBus producer = this.StartBus(
                    "producer",
                    cfg =>
                {
                    var section = new XmlEndpointsSection(producerConfig);
                    new AppConfigConfigurator(section, dependencyResolver).Configure("producer", cfg);
                });

                producer.Emit("msg.a", new { Num = 13 });

                handler.Received.WaitOne(3.Seconds()).
                Should().
                BeFalse();
            }