Ejemplo n.º 1
0
        public TaskMailerService()
        {
            log4net.Config.XmlConfigurator.Configure();

            var logger = LogProvider.For<TaskMailerService>();

            var container = new TinyIoCContainer();
            container.Register<IAmAMessageMapper<TaskReminderCommand>, TaskReminderCommandMessageMapper>();
            container.Register<MailTaskReminderHandler, MailTaskReminderHandler>();
            container.Register<IAmAMailGateway, MailGateway>();
            container.Register<ILog>(logger);
            container.Register<IAmAMailTranslator, MailTranslator>();

            var handlerFactory = new TinyIocHandlerFactory(container);
            var messageMapperFactory = new TinyIoCMessageMapperFactory(container);

            var subscriberRegistry = new SubscriberRegistry();
            subscriberRegistry.Register<TaskReminderCommand, MailTaskReminderHandler>();

            //create policies
            var retryPolicy = Policy
                .Handle<Exception>()
                .WaitAndRetry(new[]
                    {
                        TimeSpan.FromMilliseconds(50),
                        TimeSpan.FromMilliseconds(100),
                        TimeSpan.FromMilliseconds(150)
                    });

            var circuitBreakerPolicy = Policy
                .Handle<Exception>()
                .CircuitBreaker(1, TimeSpan.FromMilliseconds(500));

            var policyRegistry = new PolicyRegistry()
            {
                {CommandProcessor.RETRYPOLICY, retryPolicy},
                {CommandProcessor.CIRCUITBREAKER, circuitBreakerPolicy}
            };

            var commandProcessor = CommandProcessorBuilder.With()
                .Handlers(new HandlerConfiguration(subscriberRegistry, handlerFactory))
                .Policies(policyRegistry)
                .Logger(logger)
                .NoTaskQueues()
                .RequestContextFactory(new InMemoryRequestContextFactory())
                .Build();

            //create message mappers
            var messageMapperRegistry = new MessageMapperRegistry(messageMapperFactory)
            {
                {typeof (TaskReminderCommand), typeof(TaskReminderCommandMessageMapper)}
            };

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

            _dispatcher = DispatchBuilder.With()
                .Logger(logger)
                .CommandProcessor(commandProcessor)
                .MessageMappers(messageMapperRegistry)
                .ChannelFactory(new InputChannelFactory(rmqMessageConsumerFactory, rmqMessageProducerFactory))
                .ConnectionsFromConfiguration()
                .Build();
        }
Ejemplo n.º 2
0
        public TaskMailerService()
        {
            log4net.Config.XmlConfigurator.Configure();

            var container = new TinyIoCContainer();

            container.Register <IAmAMessageMapper <TaskReminderCommand>, Tasks.Ports.TaskReminderCommandMessageMapper>();
            container.Register <MailTaskReminderHandler, MailTaskReminderHandler>();
            container.Register <IAmAMailGateway, MailGateway>();
            container.Register <IAmAMailTranslator, MailTranslator>();

            var handlerFactory       = new TinyIocHandlerFactory(container);
            var messageMapperFactory = new TinyIoCMessageMapperFactory(container);

            var subscriberRegistry = new SubscriberRegistry();

            subscriberRegistry.Register <TaskReminderCommand, MailTaskReminderHandler>();

            //create policies
            var retryPolicy = Policy
                              .Handle <Exception>()
                              .WaitAndRetry(new[]
            {
                TimeSpan.FromMilliseconds(50),
                TimeSpan.FromMilliseconds(100),
                TimeSpan.FromMilliseconds(150)
            });

            var circuitBreakerPolicy = Policy
                                       .Handle <Exception>()
                                       .CircuitBreaker(1, TimeSpan.FromMilliseconds(500));

            var policyRegistry = new PolicyRegistry()
            {
                { CommandProcessor.RETRYPOLICY, retryPolicy },
                { CommandProcessor.CIRCUITBREAKER, circuitBreakerPolicy }
            };

            var messageMapperRegistry = new MessageMapperRegistry(messageMapperFactory)
            {
                { typeof(TaskReminderCommand), typeof(Tasks.Ports.TaskReminderCommandMessageMapper) },
                { typeof(TaskReminderSentEvent), typeof(TaskMailer.Ports.TaskReminderSentEventMapper) }
            };
            var rmqConnnection = new RmqMessagingGatewayConnection
            {
                AmpqUri  = new AmqpUriSpecification(new Uri("amqp://*****:*****@localhost:5672/%2f")),
                Exchange = new Exchange("paramore.brighter.exchange"),
            };
            var commandProcessor = CommandProcessorBuilder.With()
                                   .Handlers(new HandlerConfiguration(subscriberRegistry, handlerFactory))
                                   .Policies(policyRegistry)
                                   .TaskQueues(new MessagingConfiguration(new TemporaryMessageStore(), new RmqMessageProducer(rmqConnnection), messageMapperRegistry))
                                   .RequestContextFactory(new InMemoryRequestContextFactory())
                                   .Build();

            container.Register <IAmACommandProcessor>(commandProcessor);

            var rmqMessageConsumerFactory = new RmqMessageConsumerFactory(rmqConnnection);
            var rmqMessageProducerFactory = new RmqMessageProducerFactory(rmqConnnection);
            var inputChannelFactory       = new InputChannelFactory(new RmqMessageConsumerFactory(rmqConnnection), new RmqMessageProducerFactory(rmqConnnection));

            var connections = new List <Connection>
            {
                // Events with mapper and handler overrides
                new Connection(new ConnectionName("Task.Reminder"), inputChannelFactory, typeof(TaskReminderCommand), new ChannelName("Task.Reminder"), "Task.Reminder", noOfPerformers: 1, timeoutInMilliseconds: 200),
            };

            _dispatcher = DispatchBuilder.With()
                          .CommandProcessor(commandProcessor)
                          .MessageMappers(messageMapperRegistry)
                          .ChannelFactory(new InputChannelFactory(rmqMessageConsumerFactory, rmqMessageProducerFactory))
                          .Connections(connections)
                          .Build();
        }
