protected override void ConfigureApplicationContainer(TinyIoCContainer container) { base.ConfigureApplicationContainer(container); var logger = LogProvider.GetLogger(this.GetType().Namespace); container.Register(logger); var subscriberRegistry = new SubscriberRegistry(); subscriberRegistry.Register<AddTaskCommand, AddTaskCommandHandler>(); subscriberRegistry.Register<CompleteTaskCommand, CompleteTaskCommandHandler>(); container.Register<IHandleRequests<AddTaskCommand>, AddTaskCommandHandler>().AsMultiInstance(); container.Register<IHandleRequests<CompleteTaskCommand>, CompleteTaskCommandHandler>().AsMultiInstance(); var handlerFactory = new TinyIoCHandlerFactory(container); 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 sqlMessageStore = new MsSqlMessageStore(new MsSqlMessageStoreConfiguration("Server=.;Database=brighterMessageStore;Trusted_Connection=True", "messages", MsSqlMessageStoreConfiguration.DatabaseType.MsSqlServer), logger); var gateway = new AzureServiceBusMessageProducer(logger); container.Register<IAmAMessageMapper<TaskReminderCommand>, TaskReminderCommandMessageMapper>().AsMultiInstance(); var messageMapperFactory = new TinyIoCMessageMapperFactory(container); var messageMapperRegistry = new MessageMapperRegistry(messageMapperFactory); messageMapperRegistry.Add(typeof(TaskReminderCommand), typeof(TaskReminderCommandMessageMapper)); var commandProcessor = CommandProcessorBuilder .With() .Handlers(new HandlerConfiguration(subscriberRegistry, handlerFactory)) .Policies(policyRegistry) .TaskQueues(new MessagingConfiguration(sqlMessageStore, gateway, messageMapperRegistry)) .RequestContextFactory(new InMemoryRequestContextFactory()) .Build(); container.Register<IAmACommandProcessor>(commandProcessor); }
public SqlMessageStoreWritngMessagesAsyncTests() { _msSqlTestHelper = new MsSqlTestHelper(); _msSqlTestHelper.SetupMessageDb(); _sqlMessageStore = new MsSqlMessageStore(_msSqlTestHelper.MessageStoreConfiguration); }
public static void Run(UnityContainer container) { container.RegisterType <StoreFrontController>(); container.RegisterInstance(typeof(ILog), LogProvider.For <StoreService>(), new ContainerControlledLifetimeManager()); container.RegisterType <AddOrderCommandHandler>(); container.RegisterType <AddProductCommandHandler>(); container.RegisterType <ChangeProductCommandHandler>(); container.RegisterType <RemoveProductCommandHandler>(); container.RegisterType <IProductsDAO, ProductsDAO>(); var logger = container.Resolve <ILog>(); var handlerFactory = new UnityHandlerFactory(container); var subscriberRegistry = new SubscriberRegistry(); subscriberRegistry.Register <AddOrderCommand, AddOrderCommandHandler>(); subscriberRegistry.Register <AddProductCommand, AddProductCommandHandler>(); subscriberRegistry.Register <ChangeProductCommand, ChangeProductCommandHandler>(); subscriberRegistry.Register <RemoveProductCommand, RemoveProductCommandHandler>(); //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 messageMapperFactory = new UnityMessageMapperFactory(container); var messageMapperRegistry = new MessageMapperRegistry(messageMapperFactory); messageMapperRegistry.Register <AddOrderCommand, AddOrderCommandMessageMapper>(); var gateway = new RmqMessageProducer(container.Resolve <ILog>()); var dbPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase.Substring(8)), "App_Data\\MessageStore.sdf"); IAmAMessageStore <Message> sqlMessageStore = new MsSqlMessageStore(new MsSqlMessageStoreConfiguration("DataSource=\"" + dbPath + "\"", "Messages", MsSqlMessageStoreConfiguration.DatabaseType.SqlCe), logger); var commandProcessor = CommandProcessorBuilder.With() .Handlers(new HandlerConfiguration(subscriberRegistry, handlerFactory)) .Policies(policyRegistry) .Logger(logger) .TaskQueues(new MessagingConfiguration(sqlMessageStore, gateway, messageMapperRegistry)) .RequestContextFactory(new InMemoryRequestContextFactory()) .Build(); container.RegisterInstance(typeof(IAmACommandProcessor), commandProcessor); }
public MsSqlMessageStoreEmptyStoreTests() { _msSqlTestHelper = new MsSqlTestHelper(); _msSqlTestHelper.SetupMessageDb(); _sqlMessageStore = new MsSqlMessageStore(_msSqlTestHelper.MessageStoreConfiguration); _messageEarliest = new Message(new MessageHeader(Guid.NewGuid(), "test_topic", MessageType.MT_DOCUMENT), new MessageBody("message body")); }
public static void Run(UnityContainer container) { container.RegisterType<StoreFrontController>(); container.RegisterInstance(typeof(ILog), LogProvider.For<StoreService>(), new ContainerControlledLifetimeManager()); container.RegisterType<AddOrderCommandHandler>(); container.RegisterType<AddProductCommandHandler>(); container.RegisterType<ChangeProductCommandHandler>(); container.RegisterType<RemoveProductCommandHandler>(); container.RegisterType<IProductsDAO, ProductsDAO>(); var logger = container.Resolve<ILog>(); var handlerFactory = new UnityHandlerFactory(container); var subscriberRegistry = new SubscriberRegistry(); subscriberRegistry.Register<AddOrderCommand, AddOrderCommandHandler>(); subscriberRegistry.Register<AddProductCommand, AddProductCommandHandler>(); subscriberRegistry.Register<ChangeProductCommand, ChangeProductCommandHandler>(); subscriberRegistry.Register<RemoveProductCommand, RemoveProductCommandHandler>(); //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 messageMapperFactory = new UnityMessageMapperFactory(container); var messageMapperRegistry = new MessageMapperRegistry(messageMapperFactory); messageMapperRegistry.Register<AddOrderCommand, AddOrderCommandMessageMapper>(); var gateway = new RmqMessageProducer(container.Resolve<ILog>()); var dbPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase.Substring(8)), "App_Data\\MessageStore.sdf"); IAmAMessageStore<Message> sqlMessageStore = new MsSqlMessageStore(new MsSqlMessageStoreConfiguration("DataSource=\"" + dbPath + "\"", "Messages", MsSqlMessageStoreConfiguration.DatabaseType.SqlCe), logger); var commandProcessor = CommandProcessorBuilder.With() .Handlers(new HandlerConfiguration(subscriberRegistry, handlerFactory)) .Policies(policyRegistry) .Logger(logger) .TaskQueues(new MessagingConfiguration(sqlMessageStore, gateway, messageMapperRegistry)) .RequestContextFactory(new InMemoryRequestContextFactory()) .Build(); container.RegisterInstance(typeof(IAmACommandProcessor), commandProcessor); }
public MsSqlMessageStoreRangeRequestAsyncTests() { _msSqlTestHelper = new MsSqlTestHelper(); _msSqlTestHelper.SetupMessageDb(); _sqlMessageStore = new MsSqlMessageStore(_msSqlTestHelper.MessageStoreConfiguration); _messageEarliest = new Message(new MessageHeader(Guid.NewGuid(), _TopicFirstMessage, MessageType.MT_DOCUMENT), new MessageBody("message body")); _message1 = new Message(new MessageHeader(Guid.NewGuid(), "test_topic2", MessageType.MT_DOCUMENT), new MessageBody("message body2")); _message2 = new Message(new MessageHeader(Guid.NewGuid(), _TopicLastMessage, MessageType.MT_DOCUMENT), new MessageBody("message body3")); }
public void Establish() { _msSqlTestHelper = new MsSqlTestHelper(); _msSqlTestHelper.SetupMessageDb(); _sqlMessageStore = new MsSqlMessageStore(_msSqlTestHelper.MessageStoreConfiguration); _messageEarliest = new Message(new MessageHeader(Guid.NewGuid(), "test_topic", MessageType.MT_DOCUMENT), new MessageBody("message body")); AsyncContext.Run(async() => await _sqlMessageStore.AddAsync(_messageEarliest)); }
private static paramore.brighter.commandprocessor.CommandProcessor CreateCommandProcesor(UnityContainer container) { var logger = container.Resolve <ILog>(); var handlerFactory = new UnityHandlerFactory(container); var subscriberRegistry = new SubscriberRegistry(); subscriberRegistry.Register <AddOrganizationCommand, AddOrganizationCommandHandler>(); //subscriberRegistry.Register<AddOrganizationCommand, AddEFOrganisationCommandHandler>(); subscriberRegistry.Register <ChangeOrganizationCommand, ChangeOrganizationCommandHandler>(); subscriberRegistry.Register <OrganizationAddedEvent, OrganizationAddedEventHandler>(); subscriberRegistry.Register <OrganizationAddedEvent, OrganizationAddedLegacyEventHandler>(); //create retry policies var retryPolicy = Policy .Handle <Exception>() .WaitAndRetry(new[] { TimeSpan.FromMilliseconds(50), TimeSpan.FromMilliseconds(100), TimeSpan.FromMilliseconds(150) }); //create circuit breaker policies var circuitBreakerPolicy = Policy .Handle <Exception>() .CircuitBreaker(1, TimeSpan.FromMilliseconds(500)); var policyRegistry = new PolicyRegistry() { { paramore.brighter.commandprocessor.CommandProcessor.RETRYPOLICY, retryPolicy }, { paramore.brighter.commandprocessor.CommandProcessor.CIRCUITBREAKER, circuitBreakerPolicy } }; var messageMapperFactory = new UnityMessageMapperFactory(container); var messageMapperRegistry = new MessageMapperRegistry(messageMapperFactory); messageMapperRegistry.Register <AddOrganizationCommand, AddOrganizationCommandMessageMapper>(); string connectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; var gateway = new RmqMessageProducer(container.Resolve <ILog>()); IAmAMessageStore <Message> sqlMessageStore = new MsSqlMessageStore(new MsSqlMessageStoreConfiguration(connectionString, "Messages", MsSqlMessageStoreConfiguration.DatabaseType.MsSqlServer), logger); var commandProcessor = CommandProcessorBuilder.With() .Handlers(new HandlerConfiguration(subscriberRegistry, handlerFactory)) .Policies(policyRegistry) .TaskQueues(new MessagingConfiguration(sqlMessageStore, gateway, messageMapperRegistry)) .RequestContextFactory(new InMemoryRequestContextFactory()) .Build(); return(commandProcessor); }
public SqlMessageStoreWritingMessageAsyncTests() { _msSqlTestHelper = new MsSqlTestHelper(); _msSqlTestHelper.SetupMessageDb(); _sqlMessageStore = new MsSqlMessageStore(_msSqlTestHelper.MessageStoreConfiguration); var messageHeader = new MessageHeader(Guid.NewGuid(), "test_topic", MessageType.MT_DOCUMENT, DateTime.UtcNow.AddDays(-1), 5, 5); messageHeader.Bag.Add(_key1, _value1); messageHeader.Bag.Add(_key2, _value2); _messageEarliest = new Message(messageHeader, new MessageBody("message body")); }
public void Establish() { _msSqlTestHelper = new MsSqlTestHelper(); _msSqlTestHelper.SetupMessageDb(); s_sqlMessageStore = new MsSqlMessageStore(_msSqlTestHelper.MessageStoreConfiguration); s_messageEarliest = new Message(new MessageHeader(Guid.NewGuid(), _TopicFirstMessage, MessageType.MT_DOCUMENT), new MessageBody("message body")); s_message1 = new Message(new MessageHeader(Guid.NewGuid(), "test_topic2", MessageType.MT_DOCUMENT), new MessageBody("message body2")); s_message2 = new Message(new MessageHeader(Guid.NewGuid(), _TopicLastMessage, MessageType.MT_DOCUMENT), new MessageBody("message body3")); s_sqlMessageStore.Add(s_messageEarliest); s_sqlMessageStore.Add(s_message1); s_sqlMessageStore.Add(s_message2); }
public void Writing_and_reading_a_message_from_the_store() { CleanupDb(); CreateTestDb(); var sqlMessageStore = new MsSqlMessageStore(new MsSqlMessageStoreConfiguration(ConnectionString, TableName, MsSqlMessageStoreConfiguration.DatabaseType.SqlCe), new NoOpLogger()); var message = new Message(new MessageHeader(Guid.NewGuid(), "test_topic", MessageType.MT_DOCUMENT), new MessageBody("message body")); sqlMessageStore.Add(message).Wait(); var storedMessage = sqlMessageStore.Get(message.Id).Result; Assert.AreEqual(message.Body.Value, storedMessage.Body.Value); }
public void Establish() { _msSqlTestHelper = new MsSqlTestHelper(); _msSqlTestHelper.SetupMessageDb(); _sqlMessageStore = new MsSqlMessageStore(_msSqlTestHelper.MessageStoreConfiguration); var messageHeader = new MessageHeader(Guid.NewGuid(), "test_topic", MessageType.MT_DOCUMENT, DateTime.UtcNow.AddDays(-1), 5, 5); messageHeader.Bag.Add(key1, value1); messageHeader.Bag.Add(key2, value2); _messageEarliest = new Message(messageHeader, new MessageBody("message body")); AsyncContext.Run(async() => await _sqlMessageStore.AddAsync(_messageEarliest)); }
internal static void ConfigureDependencies(TinyIoCContainer container) { var logger = LogProvider.GetLogger("MainNancyModule"); logger.Log(LogLevel.Debug, () => "GET on messages"); var messageStore = new MsSqlMessageStore( new MsSqlMessageStoreConfiguration("Server=.;Database=brighterMessageStore;Trusted_Connection=True", "messages", MsSqlMessageStoreConfiguration.DatabaseType.MsSqlServer), logger); container.Register(messageStore); container.Register(typeof (IMessageStoreActivationStateProvider), typeof (MessageStoreActivationStateProvider)); container.Register(typeof (IMessageStoreViewerFactory), typeof (MessageStoreViewerFactory)); }
private CommandProcessor CommandProcessorRegistrar(TinyIoCContainer container) { //Database dao container.Register <ITasksDAO, TasksDAO>().AsSingleton(); //create handler var handlerFactory = new TinyIocHandlerFactory(container); var subscriberRegistry = new SubscriberRegistry(); container.Register <IHandleRequests <AddTaskCommand>, AddTaskCommandHandler>().AsMultiInstance(); subscriberRegistry.Register <AddTaskCommand, AddTaskCommandHandler>(); //complete handler container.Register <IHandleRequests <CompleteTaskCommand>, CompleteTaskCommandHandler>().AsMultiInstance(); subscriberRegistry.Register <CompleteTaskCommand, CompleteTaskCommandHandler>(); //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 container.Register <IAmAMessageMapper <TaskReminderCommand>, TaskReminderCommandMessageMapper>().AsMultiInstance(); var messageMapperFactory = new TinyIoCMessageMapperFactory(container); var messageMapperRegistry = new MessageMapperRegistry(messageMapperFactory); messageMapperRegistry.Add(typeof(TaskReminderCommand), typeof(TaskReminderCommandMessageMapper)); messageMapperRegistry.Add(typeof(TaskAddedEvent), typeof(TaskAddedEventMapper)); messageMapperRegistry.Add(typeof(TaskEditedEvent), typeof(TaskEditedEventMapper)); messageMapperRegistry.Add(typeof(TaskCompletedEvent), typeof(TaskCompletedEventMapper)); messageMapperRegistry.Add(typeof(TaskReminderSentEvent), typeof(TaskReminderSentEventMapper)); var gateway = new RmqMessageProducer(); IAmAMessageStore <Message> sqlMessageStore = new MsSqlMessageStore(new MsSqlMessageStoreConfiguration("Server=.;Database=brighterMessageStore;Trusted_Connection=True", "messages", MsSqlMessageStoreConfiguration.DatabaseType.MsSqlServer)); var commandProcessor = CommandProcessorBuilder.With() .Handlers(new HandlerConfiguration(subscriberRegistry, handlerFactory)) .Policies(policyRegistry) .TaskQueues(new MessagingConfiguration(sqlMessageStore, gateway, messageMapperRegistry)) .RequestContextFactory(new InMemoryRequestContextFactory()) .Build(); container.Register <IAmACommandProcessor>(commandProcessor); return(commandProcessor); }
public SqlMessageStoreWritngMessagesTests() { _msSqlTestHelper = new MsSqlTestHelper(); _msSqlTestHelper.SetupMessageDb(); _sqlMessageStore = new MsSqlMessageStore(_msSqlTestHelper.MessageStoreConfiguration); _messageEarliest = new Message(new MessageHeader(Guid.NewGuid(), "Test", MessageType.MT_COMMAND, DateTime.UtcNow.AddHours(-3)), new MessageBody("Body")); _sqlMessageStore.Add(_messageEarliest); var message2 = new Message(new MessageHeader(Guid.NewGuid(), "Test2", MessageType.MT_COMMAND, DateTime.UtcNow.AddHours(-2)), new MessageBody("Body2")); _sqlMessageStore.Add(message2); _messageLatest = new Message(new MessageHeader(Guid.NewGuid(), "Test3", MessageType.MT_COMMAND, DateTime.UtcNow.AddHours(-1)), new MessageBody("Body3")); _sqlMessageStore.Add(_messageLatest); }
internal static void ConfigureDependencies(TinyIoCContainer container, MessageViewerConfiguration config) { var messageStore = new MsSqlMessageStore( new MsSqlMessageStoreConfiguration("Server=.;Database=brighterMessageStore;Trusted_Connection=True", "messages", MsSqlMessageStoreConfiguration.DatabaseType.MsSqlServer)); container.Register(messageStore); container.Register(typeof (IMessageStoreConfigProvider), typeof (MessageStoreConfigProvider)); container.Register(typeof (IMessageStoreViewerFactory), typeof (MessageStoreViewerFactory)); container.Register(typeof(IHandleCommand<RepostCommand>), typeof (RepostCommandHandler)); container.Register(typeof (IAmAMessageRecoverer), typeof (MessageRecoverer)); container.Register<MessageViewerConfiguration>(config); var factory = new HandlerFactory(); factory.Add(container.Resolve<RepostCommandHandler>()); container.Register<IHandlerFactory>(factory); }
protected override void ConfigureApplicationContainer(TinyIoCContainer container) { base.ConfigureApplicationContainer(container); var logger = LogProvider.GetLogger(this.GetType().Namespace); container.Register(logger); var subscriberRegistry = new SubscriberRegistry(); subscriberRegistry.Register <AddTaskCommand, AddTaskCommandHandler>(); subscriberRegistry.Register <CompleteTaskCommand, CompleteTaskCommandHandler>(); container.Register <IHandleRequests <AddTaskCommand>, AddTaskCommandHandler>().AsMultiInstance(); container.Register <IHandleRequests <CompleteTaskCommand>, CompleteTaskCommandHandler>().AsMultiInstance(); var handlerFactory = new TinyIoCHandlerFactory(container); 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 sqlMessageStore = new MsSqlMessageStore(new MsSqlMessageStoreConfiguration("Data Source=|DataDirectory|Tasks.sdf;Persist Security Info=False;", "messages", MsSqlMessageStoreConfiguration.DatabaseType.SqlCe), logger); var gateway = new AzureServiceBusMessageProducer(logger); container.Register <IAmAMessageMapper <TaskReminderCommand>, TaskReminderCommandMessageMapper>().AsMultiInstance(); var messageMapperFactory = new TinyIoCMessageMapperFactory(container); var messageMapperRegistry = new MessageMapperRegistry(messageMapperFactory); messageMapperRegistry.Add(typeof(TaskReminderCommand), typeof(TaskReminderCommandMessageMapper)); messageMapperRegistry.Add(typeof(TaskCompletedEvent), typeof(TaskCompletedEventMapper)); var commandProcessor = CommandProcessorBuilder .With() .Handlers(new HandlerConfiguration(subscriberRegistry, handlerFactory)) .Policies(policyRegistry) .TaskQueues(new MessagingConfiguration(sqlMessageStore, gateway, messageMapperRegistry)) .RequestContextFactory(new InMemoryRequestContextFactory()) .Build(); container.Register <IAmACommandProcessor>(commandProcessor); }
internal static void ConfigureDependencies(TinyIoCContainer container, MessageViewerConfiguration config) { var messageStore = new MsSqlMessageStore( new MsSqlMessageStoreConfiguration("Server=.;Database=brighterMessageStore;Trusted_Connection=True", "messages", MsSqlMessageStoreConfiguration.DatabaseType.MsSqlServer)); container.Register(messageStore); container.Register(typeof(IMessageStoreConfigProvider), typeof(MessageStoreConfigProvider)); container.Register(typeof(IMessageStoreViewerFactory), typeof(MessageStoreViewerFactory)); container.Register(typeof(IHandleCommand <RepostCommand>), typeof(RepostCommandHandler)); container.Register(typeof(IAmAMessageRecoverer), typeof(MessageRecoverer)); container.Register <MessageViewerConfiguration>(config); var factory = new HandlerFactory(); factory.Add(container.Resolve <RepostCommandHandler>()); container.Register <IHandlerFactory>(factory); }
internal static void ConfigureDependencies(TinyIoCContainer container) { var logger = LogProvider.GetLogger("MainNancyModule"); logger.Log(LogLevel.Debug, () => "GET on messages"); var messageStore = new MsSqlMessageStore( new MsSqlMessageStoreConfiguration("Server=.;Database=brighterMessageStore;Trusted_Connection=True", "messages", MsSqlMessageStoreConfiguration.DatabaseType.MsSqlServer), logger); container.Register(messageStore); container.Register(typeof (IMessageStoreConfigProvider), typeof (MessageStoreConfigProvider)); container.Register(typeof (IMessageStoreViewerFactory), typeof (MessageStoreViewerFactory)); container.Register(typeof(IHandleCommand<RepostCommand>), typeof (RepostCommandHandler)); container.Register(typeof (IAmAMessageRecoverer), typeof (MessageRecoverer)); var factory= new HandlerFactory(); factory.Add(container.Resolve<RepostCommandHandler>()); container.Register<IHandlerFactory>(factory); }
public void Establish() { _msSqlTestHelper = new MsSqlTestHelper(); _msSqlTestHelper.SetupMessageDb(); _sqlMessageStore = new MsSqlMessageStore(_msSqlTestHelper.MessageStoreConfiguration); Clock.OverrideTime = DateTime.UtcNow.AddHours(-3); _messageEarliest = new Message(new MessageHeader(Guid.NewGuid(), "Test", MessageType.MT_COMMAND), new MessageBody("Body")); AsyncContext.Run(async () => await _sqlMessageStore.AddAsync(_messageEarliest)); Clock.OverrideTime = DateTime.UtcNow.AddHours(-2); _message2 = new Message(new MessageHeader(Guid.NewGuid(), "Test2", MessageType.MT_COMMAND), new MessageBody("Body2")); AsyncContext.Run(async () => await _sqlMessageStore.AddAsync(_message2)); Clock.OverrideTime = DateTime.UtcNow.AddHours(-1); _messageLatest = new Message(new MessageHeader(Guid.NewGuid(), "Test3", MessageType.MT_COMMAND),new MessageBody("Body3")); AsyncContext.Run(async () => await _sqlMessageStore.AddAsync(_messageLatest)); }
private async static Task AddHistoricMessage(MsSqlMessageStore sSqlMessageStore, Message message) { var sql = string.Format("INSERT INTO {0} (MessageId, MessageType, Topic, Body) VALUES (@MessageId, @MessageType, @Topic, @Body)", TableName); var parameters = new[] { new SqlCeParameter("MessageId", message.Id), new SqlCeParameter("MessageType", message.Header.MessageType.ToString()), new SqlCeParameter("Topic", message.Header.Topic), new SqlCeParameter("Body", message.Body.Value), }; using (var connection = new SqlCeConnection(ConnectionString)) using (var command = connection.CreateCommand()) { await connection.OpenAsync(); command.CommandText = sql; command.Parameters.AddRange(parameters); await command.ExecuteNonQueryAsync(); } }
private CommandProcessor CommandProcessorRegistrar(TinyIoCContainer container, ILog logger) { //Database dao container.Register<ITasksDAO, TasksDAO>().AsSingleton(); //create handler var handlerFactory = new TinyIocHandlerFactory(container); var subscriberRegistry = new SubscriberRegistry(); container.Register<IHandleRequests<AddTaskCommand>, AddTaskCommandHandler>().AsMultiInstance(); subscriberRegistry.Register<AddTaskCommand, AddTaskCommandHandler>(); //complete handler container.Register<IHandleRequests<CompleteTaskCommand>, CompleteTaskCommandHandler>().AsMultiInstance(); subscriberRegistry.Register<CompleteTaskCommand, CompleteTaskCommandHandler>(); //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 container.Register<IAmAMessageMapper<TaskReminderCommand>, TaskReminderCommandMessageMapper>().AsMultiInstance(); var messageMapperFactory = new TinyIoCMessageMapperFactory(container); var messageMapperRegistry = new MessageMapperRegistry(messageMapperFactory); messageMapperRegistry.Add(typeof(TaskReminderCommand), typeof(TaskReminderCommandMessageMapper)); var gateway = new RmqMessageProducer(logger); IAmAMessageStore<Message> sqlMessageStore = new MsSqlMessageStore(new MsSqlMessageStoreConfiguration("Server=.;Database=brighterMessageStore;Trusted_Connection=True", "messages", MsSqlMessageStoreConfiguration.DatabaseType.MsSqlServer), logger); var commandProcessor = CommandProcessorBuilder.With() .Handlers(new HandlerConfiguration(subscriberRegistry, handlerFactory)) .Policies(policyRegistry) .Logger(logger) .TaskQueues(new MessagingConfiguration(sqlMessageStore, gateway, messageMapperRegistry)) .RequestContextFactory(new InMemoryRequestContextFactory()) .Build(); return commandProcessor; }
internal static void ConfigureDependencies(TinyIoCContainer container) { var logger = LogProvider.GetLogger("MainNancyModule"); logger.Log(LogLevel.Debug, () => "GET on messages"); var messageStore = new MsSqlMessageStore( new MsSqlMessageStoreConfiguration("Server=.;Database=brighterMessageStore;Trusted_Connection=True", "messages", MsSqlMessageStoreConfiguration.DatabaseType.MsSqlServer), logger); container.Register(messageStore); container.Register(typeof(IMessageStoreConfigProvider), typeof(MessageStoreConfigProvider)); container.Register(typeof(IMessageStoreViewerFactory), typeof(MessageStoreViewerFactory)); container.Register(typeof(IHandleCommand <RepostCommand>), typeof(RepostCommandHandler)); container.Register(typeof(IAmAMessageRecoverer), typeof(MessageRecoverer)); var factory = new HandlerFactory(); factory.Add(container.Resolve <RepostCommandHandler>()); container.Register <IHandlerFactory>(factory); }