public void Establish() { var subscriberRegistry = new SubscriberRegistry(); subscriberRegistry.Register <MyEvent, MyEventHandler>(); _commandProcessor = new CommandProcessor( subscriberRegistry, new CheapHandlerFactory(), new InMemoryRequestContextFactory(), new PolicyRegistry()); _channel = new FakeChannel(); var mapper = new MyEventMessageMapper(); _messagePump = new MessagePump <MyEvent>(_commandProcessor, mapper) { Channel = _channel, TimeoutInMilliseconds = 5000 }; _event = new MyEvent(); var message = new Message(new MessageHeader(Guid.NewGuid(), "MyTopic", MessageType.MT_EVENT), new MessageBody(JsonConvert.SerializeObject(_event))); _channel.Add(message); var quitMessage = new Message(new MessageHeader(Guid.Empty, "", MessageType.MT_QUIT), new MessageBody("")); _channel.Add(quitMessage); }
public MessagePumpRetryCommandOnConnectionFailureTests() { _commandProcessor = new SpyCommandProcessor(); var channel = new FailingChannel { NumberOfRetries = 1 }; var mapper = new MyCommandMessageMapper(); _messagePump = new MessagePump <MyCommand>(_commandProcessor, mapper) { Channel = channel, TimeoutInMilliseconds = 500, RequeueCount = -1 }; var command = new MyCommand(); //two command, will be received when connection restored var message1 = new Message(new MessageHeader(Guid.NewGuid(), "MyTopic", MessageType.MT_COMMAND), new MessageBody(JsonConvert.SerializeObject(command))); var message2 = new Message(new MessageHeader(Guid.NewGuid(), "MyTopic", MessageType.MT_COMMAND), new MessageBody(JsonConvert.SerializeObject(command))); channel.Enqueue(message1); channel.Enqueue(message2); //end the pump var quitMessage = new Message(new MessageHeader(Guid.Empty, "", MessageType.MT_QUIT), new MessageBody("")); channel.Enqueue(quitMessage); }
public Performer( IAmAChannel channel, IAmAMessagePump messagePump) { _channel = channel; _messagePump = messagePump; }
public MessagePumpDispatchAsyncTests() { var subscriberRegistry = new SubscriberRegistry(); subscriberRegistry.RegisterAsync <MyEvent, MyEventHandlerAsyncWithContinuation>(); var handlerFactory = new TestHandlerFactoryAsync <MyEvent, MyEventHandlerAsyncWithContinuation>(() => new MyEventHandlerAsyncWithContinuation()); var commandProcessor = new CommandProcessor( subscriberRegistry, handlerFactory, new InMemoryRequestContextFactory(), new PolicyRegistry()); var channel = new FakeChannel(); var mapper = new MyEventMessageMapper(); _messagePump = new MessagePumpAsync <MyEvent>(commandProcessor, mapper) { Channel = channel, TimeoutInMilliseconds = 5000 }; var message = new Message(new MessageHeader(Guid.NewGuid(), "MyTopic", MessageType.MT_EVENT), new MessageBody(JsonConvert.SerializeObject(_myEvent))); channel.Add(message); var quitMessage = new Message(new MessageHeader(Guid.Empty, "", MessageType.MT_QUIT), new MessageBody("")); channel.Add(quitMessage); }
public MessagePumpDispatchTests() { var subscriberRegistry = new SubscriberRegistry(); subscriberRegistry.Register <MyEvent, MyEventHandler>(); var handlerFactory = new TestHandlerFactory <MyEvent, MyEventHandler>(() => new MyEventHandler(_receivedMessages)); var commandProcessor = new CommandProcessor( subscriberRegistry, handlerFactory, new InMemoryRequestContextFactory(), new PolicyRegistry()); PipelineBuilder <MyEvent> .ClearPipelineCache(); var channel = new FakeChannel(); var mapper = new MyEventMessageMapper(); _messagePump = new MessagePump <MyEvent>(commandProcessor, mapper) { Channel = channel, TimeoutInMilliseconds = 5000 }; var message = new Message(new MessageHeader(Guid.NewGuid(), "MyTopic", MessageType.MT_EVENT), new MessageBody(JsonSerializer.Serialize(_myEvent, JsonSerialisationOptions.Options))); channel.Enqueue(message); var quitMessage = new Message(new MessageHeader(Guid.Empty, "", MessageType.MT_QUIT), new MessageBody("")); channel.Enqueue(quitMessage); }
public MessagePumpRetryEventConnectionFailureTests() { _commandProcessor = new SpyCommandProcessor(); var channel = new FailingChannel { NumberOfRetries = 1 }; var mapper = new MyEventMessageMapper(); _messagePump = new MessagePump <MyEvent>(_commandProcessor, mapper) { Channel = channel, TimeoutInMilliseconds = 500, RequeueCount = -1 }; var @event = new MyEvent(); //Two events will be received when channel fixed var message1 = new Message(new MessageHeader(Guid.NewGuid(), "MyTopic", MessageType.MT_EVENT), new MessageBody(JsonConvert.SerializeObject(@event))); var message2 = new Message(new MessageHeader(Guid.NewGuid(), "MyTopic", MessageType.MT_EVENT), new MessageBody(JsonConvert.SerializeObject(@event))); channel.Enqueue(message1); channel.Enqueue(message2); //Quit the message pump var quitMessage = new Message(new MessageHeader(Guid.Empty, "", MessageType.MT_QUIT), new MessageBody("")); channel.Enqueue(quitMessage); }
public Performer( IAmAChannel channel, IAmAMessagePump messagePump, bool runAsync = false) { _channel = channel; _messagePump = messagePump; _runAsync = runAsync; }
public MessagePumpUnacceptableMessageTests() { _commandProcessor = new SpyRequeueCommandProcessor(); _channel = new FakeChannel(); var mapper = new MyEventMessageMapper(); _messagePump = new MessagePump <MyEvent>(_commandProcessor, mapper) { Channel = _channel, TimeoutInMilliseconds = 5000, RequeueCount = 3 }; var unacceptableMessage = new Message(new MessageHeader(Guid.NewGuid(), "MyTopic", MessageType.MT_UNACCEPTABLE), new MessageBody("")); _channel.Add(unacceptableMessage); }
public MessagePumpFailingMessageTranslationTests() { _commandProcessor = new SpyRequeueCommandProcessor(); _channel = new FakeChannel(); var mapper = new FailingEventMessageMapper(); _messagePump = new MessagePumpBlocking <MyFailingMapperEvent>(_commandProcessor, mapper) { Channel = _channel, TimeoutInMilliseconds = 5000, RequeueCount = 3, UnacceptableMessageLimit = 3 }; var unmappableMessage = new Message(new MessageHeader(Guid.NewGuid(), "MyTopic", MessageType.MT_EVENT), new MessageBody("{ \"Id\" : \"48213ADB-A085-4AFF-A42C-CF8209350CF7\" }")); _channel.Enqueue(unmappableMessage); }
public MessagePumpEventProcessingExceptionTests() { _commandProcessor = new SpyRequeueCommandProcessor(); _channel = new FakeChannel(); var mapper = new MyEventMessageMapper(); _messagePump = new MessagePumpBlocking <MyEvent>(_commandProcessor, mapper) { Channel = _channel, TimeoutInMilliseconds = 5000, RequeueCount = _requeueCount }; var msg = mapper.MapToMessage(new MyEvent()); _channel.Enqueue(msg); }
public void Establish() { _commandProcessor = new SpyRequeueCommandProcessor(); _channel = new FakeChannel(); var mapper = new MyCommandMessageMapper(); _messagePump = new MessagePump <MyCommand>(_commandProcessor, mapper) { Channel = _channel, TimeoutInMilliseconds = 5000, RequeueCount = 3 }; _command = new MyCommand(); var message1 = new Message(new MessageHeader(Guid.NewGuid(), "MyTopic", MessageType.MT_COMMAND), new MessageBody(JsonConvert.SerializeObject(_command))); var message2 = new Message(new MessageHeader(Guid.NewGuid(), "MyTopic", MessageType.MT_COMMAND), new MessageBody(JsonConvert.SerializeObject(_command))); _channel.Add(message1); _channel.Add(message2); }
public MessagePumpEventRequeueCountThresholdTests() { _commandProcessor = new SpyRequeueCommandProcessor(); _channel = new FakeChannel(); var mapper = new MyEventMessageMapper(); _messagePump = new MessagePump <MyEvent>(_commandProcessor, mapper) { Channel = _channel, TimeoutInMilliseconds = 5000, RequeueCount = 3 }; _event = new MyEvent(); var message1 = new Message(new MessageHeader(Guid.NewGuid(), "MyTopic", MessageType.MT_EVENT), new MessageBody(JsonConvert.SerializeObject(_event))); var message2 = new Message(new MessageHeader(Guid.NewGuid(), "MyTopic", MessageType.MT_EVENT), new MessageBody(JsonConvert.SerializeObject(_event))); _channel.Add(message1); _channel.Add(message2); }
public MessagePumpCommandRequeueCountThresholdTests() { _commandProcessor = new SpyRequeueCommandProcessor(); _channel = new FakeChannel(); var mapper = new MyCommandMessageMapper(); _messagePump = new MessagePumpBlocking <MyCommand>(_commandProcessor, mapper) { Channel = _channel, TimeoutInMilliseconds = 5000, RequeueCount = 3 }; _command = new MyCommand(); var message1 = new Message(new MessageHeader(Guid.NewGuid(), "MyTopic", MessageType.MT_COMMAND), new MessageBody(JsonSerializer.Serialize(_command, JsonSerialisationOptions.Options))); var message2 = new Message(new MessageHeader(Guid.NewGuid(), "MyTopic", MessageType.MT_COMMAND), new MessageBody(JsonSerializer.Serialize(_command, JsonSerialisationOptions.Options))); _channel.Enqueue(message1); _channel.Enqueue(message2); }
public MessagePumpToCommandProcessorTests() { _commandProcessor = new SpyCommandProcessor(); _channel = new FakeChannel(); var mapper = new MyEventMessageMapper(); _messagePump = new MessagePump <MyEvent>(_commandProcessor, mapper) { Channel = _channel, TimeoutInMilliseconds = 5000 }; _event = new MyEvent(); var message = new Message(new MessageHeader(Guid.NewGuid(), "MyTopic", MessageType.MT_EVENT), new MessageBody(JsonSerializer.Serialize(_event, JsonSerialisationOptions.Options))); _channel.Enqueue(message); var quitMessage = new Message(new MessageHeader(Guid.Empty, "", MessageType.MT_QUIT), new MessageBody("")); _channel.Enqueue(quitMessage); }
public void Establish() { _commandProcessor = new SpyCommandProcessor(); _channel = new FakeChannel(); var mapper = new MyEventMessageMapper(); _messagePump = new MessagePump <MyEvent>(_commandProcessor, mapper) { Channel = _channel, TimeoutInMilliseconds = 5000 }; _event = new MyEvent(); var message = new Message(new MessageHeader(Guid.NewGuid(), "MyTopic", MessageType.MT_EVENT), new MessageBody(JsonConvert.SerializeObject(_event))); _channel.Add(message); var quitMessage = new Message(new MessageHeader(Guid.Empty, "", MessageType.MT_QUIT), new MessageBody("")); _channel.Add(quitMessage); }
public MessagePumpCommandRequeueTests() { _commandProcessor = new SpyRequeueCommandProcessor(); _channel = new FakeChannel(); var mapper = new MyCommandMessageMapper(); _messagePump = new MessagePump <MyCommand>(_commandProcessor, mapper) { Channel = _channel, TimeoutInMilliseconds = 5000, RequeueCount = -1 }; var message1 = new Message(new MessageHeader(Guid.NewGuid(), "MyTopic", MessageType.MT_COMMAND), new MessageBody(JsonSerializer.Serialize(_command, JsonSerialisationOptions.Options))); var message2 = new Message(new MessageHeader(Guid.NewGuid(), "MyTopic", MessageType.MT_COMMAND), new MessageBody(JsonSerializer.Serialize(_command, JsonSerialisationOptions.Options))); _channel.Enqueue(message1); _channel.Enqueue(message2); var quitMessage = new Message(new MessageHeader(Guid.Empty, "", MessageType.MT_QUIT), new MessageBody("")); _channel.Enqueue(quitMessage); }
public MessagePumpUnacceptableMessageLimitBreachedTests() { _commandProcessor = new SpyRequeueCommandProcessor(); _channel = new FakeChannel(); var mapper = new MyEventMessageMapper(); _messagePump = new MessagePumpBlocking <MyEvent>(_commandProcessor, mapper) { Channel = _channel, TimeoutInMilliseconds = 5000, RequeueCount = 3, UnacceptableMessageLimit = 3 }; var unacceptableMessage1 = new Message(new MessageHeader(Guid.NewGuid(), "MyTopic", MessageType.MT_UNACCEPTABLE), new MessageBody("")); var unacceptableMessage2 = new Message(new MessageHeader(Guid.NewGuid(), "MyTopic", MessageType.MT_UNACCEPTABLE), new MessageBody("")); var unacceptableMessage3 = new Message(new MessageHeader(Guid.NewGuid(), "MyTopic", MessageType.MT_UNACCEPTABLE), new MessageBody("")); var unacceptableMessage4 = new Message(new MessageHeader(Guid.NewGuid(), "MyTopic", MessageType.MT_UNACCEPTABLE), new MessageBody("")); _channel.Enqueue(unacceptableMessage1); _channel.Enqueue(unacceptableMessage2); _channel.Enqueue(unacceptableMessage3); _channel.Enqueue(unacceptableMessage4); }
public void Establish() { _commandProcessor = new SpyCommandProcessor(); _channel = new FailingChannel { NumberOfRetries = 4 }; var mapper = new MyCommandMessageMapper(); _messagePump = new MessagePump <MyCommand>(_commandProcessor, mapper) { Channel = _channel, TimeoutInMilliseconds = 5000, RequeueCount = -1 }; _command = new MyCommand(); var message1 = new Message(new MessageHeader(Guid.NewGuid(), "MyTopic", MessageType.MT_COMMAND), new MessageBody(JsonConvert.SerializeObject(_command))); var message2 = new Message(new MessageHeader(Guid.NewGuid(), "MyTopic", MessageType.MT_COMMAND), new MessageBody(JsonConvert.SerializeObject(_command))); _channel.Add(message1); _channel.Add(message2); var quitMessage = new Message(new MessageHeader(Guid.Empty, "", MessageType.MT_QUIT), new MessageBody("")); _channel.Add(quitMessage); }
public MessagePumpRetryEventConnectionFailureTests() { _commandProcessor = new SpyCommandProcessor(); _channel = new FailingChannel { NumberOfRetries = 4 }; var mapper = new MyEventMessageMapper(); _messagePump = new MessagePump <MyEvent>(_commandProcessor, mapper) { Channel = _channel, TimeoutInMilliseconds = 5000, RequeueCount = -1 }; _event = new MyEvent(); var message1 = new Message(new MessageHeader(Guid.NewGuid(), "MyTopic", MessageType.MT_EVENT), new MessageBody(JsonConvert.SerializeObject(_event))); var message2 = new Message(new MessageHeader(Guid.NewGuid(), "MyTopic", MessageType.MT_EVENT), new MessageBody(JsonConvert.SerializeObject(_event))); _channel.Add(message1); _channel.Add(message2); var quitMessage = new Message(new MessageHeader(Guid.Empty, "", MessageType.MT_QUIT), new MessageBody("")); _channel.Add(quitMessage); }
public Performer(IAmAnInputChannel channel, IAmAMessagePump messagePump) { this.channel = channel; this.messagePump = messagePump; }
public RMQMessageConsumerRetryDLQTests() { Guid correlationId = Guid.NewGuid(); string contentType = "text\\plain"; var channelName = $"Requeue-Limit-Tests-{Guid.NewGuid().ToString()}"; _topicName = $"Requeue-Limit-Tests-{Guid.NewGuid().ToString()}"; var routingKey = new RoutingKey(_topicName); //what do we send var myCommand = new MyDeferredCommand { Value = "Hello Requeue" }; _message = new Message( new MessageHeader(myCommand.Id, _topicName, MessageType.MT_COMMAND, correlationId, "", contentType), new MessageBody(JsonSerializer.Serialize((object)myCommand, JsonSerialisationOptions.Options)) ); var deadLetterQueueName = $"{_message.Header.Topic}.DLQ"; var deadLetterRoutingKey = $"{_message.Header.Topic}.DLQ"; var subscription = new RmqSubscription <MyCommand>( name: new SubscriptionName(channelName), channelName: new ChannelName(channelName), routingKey: routingKey, //after 2 retries, fail and move to the DLQ requeueCount: 2, //delay before re-queuing requeueDelayInMilliseconds: 50, deadLetterChannelName: new ChannelName(deadLetterQueueName), deadLetterRoutingKey: deadLetterRoutingKey, makeChannels: OnMissingChannel.Create ); var rmqConnection = new RmqMessagingGatewayConnection { AmpqUri = new AmqpUriSpecification(new Uri("amqp://*****:*****@localhost:5672/%2f")), Exchange = new Exchange("paramore.brighter.exchange"), DeadLetterExchange = new Exchange("paramore.brighter.exchange.dlq") }; //how do we send to the queue _sender = new RmqMessageProducer(rmqConnection, new RmqPublication()); //set up our receiver _channelFactory = new ChannelFactory(new RmqMessageConsumerFactory(rmqConnection)); _channel = _channelFactory.CreateChannel(subscription); //how do we handle a command IHandleRequests <MyDeferredCommand> handler = new MyDeferredCommandHandler(); //hook up routing for the command processor var subscriberRegistry = new SubscriberRegistry(); subscriberRegistry.Register <MyDeferredCommand, MyDeferredCommandHandler>(); //once we read, how do we dispatch to a handler. N.B. we don't use this for reading here _commandProcessor = new CommandProcessor( subscriberRegistry: subscriberRegistry, handlerFactory: new QuickHandlerFactory(() => handler), requestContextFactory: new InMemoryRequestContextFactory(), policyRegistry: new PolicyRegistry() ); //pump messages from a channel to a handler - in essence we are building our own dispatcher in this test IAmAMessageMapper <MyDeferredCommand> mapper = new MyDeferredCommandMessageMapper(_topicName); _messagePump = new MessagePumpBlocking <MyDeferredCommand>(_commandProcessor, mapper) { Channel = _channel, TimeoutInMilliseconds = 5000, RequeueCount = 3 }; _deadLetterConsumer = new RmqMessageConsumer( connection: rmqConnection, queueName: deadLetterQueueName, routingKey: deadLetterRoutingKey, isDurable: false, makeChannels: OnMissingChannel.Assume ); }
public Performer(IAmAChannel channel, IAmAMessagePump messagePump) { _channel = channel; _messagePump = messagePump; }
public Consumer(ConnectionName name, IAmAnInputChannel channel, IAmAMessagePump messagePump) { Name = name; Performer = new Performer(channel, messagePump); State = ConsumerState.Shut; }
/// <summary> /// Initializes a new instance of the <see cref="Consumer"/> class. /// </summary> /// <param name="name">The name.</param> /// <param name="subscriptionName">The name of the associated subscription.</param> /// <param name="channel">The channel.</param> /// <param name="messagePump">The message pump.</param> public Consumer(ConsumerName name, SubscriptionName subscriptionName, IAmAChannel channel, IAmAMessagePump messagePump) { Name = name; SubscriptionName = subscriptionName; Performer = new Performer(channel, messagePump); State = ConsumerState.Shut; }
/// <summary> /// Initializes a new instance of the <see cref="Consumer"/> class. /// </summary> /// <param name="name">The name.</param> /// <param name="channel">The channel.</param> /// <param name="messagePump">The message pump.</param> public Consumer(ConnectionName name, IAmAnInputChannel channel, IAmAMessagePump messagePump) { Name = name; Performer = new Performer(channel, messagePump); State = ConsumerState.Shut; }
public SnsReDrivePolicySDlqTests() { Guid correlationId = Guid.NewGuid(); string replyTo = "http:\\queueUrl"; string contentType = "text\\plain"; var channelName = $"Redrive-Tests-{Guid.NewGuid().ToString()}".Truncate(45); _dlqChannelName = $"Redrive-DLQ-Tests-{Guid.NewGuid().ToString()}".Truncate(45); _topicName = $"Redrive-Tests-{Guid.NewGuid().ToString()}".Truncate(45); var routingKey = new RoutingKey(_topicName); //how are we consuming var subscription = new SqsSubscription <MyCommand>( name: new SubscriptionName(channelName), channelName: new ChannelName(channelName), routingKey: routingKey, //don't block the redrive policy from owning retry management requeueCount: -1, //delay before requeuing requeueDelayInMs: 50, //we want our SNS subscription to manage requeue limits using the DLQ for 'too many requeues' redrivePolicy: new RedrivePolicy ( deadLetterQueueName: new ChannelName(_dlqChannelName), maxReceiveCount: 2 )); //what do we send var myCommand = new MyDeferredCommand { Value = "Hello Redrive" }; _message = new Message( new MessageHeader(myCommand.Id, _topicName, MessageType.MT_COMMAND, correlationId, replyTo, contentType), new MessageBody(JsonSerializer.Serialize((object)myCommand, JsonSerialisationOptions.Options)) ); //Must have credentials stored in the SDK Credentials store or shared credentials file (AWSCredentials credentials, RegionEndpoint region) = CredentialsChain.GetAwsCredentials(); _awsConnection = new AWSMessagingGatewayConnection(credentials, region); //how do we send to the queue _sender = new SqsMessageProducer(_awsConnection, new SnsPublication { MakeChannels = OnMissingChannel.Create }); //We need to do this manually in a test - will create the channel from subscriber parameters _channelFactory = new ChannelFactory(_awsConnection); _channel = _channelFactory.CreateChannel(subscription); //how do we handle a command IHandleRequests <MyDeferredCommand> handler = new MyDeferredCommandHandler(); //hook up routing for the command processor var subscriberRegistry = new SubscriberRegistry(); subscriberRegistry.Register <MyDeferredCommand, MyDeferredCommandHandler>(); //once we read, how do we dispatch to a handler. N.B. we don't use this for reading here _commandProcessor = new CommandProcessor( subscriberRegistry: subscriberRegistry, handlerFactory: new QuickHandlerFactory(() => handler), requestContextFactory: new InMemoryRequestContextFactory(), policyRegistry: new PolicyRegistry() ); //pump messages from a channel to a handler - in essence we are building our own dispatcher in this test IAmAMessageMapper <MyDeferredCommand> mapper = new MyDeferredCommandMessageMapper(_topicName); _messagePump = new MessagePumpBlocking <MyDeferredCommand>(_commandProcessor, mapper) { Channel = _channel, TimeoutInMilliseconds = 5000, RequeueCount = 3 }; }