示例#1
0
        public void Establish()
        {
            var messageMapperRegistry = new MessageMapperRegistry(new SimpleMessageMapperFactory(() => new MyEventMessageMapper()));

            messageMapperRegistry.Register <MyEvent, MyEventMessageMapper>();
            var policyRegistry = new PolicyRegistry
            {
                {
                    CommandProcessor.RETRYPOLICY, Policy
                    .Handle <Exception>()
                    .WaitAndRetry(new[] { TimeSpan.FromMilliseconds(50) })
                },
                {
                    CommandProcessor.CIRCUITBREAKER, Policy
                    .Handle <Exception>()
                    .CircuitBreaker(1, TimeSpan.FromMilliseconds(500))
                }
            };

            var connection = new RmqMessagingGatewayConnection
            {
                AmpqUri  = new AmqpUriSpecification(new Uri("amqp://*****:*****@localhost:5672/%2f")),
                Exchange = new Exchange("paramore.brighter.exchange")
            };

            var rmqMessageConsumerFactory = new RmqMessageConsumerFactory(connection);
            var rmqMessageProducerFactory = new RmqMessageProducerFactory(connection);

            var connections = new List <Connection>
            {
                new Connection(
                    new ConnectionName("foo"),
                    new InputChannelFactory(rmqMessageConsumerFactory, rmqMessageProducerFactory),
                    typeof(MyEvent),
                    new ChannelName("mary"),
                    "bob",
                    timeoutInMilliseconds: 200),
                new Connection(
                    new ConnectionName("bar"),
                    new InputChannelFactory(rmqMessageConsumerFactory, rmqMessageProducerFactory),
                    typeof(MyEvent),
                    new ChannelName("alice"),
                    "simon",
                    timeoutInMilliseconds: 200)
            };

            _builder = DispatchBuilder.With()
                       .CommandProcessor(CommandProcessorBuilder.With()
                                         .Handlers(new HandlerConfiguration(new SubscriberRegistry(),
                                                                            new TinyIocHandlerFactory(new TinyIoCContainer())))
                                         .Policies(policyRegistry)
                                         .NoTaskQueues()
                                         .RequestContextFactory(new InMemoryRequestContextFactory())
                                         .Build()
                                         )
                       .MessageMappers(messageMapperRegistry)
                       .ChannelFactory(new InputChannelFactory(rmqMessageConsumerFactory, rmqMessageProducerFactory))
                       .Connections(connections);
        }