コード例 #1
0
        public void Establish()
        {
            var fakeStore = new FakeMessageStoreWithViewer();

            _messageToRepost = new Message(new MessageHeader(Guid.NewGuid(), "a topic", MessageType.MT_COMMAND, DateTime.UtcNow), new MessageBody("body"));
            fakeStore.Add(_messageToRepost);
            var fakeMessageStoreFactory = new FakeMessageStoreViewerFactory(fakeStore, _storeName);

            _command = new RepostCommand {
                MessageIds = new List <string> {
                    _messageToRepost.Header.Id.ToString()
                }, StoreName = _storeName
            };
            _fakeMessageProducer = new FakeMessageProducer();
            _repostHandler       = new RepostCommandHandler(fakeMessageStoreFactory, new FakeMessageProducerFactoryProvider(new FakeMessageProducerFactory(_fakeMessageProducer)), new MessageRecoverer());
        }
コード例 #2
0
        public CommandProcessorPostBoxImplicitClearAsyncTests()
        {
            var myCommand = new MyCommand {
                Value = "Hello World"
            };

            _fakeOutboxSync      = new FakeOutboxSync();
            _fakeMessageProducer = new FakeMessageProducer();

            const string topic = "MyCommand";

            _message = new Message(
                new MessageHeader(myCommand.Id, topic, MessageType.MT_COMMAND),
                new MessageBody(JsonSerializer.Serialize(myCommand, JsonSerialisationOptions.Options))
                );

            _message2 = new Message(
                new MessageHeader(Guid.NewGuid(), topic, MessageType.MT_COMMAND),
                new MessageBody(JsonSerializer.Serialize(myCommand, JsonSerialisationOptions.Options))
                );

            var messageMapperRegistry = new MessageMapperRegistry(new SimpleMessageMapperFactory((_) => new MyCommandMessageMapper()));

            messageMapperRegistry.Register <MyCommand, MyCommandMessageMapper>();

            var retryPolicy = Policy
                              .Handle <Exception>()
                              .RetryAsync();

            var circuitBreakerPolicy = Policy
                                       .Handle <Exception>()
                                       .CircuitBreakerAsync(1, TimeSpan.FromMilliseconds(1));

            _commandProcessor = new CommandProcessor(
                new InMemoryRequestContextFactory(),
                new PolicyRegistry {
                { CommandProcessor.RETRYPOLICYASYNC, retryPolicy }, { CommandProcessor.CIRCUITBREAKERASYNC, circuitBreakerPolicy }
            },
                messageMapperRegistry,
                _fakeOutboxSync,
                new ProducerRegistry(new Dictionary <string, IAmAMessageProducer>()
            {
                { topic, _fakeMessageProducer },
            }));
        }
コード例 #3
0
        public void Establish()
        {
            _myCommand.Value = "Hello World";

            _fakeMessageStore    = new FakeMessageStore();
            _fakeMessageProducer = new FakeMessageProducer();

            _message = new Message(
                header: new MessageHeader(messageId: _myCommand.Id, topic: "MyCommand", messageType: MessageType.MT_COMMAND),
                body: new MessageBody(JsonConvert.SerializeObject(_myCommand))
                );

            var messageMapperRegistry = new MessageMapperRegistry(new SimpleMessageMapperFactory(() => new MyCommandMessageMapper()));

            messageMapperRegistry.Register <MyCommand, MyCommandMessageMapper>();

            var retryPolicy = Policy
                              .Handle <Exception>()
                              .RetryAsync();

            var circuitBreakerPolicy = Policy
                                       .Handle <Exception>()
                                       .CircuitBreakerAsync(1, TimeSpan.FromMilliseconds(1));

            _commandProcessor = new CommandProcessor(
                new InMemoryRequestContextFactory(),
                new PolicyRegistry()
            {
                { CommandProcessor.RETRYPOLICYASYNC, retryPolicy }, { CommandProcessor.CIRCUITBREAKERASYNC, circuitBreakerPolicy }
            },
                messageMapperRegistry,
                (IAmAMessageStoreAsync <Message>)_fakeMessageStore,
                (IAmAMessageProducerAsync)_fakeMessageProducer);

            _controlBusSender = new ControlBusSender(_commandProcessor);
        }
