public DocumentService() { log4net.Config.XmlConfigurator.Configure(); var container = new TinyIoCContainer(); var handlerFactory = new TinyIocHandlerFactory(container); var messageMapperFactory = new TinyIoCMessageMapperFactory(container); container.Register<IHandleRequests<DocumentCreatedEvent>, DocumentCreatedEventHandler>(); container.Register<IHandleRequests<DocumentUpdatedEvent>, DocumentUpdatedEventHandler>(); container.Register<IHandleRequests<FolderCreatedEvent>, FolderCreatedEventHandler>(); var subscriberRegistry = new SubscriberRegistry(); subscriberRegistry.Register<DocumentCreatedEvent, DocumentCreatedEventHandler>(); subscriberRegistry.Register<DocumentUpdatedEvent, DocumentUpdatedEventHandler>(); subscriberRegistry.Register<FolderCreatedEvent, FolderCreatedEventHandler>(); //create policies var retryPolicy = Policy .Handle<Exception>() .WaitAndRetry(new[] { TimeSpan.FromMilliseconds(5000), TimeSpan.FromMilliseconds(10000), TimeSpan.FromMilliseconds(10000) }); 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) { {typeof(FolderCreatedEvent), typeof(FolderCreatedEventMessageMapper)}, {typeof(DocumentCreatedEvent), typeof(DocumentCreatedEventMessageMapper)}, {typeof(DocumentUpdatedEvent), typeof(DocumentUpdatedEventMessageMapper)} }; var sqsMessageConsumerFactory = new SqsMessageConsumerFactory(); var sqsMessageProducerFactory = new SqsMessageProducerFactory(); var builder = DispatchBuilder .With() .CommandProcessor(CommandProcessorBuilder.With() .Handlers(new HandlerConfiguration(subscriberRegistry, handlerFactory)) .Policies(policyRegistry) .NoTaskQueues() .RequestContextFactory(new InMemoryRequestContextFactory()) .Build() ) .MessageMappers(messageMapperRegistry) .ChannelFactory(new InputChannelFactory(sqsMessageConsumerFactory, sqsMessageProducerFactory)) .ConnectionsFromConfiguration(); _dispatcher = builder.Build(); }
public DocumentService() { log4net.Config.XmlConfigurator.Configure(); var container = new TinyIoCContainer(); var handlerFactory = new TinyIocHandlerFactory(container); var messageMapperFactory = new TinyIoCMessageMapperFactory(container); container.Register<IHandleRequests<DocumentCreatedEvent>, DocumentCreatedEventHandler>(); container.Register<IHandleRequests<DocumentUpdatedEvent>, DocumentUpdatedEventHandler>(); container.Register<IHandleRequests<FolderCreatedEvent>, FolderCreatedEventHandler>(); var subscriberRegistry = new SubscriberRegistry(); subscriberRegistry.Register<DocumentCreatedEvent, DocumentCreatedEventHandler>(); subscriberRegistry.Register<DocumentUpdatedEvent, DocumentUpdatedEventHandler>(); subscriberRegistry.Register<FolderCreatedEvent, FolderCreatedEventHandler>(); //create policies var retryPolicy = Policy .Handle<Exception>() .WaitAndRetry(new[] { TimeSpan.FromMilliseconds(5000), TimeSpan.FromMilliseconds(10000), TimeSpan.FromMilliseconds(10000) }); 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) { {typeof(FolderCreatedEvent), typeof(FolderCreatedEventMessageMapper)}, {typeof(DocumentCreatedEvent), typeof(DocumentCreatedEventMessageMapper)}, {typeof(DocumentUpdatedEvent), typeof(DocumentUpdatedEventMessageMapper)} }; var awsCredentials = new StoredProfileAWSCredentials(); var sqsMessageConsumerFactory = new SqsMessageConsumerFactory(awsCredentials ); var sqsMessageProducerFactory = new SqsMessageProducerFactory(awsCredentials ); var connections = new List<paramore.brighter.serviceactivator.Connection> { new paramore.brighter.serviceactivator.Connection( new ConnectionName("paramore.example.documentsandfolders.documentcreatedevent"), new InputChannelFactory(sqsMessageConsumerFactory, sqsMessageProducerFactory), typeof(DocumentCreatedEvent), new ChannelName("https://sqs.eu-west-1.amazonaws.com/027649620536/DocumentCreatedEvent"), "DocumentCreatedEvent", timeoutInMilliseconds: 5000, noOfPerformers: 10), new paramore.brighter.serviceactivator.Connection( new ConnectionName("paramore.example.documentsandfolders.documentupdatedevent"), new InputChannelFactory(sqsMessageConsumerFactory, sqsMessageProducerFactory), typeof(DocumentUpdatedEvent), new ChannelName("https://sqs.eu-west-1.amazonaws.com/027649620536/DocumentUpdatedEvent"), "DocumentUpdatedEvent", timeoutInMilliseconds: 5000, noOfPerformers: 10), new paramore.brighter.serviceactivator.Connection( new ConnectionName("paramore.example.documentsandfolders.foldercreateddevent"), new InputChannelFactory(sqsMessageConsumerFactory, sqsMessageProducerFactory), typeof(FolderCreatedEvent), new ChannelName("https://sqs.eu-west-1.amazonaws.com/027649620536/FolderCreatedEvent"), "FolderCreatedEvent", timeoutInMilliseconds: 5000, noOfPerformers: 10) }; var builder = DispatchBuilder .With() .CommandProcessor(CommandProcessorBuilder.With() .Handlers(new HandlerConfiguration(subscriberRegistry, handlerFactory)) .Policies(policyRegistry) .NoTaskQueues() .RequestContextFactory(new InMemoryRequestContextFactory()) .Build() ) .MessageMappers(messageMapperRegistry) .ChannelFactory(new InputChannelFactory(sqsMessageConsumerFactory, sqsMessageProducerFactory)) .Connections(connections); _dispatcher = builder.Build(); }