public GreetingService() { log4net.Config.XmlConfigurator.Configure(); var container = new TinyIoCContainer(); var handlerFactory = new TinyIocHandlerFactory(container); var messageMapperFactory = new TinyIoCMessageMapperFactory(container); container.Register<IHandleRequests<GreetingCommand>, GreetingCommandHandler>(); var subscriberRegistry = new SubscriberRegistry(); subscriberRegistry.Register<GreetingCommand, GreetingCommandHandler>(); //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) { {typeof(GreetingCommand), typeof(GreetingCommandMessageMapper)} }; //create the gateway var rmqMessageConsumerFactory = new RmqMessageConsumerFactory(); var rmqMessageProducerFactory = new RmqMessageProducerFactory(); var builder = DispatchBuilder .With() .CommandProcessor(CommandProcessorBuilder.With() .Handlers(new HandlerConfiguration(subscriberRegistry, handlerFactory)) .Policies(policyRegistry) .NoTaskQueues() .RequestContextFactory(new InMemoryRequestContextFactory()) .Build() ) .MessageMappers(messageMapperRegistry) .ChannelFactory(new InputChannelFactory(rmqMessageConsumerFactory, rmqMessageProducerFactory)) .ConnectionsFromConfiguration(); _dispatcher = builder.Build(); }
public GreetingService() { log4net.Config.XmlConfigurator.Configure(new FileInfo("log4net.config")); var container = new TinyIoCContainer(); var handlerFactory = new TinyIocHandlerFactory(container); var messageMapperFactory = new TinyIoCMessageMapperFactory(container); container.Register<IHandleRequests<GreetingEvent>, GreetingEventHandler>(); var subscriberRegistry = new SubscriberRegistry(); subscriberRegistry.Register<GreetingEvent, GreetingEventHandler>(); //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) { {typeof(GreetingEvent), typeof(GreetingEventMessageMapper)} }; //create the gateway var rmqConnnection = new RmqMessagingGatewayConnection { AmpqUri = new AmqpUriSpecification(new Uri("amqp://*****:*****@localhost:5672/%2f")), Exchange = new Exchange("paramore.brighter.exchange"), }; var rmqMessageConsumerFactory = new RmqMessageConsumerFactory(rmqConnnection); var rmqMessageProducerFactory = new RmqMessageProducerFactory(rmqConnnection); // < add connectionName = "paramore.example.greeting" channelName = "greeting." routingKey = "greeting.command" dataType = "Greetings.Ports.Commands.GreetingEvent" timeOutInMilliseconds = "200" /> // Service Activator connections var connections = new List<paramore.brighter.serviceactivator.Connection> { new paramore.brighter.serviceactivator.Connection( new ConnectionName("paramore.example.greeting"), new InputChannelFactory(rmqMessageConsumerFactory, rmqMessageProducerFactory), typeof(GreetingEvent), new ChannelName("greeting.event"), "greeting.event", timeoutInMilliseconds: 200) }; var builder = DispatchBuilder .With() .CommandProcessor(CommandProcessorBuilder.With() .Handlers(new HandlerConfiguration(subscriberRegistry, handlerFactory)) .Policies(policyRegistry) .NoTaskQueues() .RequestContextFactory(new InMemoryRequestContextFactory()) .Build() ) .MessageMappers(messageMapperRegistry) .ChannelFactory(new InputChannelFactory(rmqMessageConsumerFactory, rmqMessageProducerFactory)) .Connections(connections); _dispatcher = builder.Build(); }
public static void Main(string[] args) { Log.Logger = new LoggerConfiguration() .WriteTo.Console() .CreateLogger(); var container = new TinyIoCContainer(); var handlerFactory = new TinyIocHandlerFactory(container); var messageMapperFactory = new TinyIoCMessageMapperFactory(container); container.Register<IHandleRequests<GreetingEvent>, GreetingEventHandler>(); var subscriberRegistry = new SubscriberRegistry(); subscriberRegistry.Register<GreetingEvent, GreetingEventHandler>(); //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) { {typeof(GreetingEvent), typeof(GreetingEventMessageMapper)} }; //create the gateway var rmqConnnection = new RmqMessagingGatewayConnection { AmpqUri = new AmqpUriSpecification(new Uri("amqp://*****:*****@localhost:5672/%2f")), Exchange = new Exchange("paramore.brighter.exchange"), }; var rmqMessageConsumerFactory = new RmqMessageConsumerFactory(rmqConnnection ); var rmqMessageProducerFactory = new RmqMessageProducerFactory(rmqConnnection ); // Service Activator connections var connections = new List<paramore.brighter.serviceactivator.Connection> { new paramore.brighter.serviceactivator.Connection( new ConnectionName("paramore.example.greeting"), new InputChannelFactory(rmqMessageConsumerFactory, rmqMessageProducerFactory), typeof(GreetingEvent), new ChannelName("greeting.event"), "greeting.event", timeoutInMilliseconds: 200) }; var builder = DispatchBuilder .With() .CommandProcessor(CommandProcessorBuilder.With() .Handlers(new HandlerConfiguration(subscriberRegistry, handlerFactory)) .Policies(policyRegistry) .NoTaskQueues() .RequestContextFactory(new InMemoryRequestContextFactory()) .Build() ) .MessageMappers(messageMapperRegistry) .ChannelFactory(new InputChannelFactory(rmqMessageConsumerFactory, rmqMessageProducerFactory)) .Connections(connections); var dispatcher = builder.Build(); dispatcher.Receive(); Console.WriteLine("Press Enter to stop ..."); Console.ReadLine(); dispatcher.End().Wait(); }
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(); }