public async Task Add_Different_Handler_Per_Queue() { // Arrange string group1 = "group1"; string group2 = "group2"; string queueName1 = "queue1"; string queueName2 = "queue2"; JustSaying.JustSayingBus bus = CreateBus(); var handler1 = new InspectableHandler <TestJustSayingMessage>(); var handler2 = new InspectableHandler <TestJustSayingMessage>(); bus.AddMessageHandler(queueName1, () => handler1); bus.AddMessageHandler(queueName2, () => handler2); ISqsQueue queue1 = TestQueue(bus.SerializationRegister, queueName1); ISqsQueue queue2 = TestQueue(bus.SerializationRegister, queueName2); bus.AddQueue(group1, queue1); bus.AddQueue(group2, queue2); using var cts = new CancellationTokenSource(); // Act await bus.StartAsync(cts.Token); await Patiently.AssertThatAsync(_outputHelper, () => { handler1.ReceivedMessages.Count.ShouldBeGreaterThan(0); handler2.ReceivedMessages.Count.ShouldBeGreaterThan(0); }); cts.Cancel(); await bus.Completion; foreach (var message in handler1.ReceivedMessages) { message.QueueName.ShouldBe(queueName1); } foreach (var message in handler2.ReceivedMessages) { message.QueueName.ShouldBe(queueName2); } bus.Dispose(); }
public async Task Add_Different_Handler_Per_Queue() { // Arrange string group1 = "group1"; string group2 = "group2"; string region = "region"; string queueName1 = "queue1"; string queueName2 = "queue2"; JustSaying.JustSayingBus bus = CreateBus(); ISqsQueue queue1 = TestQueue(bus.SerializationRegister, queueName1); ISqsQueue queue2 = TestQueue(bus.SerializationRegister, queueName2); bus.AddQueue(region, group1, queue1); bus.AddQueue(region, group2, queue2); var handledBy1 = new List <TestJustSayingMessage>(); var handledBy2 = new List <TestJustSayingMessage>(); bus.AddMessageHandler(queueName1, () => new TestHandler <TestJustSayingMessage>(x => handledBy1.Add(x))); bus.AddMessageHandler(queueName2, () => new TestHandler <TestJustSayingMessage>(x => handledBy2.Add(x))); var cts = new CancellationTokenSource(); cts.CancelAfter(TimeoutPeriod); // Act await bus.StartAsync(cts.Token); await cts.Token.WaitForCancellation(); // Assert handledBy1.Count.ShouldBeGreaterThan(0); foreach (var message in handledBy1) { message.QueueName.ShouldBe(queueName1); } handledBy2.Count.ShouldBeGreaterThan(0); foreach (var message in handledBy2) { message.QueueName.ShouldBe(queueName2); } }