コード例 #4
0
        public PostCommandTests()
        {
            _myCommand.Value = "Hello World";

            _fakeOutbox          = new FakeOutbox();
            _fakeMessageProducer = new FakeMessageProducer();

            _message = new Message(
                new MessageHeader(_myCommand.Id, "MyCommand", MessageType.MT_COMMAND),
                new MessageBody(JsonSerializer.Serialize(_myCommand, JsonSerialisationOptions.Options))
                );

            var messageMapperRegistry =
                new MessageMapperRegistry(new SimpleMessageMapperFactory((_) => new MyCommandMessageMapper()));

            messageMapperRegistry.Register <MyCommand, MyCommandMessageMapper>();

            _commandProcessor = CommandProcessorBuilder.With()
                                .Handlers(new HandlerConfiguration(new SubscriberRegistry(), new EmptyHandlerFactory()))
                                .DefaultPolicy()
                                .TaskQueues(new MessagingConfiguration((IAmAMessageProducer)_fakeMessageProducer, messageMapperRegistry), _fakeOutbox)
                                .RequestContextFactory(new InMemoryRequestContextFactory())
                                .Build();
        }
        public CommandProcessorCallTests()
        {
            _myRequest.RequestValue = "Hello World";

            _fakeMessageProducer = new FakeMessageProducer();

            var header = new MessageHeader(
                messageId: _myRequest.Id,
                topic: "MyRequest",
                messageType: MessageType.MT_COMMAND,
                correlationId: _myRequest.ReplyAddress.CorrelationId,
                replyTo: _myRequest.ReplyAddress.Topic);

            var json = new JObject(new JProperty("Id", _myRequest.Id), new JProperty("RequestValue", _myRequest.RequestValue));
            var body = new MessageBody(json.ToString());

            _message = new Message(header, body);

            var messageMapperRegistry = new MessageMapperRegistry(new SimpleMessageMapperFactory((type) =>
            {
                if (type == typeof(MyRequestMessageMapper))
                {
                    return(new MyRequestMessageMapper());
                }
                if (type == typeof(MyResponseMessageMapper))
                {
                    return(new MyResponseMessageMapper());
                }

                throw new ConfigurationException($"No mapper found for {type.Name}");
            }));

            messageMapperRegistry.Register <MyRequest, MyRequestMessageMapper>();
            messageMapperRegistry.Register <MyResponse, MyResponseMessageMapper>();

            var subscriberRegistry = new SubscriberRegistry();

            subscriberRegistry.Register <MyResponse, MyResponseHandler>();
            var handlerFactory = new TestHandlerFactory <MyResponse, MyResponseHandler>(() => new MyResponseHandler());

            var retryPolicy = Policy
                              .Handle <Exception>()
                              .Retry();

            var circuitBreakerPolicy = Policy
                                       .Handle <Exception>()
                                       .CircuitBreaker(1, TimeSpan.FromMilliseconds(1));

            InMemoryChannelFactory inMemoryChannelFactory = new InMemoryChannelFactory();

            //we need to seed the response as the fake producer does not actually send across the wire
            inMemoryChannelFactory.SeedChannel(new[] { _message });

            _commandProcessor = new CommandProcessor(
                subscriberRegistry,
                handlerFactory,
                new InMemoryRequestContextFactory(),
                new PolicyRegistry {
                { CommandProcessor.RETRYPOLICY, retryPolicy }, { CommandProcessor.CIRCUITBREAKER, circuitBreakerPolicy }
            },
                messageMapperRegistry,
                (IAmAMessageProducer)_fakeMessageProducer,
                responseChannelFactory: inMemoryChannelFactory);

            PipelineBuilder <MyRequest> .ClearPipelineCache();
        }