Ejemplo n.º 3
0
        public TaskMailerService()
        {
            //Create a logger
            var properties = new NameValueCollection();
            properties["showDateTime"] = "true";
            LogManager.Adapter = new ConsoleOutLoggerFactoryAdapter(properties);
            var logger = LogManager.GetLogger(typeof (Dispatcher));
                
            var container = new TinyIoCContainer();
            container.Register<IAmAMessageMapper<TaskReminderCommand>, TaskReminderCommandMessageMapper>();
            var handlerFactory = new TinyIocHandlerFactory(container);

            var subscriberRegistry = new SubscriberRegistry();

            //create policies
            var retryPolicy = Policy
                .Handle<Exception>()
                .WaitAndRetry(new[]
                    {
                        TimeSpan.FromMilliseconds(50),
                        TimeSpan.FromMilliseconds(100),
                        TimeSpan.FromMilliseconds(150)
                    });

            var circuitBreakerPolicy = Policy
                .Handle<Exception>()
                .CircuitBreaker(1, TimeSpan.FromMilliseconds(500));

            var policyRegistry = new PolicyRegistry()
            {
                {CommandProcessor.RETRYPOLICY, retryPolicy},
                {CommandProcessor.CIRCUITBREAKER, circuitBreakerPolicy}
            };

            //create message mappers
            //var messageMapperRegistry = 

            //create the gateway
            var gateway = new RMQMessagingGateway(logger);

            var builder = DispatchBuilder.With()
                        .WithLogger(logger)
                        .WithCommandProcessor(CommandProcessorBuilder.With()
                            .Handlers(new HandlerConfiguration(subscriberRegistry, handlerFactory))
                            .Policies(policyRegistry)
                            .Logger(logger)
                            .TaskQueues(new MessagingConfiguration(
                                messageStore: new RavenMessageStore(new EmbeddableDocumentStore(), logger),
                                messagingGateway: gateway,
                                messageMapperRegistry: null
                                ))
                            .RequestContextFactory(new InMemoryRequestContextFactory())
                            .Build()
                            )
                            .WithMessageMappers(null)
                            .WithChannelFactory(new RMQInputChannelfactory(gateway)) 
                            .ConnectionsFromConfiguration();

            dispatcher = builder.Build();

        }
Ejemplo n.º 4
0
        public TaskMailerService()
        {
            //Create a logger
            var properties = new NameValueCollection();

            properties["showDateTime"] = "true";
            LogManager.Adapter         = new ConsoleOutLoggerFactoryAdapter(properties);
            var logger = LogManager.GetLogger(typeof(Dispatcher));

            var container = new TinyIoCContainer();

            container.Register <IAmAMessageMapper <TaskReminderCommand>, TaskReminderCommandMessageMapper>();
            var handlerFactory       = new TinyIocHandlerFactory(container);
            var messageMapperFactory = new TinyIoCMessageMapperFactory(container);

            var subscriberRegistry = new SubscriberRegistry();

            //create policies
            var retryPolicy = Policy
                              .Handle <Exception>()
                              .WaitAndRetry(new[]
            {
                TimeSpan.FromMilliseconds(50),
                TimeSpan.FromMilliseconds(100),
                TimeSpan.FromMilliseconds(150)
            });

            var circuitBreakerPolicy = Policy
                                       .Handle <Exception>()
                                       .CircuitBreaker(1, TimeSpan.FromMilliseconds(500));

            var policyRegistry = new PolicyRegistry()
            {
                { CommandProcessor.RETRYPOLICY, retryPolicy },
                { CommandProcessor.CIRCUITBREAKER, circuitBreakerPolicy }
            };

            //create message mappers
            var messageMapperRegistry = new MessageMapperRegistry(messageMapperFactory);

            //create the gateway
            var gateway = new RMQMessagingGateway(logger);

            var builder = DispatchBuilder.With()
                          .WithLogger(logger)
                          .WithCommandProcessor(CommandProcessorBuilder.With()
                                                .Handlers(new HandlerConfiguration(subscriberRegistry, handlerFactory))
                                                .Policies(policyRegistry)
                                                .Logger(logger)
                                                .TaskQueues(new MessagingConfiguration(
                                                                messageStore: new RavenMessageStore(new EmbeddableDocumentStore(), logger),
                                                                messagingGateway: gateway,
                                                                messageMapperRegistry: messageMapperRegistry
                                                                ))
                                                .RequestContextFactory(new InMemoryRequestContextFactory())
                                                .Build()
                                                )
                          .WithMessageMappers(null)
                          .WithChannelFactory(new RMQInputChannelfactory(gateway))
                          .ConnectionsFromConfiguration();

            dispatcher = builder.Build();
        }