Example #1
0
 public MySqlMessageStoreEmptyStoreTests()
 {
     _mySqlTestHelper = new MySqlTestHelper();
     _mySqlTestHelper.SetupMessageDb();
     _mySqlMessageStore = new MySqlMessageStore(_mySqlTestHelper.MessageStoreConfiguration);
     _messageEarliest   = new Message(new MessageHeader(Guid.NewGuid(), "test_topic", MessageType.MT_DOCUMENT),
                                      new MessageBody("message body"));
 }
Example #2
0
 public MySqlMessageStoreRangeRequestAsyncTests()
 {
     _mySqlTestHelper = new MySqlTestHelper();
     _mySqlTestHelper.SetupMessageDb();
     _mySqlMessageStore = new MySqlMessageStore(_mySqlTestHelper.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"));
 }
        private void RegisterCommandProcessor()
        {
            //create handler
            var subscriberRegistry = new SubscriberRegistry();

            RegisterBrighterHandlersFromAssembly(
                typeof(IHandleRequestsAsync <>),
                new Assembly[] { typeof(NewShipRegistrationHandlerAsync).Assembly },
                typeof(IHandleRequestsAsync <>).GetTypeInfo().Assembly,
                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 retryPolicyAsync          = Policy.Handle <Exception>().WaitAndRetryAsync(new[] { TimeSpan.FromMilliseconds(50), TimeSpan.FromMilliseconds(100), TimeSpan.FromMilliseconds(150) });
            var circuitBreakerPolicyAsync = Policy.Handle <Exception>().CircuitBreakerAsync(1, TimeSpan.FromMilliseconds(500));
            var policyRegistry            = new Paramore.Brighter.PolicyRegistry()
            {
                { CommandProcessor.RETRYPOLICY, retryPolicy },
                { CommandProcessor.CIRCUITBREAKER, circuitBreakerPolicy },
                { CommandProcessor.RETRYPOLICYASYNC, retryPolicyAsync },
                { CommandProcessor.CIRCUITBREAKERASYNC, circuitBreakerPolicyAsync }
            };

            var servicesHandlerFactory = new ServicesHandlerFactoryAsync(_container);

            var messagingGatewayConfiguration = RmqGatewayBuilder.With.Uri(new Uri(Configuration["Broker:Uri"]))
                                                .Exchange(Configuration["Broker:Exchange"])
                                                .DefaultQueues();

            var gateway         = new RmqMessageProducer(messagingGatewayConfiguration);
            var sqlMessageStore = new MySqlMessageStore(new MySqlMessageStoreConfiguration(Configuration["Database:MessageStore"], Configuration["Database:MessageTableName"]));

            var messageMapperFactory = new MessageMapperFactory(_container);

            var messageMapperRegistry = new MessageMapperRegistry(messageMapperFactory);

            RegisterMessageMappersFromAssembly(
                new Assembly[] { typeof(LineNameUpdatedEventMessageMapper).Assembly },
                typeof(IAmAMessageMapper <>).GetTypeInfo().Assembly,
                messageMapperRegistry);

            var messagingConfiguration = new MessagingConfiguration(
                messageStore: sqlMessageStore,
                messageProducer: gateway,
                messageMapperRegistry: messageMapperRegistry);

            var commandProcessor = CommandProcessorBuilder.With()
                                   .Handlers(new Paramore.Brighter.HandlerConfiguration(subscriberRegistry, servicesHandlerFactory))
                                   .Policies(policyRegistry)
                                   .TaskQueues(messagingConfiguration)
                                   .RequestContextFactory(new Paramore.Brighter.InMemoryRequestContextFactory())
                                   .Build();

            _container.RegisterInstance <IAmACommandProcessor>(commandProcessor);
        }
Example #4
0
        public MySqlMessageStoreWritingMessageAsyncTests()
        {
            _mySqlTestHelper = new MySqlTestHelper();
            _mySqlTestHelper.SetupMessageDb();
            _mySqlMessageStore = new MySqlMessageStore(_mySqlTestHelper.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"));
        }
Example #5
0
        public MySqlMessageStoreWritngMessagesTests()
        {
            _mySqlTestHelper = new MySqlTestHelper();
            _mySqlTestHelper.SetupMessageDb();
            _mySqlMessageStore = new MySqlMessageStore(_mySqlTestHelper.MessageStoreConfiguration);

            _messageEarliest = new Message(new MessageHeader(Guid.NewGuid(), "Test", MessageType.MT_COMMAND, DateTime.UtcNow.AddHours(-3)), new MessageBody("Body"));
            _mySqlMessageStore.Add(_messageEarliest);

            var message2 = new Message(new MessageHeader(Guid.NewGuid(), "Test2", MessageType.MT_COMMAND, DateTime.UtcNow.AddHours(-2)), new MessageBody("Body2"));

            _mySqlMessageStore.Add(message2);

            _messageLatest = new Message(new MessageHeader(Guid.NewGuid(), "Test3", MessageType.MT_COMMAND, DateTime.UtcNow.AddHours(-1)), new MessageBody("Body3"));
            _mySqlMessageStore.Add(_messageLatest);
        }
Example #6
0
        private void RegisterCommandProcessor()
        {
            //create handler
            var subscriberRegistry = new SubscriberRegistry();

            _container.Register <IHandleRequestsAsync <AddToDoCommand>, AddToDoCommandHandlerAsync>(Lifestyle.Scoped);
            _container.Register <IHandleRequestsAsync <DeleteAllToDosCommand>, DeleteAllToDosCommandHandlerAsync>(Lifestyle.Scoped);
            _container.Register <IHandleRequestsAsync <DeleteToDoByIdCommand>, DeleteToDoByIdCommandHandlerAsync>(Lifestyle.Scoped);
            _container.Register <IHandleRequestsAsync <UpdateToDoCommand>, UpdateToDoCommandHandlerAsync>(Lifestyle.Scoped);

            subscriberRegistry.RegisterAsync <AddToDoCommand, AddToDoCommandHandlerAsync>();
            subscriberRegistry.RegisterAsync <DeleteAllToDosCommand, DeleteAllToDosCommandHandlerAsync>();
            subscriberRegistry.RegisterAsync <DeleteToDoByIdCommand, DeleteToDoByIdCommandHandlerAsync>();
            subscriberRegistry.RegisterAsync <UpdateToDoCommand, UpdateToDoCommandHandlerAsync>();

            //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 retryPolicyAsync          = Policy.Handle <Exception>().WaitAndRetryAsync(new[] { TimeSpan.FromMilliseconds(50), TimeSpan.FromMilliseconds(100), TimeSpan.FromMilliseconds(150) });
            var circuitBreakerPolicyAsync = Policy.Handle <Exception>().CircuitBreakerAsync(1, TimeSpan.FromMilliseconds(500));
            var policyRegistry            = new PolicyRegistry()
            {
                { CommandProcessor.RETRYPOLICY, retryPolicy },
                { CommandProcessor.CIRCUITBREAKER, circuitBreakerPolicy },
                { CommandProcessor.RETRYPOLICYASYNC, retryPolicyAsync },
                { CommandProcessor.CIRCUITBREAKERASYNC, circuitBreakerPolicyAsync }
            };

            var servicesHandlerFactory = new ServicesHandlerFactoryAsync(_container);

            var messagingGatewayConfiguration = RmqGatewayBuilder.With.Uri(new Uri(Configuration["RabbitMQ:Uri"])).Exchange(Configuration["RabbitMQ:Exchange"]).DefaultQueues();

            var gateway         = new RmqMessageProducer(messagingGatewayConfiguration);
            var sqlMessageStore = new MySqlMessageStore(new MySqlMessageStoreConfiguration(Configuration["Database:MessageStore"], Configuration["Database:MessageTableName"]));

            var messageMapperFactory = new MessageMapperFactory(_container);

            _container.Register <IAmAMessageMapper <BulkAddToDoCommand>, BulkAddToDoMessageMapper>();
            _container.Register <IAmAMessageMapper <TaskCompletedEvent>, TaskCompleteEventMessageMapper>();
            _container.Register <IAmAMessageMapper <TaskCreatedEvent>, TaskCreatedEventMessageMapper>();

            var messageMapperRegistry = new MessageMapperRegistry(messageMapperFactory)
            {
                { typeof(BulkAddToDoCommand), typeof(BulkAddToDoMessageMapper) },
                { typeof(TaskCompletedEvent), typeof(TaskCompleteEventMessageMapper) },
                { typeof(TaskCreatedEvent), typeof(TaskCreatedEventMessageMapper) }
            };

            var messagingConfiguration = new MessagingConfiguration(
                messageStore: sqlMessageStore,
                messageProducer: gateway,
                messageMapperRegistry: messageMapperRegistry);

            var commandProcessor = CommandProcessorBuilder.With()
                                   .Handlers(new Paramore.Brighter.HandlerConfiguration(subscriberRegistry, servicesHandlerFactory))
                                   .Policies(policyRegistry)
                                   .TaskQueues(messagingConfiguration)
                                   .RequestContextFactory(new Paramore.Brighter.InMemoryRequestContextFactory())
                                   .Build();

            _container.RegisterSingleton <IAmACommandProcessor>(commandProcessor);
        }
 public MySqlMessageStoreWritngMessagesAsyncTests()
 {
     _mySqlTestHelper = new MySqlTestHelper();
     _mySqlTestHelper.SetupMessageDb();
     _mySqlMessageStore = new MySqlMessageStore(_mySqlTestHelper.MessageStoreConfiguration);
 }