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 ManagementAndMonitoringService() { 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("messages"); var rmqMessageProducerFactory = new RmqMessageProducerFactory("messages"); 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(); var controlBusBuilder = ControlBusReceiverBuilder .With() .Dispatcher(_dispatcher) .ProducerFactory(rmqMessageProducerFactory) .ChannelFactory(new InputChannelFactory(rmqMessageConsumerFactory, rmqMessageProducerFactory)) as ControlBusReceiverBuilder; _controlDispatcher = controlBusBuilder.Build(Environment.MachineName + "." + "ManagementAndMonitoring"); container.Register<IAmAControlBusSender>(new ControlBusSenderFactory().Create( new MsSqlMessageStore( new MsSqlMessageStoreConfiguration( "DataSource=\"" + Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase.Substring(8)), "App_Data\\MessageStore.sdf") + "\"", "Messages", MsSqlMessageStoreConfiguration.DatabaseType.SqlCe) ), new RmqMessageProducer("monitoring"))); }
public ManagementAndMonitoringService() { 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)} }; var rmqGatewayMessages = new RmqMessagingGatewayConnection { AmpqUri = new AmqpUriSpecification(new Uri("amqp://*****:*****@localhost:5672/%2f")), Exchange = new Exchange("paramore.brighter.exchange"), }; var rmqGatewayMonitoring = new RmqMessagingGatewayConnection { AmpqUri = new AmqpUriSpecification(new Uri("amqp://*****:*****@localhost:5672/%2f")), Exchange = new Exchange("paramore.brighter.exchange"), }; //create the gateway var rmqMessageConsumerFactory = new RmqMessageConsumerFactory(rmqGatewayMessages); var rmqMessageProducerFactory = new RmqMessageProducerFactory(rmqGatewayMessages); var connections = new List<Connection> { }; 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(); var controlBusBuilder = ControlBusReceiverBuilder .With() .Dispatcher(_dispatcher) .ProducerFactory(rmqMessageProducerFactory) .ChannelFactory(new InputChannelFactory(rmqMessageConsumerFactory, rmqMessageProducerFactory)) as ControlBusReceiverBuilder; _controlDispatcher = controlBusBuilder.Build(Environment.MachineName + "." + "ManagementAndMonitoring"); container.Register<IAmAControlBusSender>(new ControlBusSenderFactory().Create( new SqliteMessageStore( new SqliteMessageStoreConfiguration( "DataSource=\"" + Path.Combine(Path.GetDirectoryName(typeof(GreetingCommand).GetTypeInfo().Assembly.CodeBase.Substring(8)), "App_Data\\MessageStore.sdf") + "\"", "Messages") ), new RmqMessageProducer(rmqGatewayMonitoring))); }
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(); }
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 static void Main() { Log.Logger = new LoggerConfiguration() .WriteTo.Console() .CreateLogger(); 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)} }; var rmqGatewayMessages = RmqGatewayBuilder.With .Uri(new Uri("amqp://*****:*****@localhost:5672/%2f")) .Exchange("paramore.brighter.exchange") .DefaultQueues(); var rmqMessageProducerFactory = new RmqMessageProducerFactory(rmqGatewayMessages); var inputChannelFactory = new InputChannelFactory(new RmqMessageConsumerFactory(rmqGatewayMessages), rmqMessageProducerFactory); var builder = DispatchBuilder .With() .CommandProcessor(CommandProcessorBuilder.With() .Handlers(new HandlerConfiguration(subscriberRegistry, handlerFactory)) .Policies(policyRegistry) .NoTaskQueues() .RequestContextFactory(new InMemoryRequestContextFactory()) .Build() ) .MessageMappers(messageMapperRegistry) .ChannelFactory(inputChannelFactory) .Connections(new[] { ConnectionBuilder.With .Name("paramore.example.greeting") .ChannelFactory(inputChannelFactory) .Type(typeof(GreetingCommand)) .ChannelName("greeting.event") .RoutingKey("greeting.event") .Timeout(200) .Build() }); _dispatcher = builder.Build(); var controlBusBuilder = ControlBusReceiverBuilder .With() .Dispatcher(_dispatcher) .ProducerFactory(rmqMessageProducerFactory) .ChannelFactory(inputChannelFactory) as ControlBusReceiverBuilder; var controlDispatcher = controlBusBuilder.Build(Environment.MachineName + "." + "ManagementAndMonitoring"); container.Register<IAmAControlBusSender>(new ControlBusSenderFactory().Create( new SqliteMessageStore( new SqliteMessageStoreConfiguration( "DataSource=\"" + Path.Combine(Path.GetDirectoryName(typeof(GreetingCommand).GetTypeInfo().Assembly.CodeBase.Substring(8)), "App_Data\\MessageStore.sdf") + "\"", "Messages") ), new RmqMessageProducer(RmqGatewayBuilder.With .Uri(new Uri("amqp://*****:*****@localhost:5672/%2f")) .Exchange("paramore.brighter.exchange") .DefaultQueues()))); controlDispatcher.Receive(); _dispatcher.Receive(); Console.WriteLine("Press Enter to stop ..."); Console.ReadLine(); controlDispatcher.End(); //Don't wait on the control bus, we are stopping so we don't want any more control messages, just terminate _dispatcher.End().Wait(); }