public async Task Test() { using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5)); var messagesSink = new MessagesSink(MessagesCount * 2); var highPriorityMessages = MessagesFactories.Create(MessagesCount); var lowPriorityMessages = MessagesFactories.Create(MessagesCount, MessagesCount); var subscriptionId = Guid.NewGuid().ToString(); using (bus.Subscribe <Message>(subscriptionId, messagesSink.Receive, x => x.WithMaxPriority(2))) { } await bus.PublishBatchAsync( lowPriorityMessages, x => x.WithPriority(LowPriority), cts.Token ).ConfigureAwait(false); await bus.PublishBatchAsync( highPriorityMessages, x => x.WithPriority(HighPriority), cts.Token ).ConfigureAwait(false); using (bus.Subscribe <Message>(subscriptionId, messagesSink.Receive, x => x.WithMaxPriority(2))) { await messagesSink.WaitAllReceivedAsync(cts.Token).ConfigureAwait(false); messagesSink.ReceivedMessages.Should().Equal(highPriorityMessages.Concat(lowPriorityMessages)); } }
public async Task Test() { using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5)); var queue = Guid.NewGuid().ToString(); var bunniesSink = new MessagesSink(MessagesCount); var rabbitsSink = new MessagesSink(MessagesCount); var bunnies = MessagesFactories.Create(MessagesCount, i => new BunnyMessage(i)); var rabbits = MessagesFactories.Create(MessagesCount, i => new RabbitMessage(i)); using ( await bus.SendReceive.ReceiveAsync( queue, x => x.Add <BunnyMessage>(bunniesSink.Receive).Add <RabbitMessage>(rabbitsSink.Receive), cts.Token ) ) { await bus.SendReceive.SendBatchAsync(queue, bunnies, cts.Token); await bus.SendReceive.SendBatchAsync(queue, rabbits, cts.Token); await Task.WhenAll( bunniesSink.WaitAllReceivedAsync(cts.Token), rabbitsSink.WaitAllReceivedAsync(cts.Token) ); bunniesSink.ReceivedMessages.Should().Equal(bunnies); rabbitsSink.ReceivedMessages.Should().Equal(rabbits); } }
public async Task Test() { using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10)); var subscriptionId = Guid.NewGuid().ToString(); var firstTopicMessagesSink = new MessagesSink(MessagesCount); var firstTopicMessages = MessagesFactories.Create(MessagesCount); var secondTopicMessagesSink = new MessagesSink(MessagesCount); var secondTopicMessages = MessagesFactories.Create(MessagesCount); using (bus.Subscribe <Message>(subscriptionId, firstTopicMessagesSink.Receive, x => x.WithTopic("first"))) using (bus.Subscribe <Message>(subscriptionId, secondTopicMessagesSink.Receive, x => x.WithTopic("second"))) { await Task.WhenAll( bus.FuturePublishBatchAsync(firstTopicMessages, TimeSpan.FromSeconds(5), "first", cts.Token), bus.FuturePublishBatchAsync(secondTopicMessages, TimeSpan.FromSeconds(5), "second", cts.Token) ).ConfigureAwait(false); await Task.WhenAll( firstTopicMessagesSink.WaitAllReceivedAsync(cts.Token), secondTopicMessagesSink.WaitAllReceivedAsync(cts.Token) ).ConfigureAwait(false); firstTopicMessagesSink.ReceivedMessages.Should().Equal(firstTopicMessages); secondTopicMessagesSink.ReceivedMessages.Should().Equal(secondTopicMessages); } }
public async Task Should_publish_and_consume_with_multiple_subscription_ids() { using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5)); var firstConsumerMessagesSink = new MessagesSink(MessagesCount); var secondConsumerMessagesSink = new MessagesSink(MessagesCount); var messages = MessagesFactories.Create(MessagesCount); using ( await bus.PubSub.SubscribeAsync <Message>( Guid.NewGuid().ToString(), firstConsumerMessagesSink.Receive, cts.Token ) ) using ( await bus.PubSub.SubscribeAsync <Message>( Guid.NewGuid().ToString(), secondConsumerMessagesSink.Receive, cts.Token ) ) { await bus.PubSub.PublishBatchAsync(messages, cts.Token); await Task.WhenAll( firstConsumerMessagesSink.WaitAllReceivedAsync(cts.Token), secondConsumerMessagesSink.WaitAllReceivedAsync(cts.Token) ); firstConsumerMessagesSink.ReceivedMessages.Should().BeEquivalentTo(messages); secondConsumerMessagesSink.ReceivedMessages.Should().BeEquivalentTo(messages); } }
public async Task Test() { using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10)); var subscriptionId = Guid.NewGuid().ToString(); var messagesSink = new MessagesSink(MessagesCount); var messages = MessagesFactories.Create(MessagesCount); using (await bus.PubSub.SubscribeAsync <Message>(subscriptionId, messagesSink.Receive, cts.Token)) { await bus.Scheduler.FuturePublishBatchAsync(messages, TimeSpan.FromSeconds(5), "#", cts.Token); await messagesSink.WaitAllReceivedAsync(cts.Token); messagesSink.ReceivedMessages.Should().Equal(messages); } }
public async Task Test() { using var timeoutCts = new CancellationTokenSource(TimeSpan.FromSeconds(5)); var queue = Guid.NewGuid().ToString(); var messagesSink = new MessagesSink(MessagesCount); var messages = MessagesFactories.Create(MessagesCount); using (bus.Receive(queue, x => x.Add <Message>(messagesSink.Receive))) { await bus.SendBatchAsync(queue, messages, timeoutCts.Token).ConfigureAwait(false); await messagesSink.WaitAllReceivedAsync(timeoutCts.Token).ConfigureAwait(false); messagesSink.ReceivedMessages.Should().Equal(messages); } }
public async Task Should_publish_and_consume() { using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5)); var subscriptionId = Guid.NewGuid().ToString(); var messagesSink = new MessagesSink(MessagesCount); var messages = MessagesFactories.Create(MessagesCount); using (bus.Subscribe <Message>(subscriptionId, messagesSink.Receive)) { await bus.PublishBatchAsync(messages, cts.Token).ConfigureAwait(false); await messagesSink.WaitAllReceivedAsync(cts.Token).ConfigureAwait(false); messagesSink.ReceivedMessages.Should().Equal(messages); } }
public async Task Test() { using var timeoutCts = new CancellationTokenSource(TimeSpan.FromSeconds(5)); var subscriptionId = Guid.NewGuid().ToString(); var messagesSink = new MessagesSink(MessagesCount); var messages = MessagesFactories.Create(MessagesCount); using (await bus.PubSub.SubscribeAsync <Message>(subscriptionId, messagesSink.Receive, timeoutCts.Token)) { await bus.PubSub.PublishBatchInParallelAsync(messages, timeoutCts.Token); await messagesSink.WaitAllReceivedAsync(timeoutCts.Token); messagesSink.ReceivedMessages.Should().BeEquivalentTo(messages); } }
public async Task Test() { using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5)); var firstTopicMessagesSink = new MessagesSink(MessagesCount); var secondTopicMessagesSink = new MessagesSink(MessagesCount); var firstTopicMessages = MessagesFactories.Create(MessagesCount); var secondTopicMessages = MessagesFactories.Create(MessagesCount, MessagesCount); using ( await bus.PubSub.SubscribeAsync <Message>( Guid.NewGuid().ToString(), firstTopicMessagesSink.Receive, x => x.WithTopic("first"), cts.Token ) ) using ( await bus.PubSub.SubscribeAsync <Message>( Guid.NewGuid().ToString(), secondTopicMessagesSink.Receive, x => x.WithTopic("second"), cts.Token ) ) { await bus.PubSub.PublishBatchAsync( firstTopicMessages, x => x.WithTopic("first"), cts.Token ); await bus.PubSub.PublishBatchAsync( secondTopicMessages, x => x.WithTopic("second"), cts.Token ); await Task.WhenAll( firstTopicMessagesSink.WaitAllReceivedAsync(cts.Token), secondTopicMessagesSink.WaitAllReceivedAsync(cts.Token) ); firstTopicMessagesSink.ReceivedMessages.Should().Equal(firstTopicMessages); secondTopicMessagesSink.ReceivedMessages.Should().Equal(secondTopicMessages); } }
public async Task Should_survive_restart() { using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30)); var subscriptionId = Guid.NewGuid().ToString(); var messagesSink = new MessagesSink(2); using (await bus.PubSub.SubscribeAsync <Message>(subscriptionId, messagesSink.Receive, cts.Token)) { var message = new Message(0); await bus.PubSub.PublishAsync(message, cts.Token); await rmqFixture.ManagementClient.KillAllConnectionsAsync(cts.Token); await bus.PubSub.PublishAsync(message, cts.Token); await messagesSink.WaitAllReceivedAsync(cts.Token); } }
public async Task Should_survive_restart() { using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30)); var queue = Guid.NewGuid().ToString(); var messagesSink = new MessagesSink(2); using (await bus.SendReceive.ReceiveAsync(queue, x => x.Add <Message>(messagesSink.Receive), cts.Token)) { var message = new Message(0); await bus.SendReceive.SendAsync(queue, message, cts.Token); await rmqFixture.ManagementClient.KillAllConnectionsAsync(cts.Token); await bus.SendReceive.SendAsync(queue, message, cts.Token); await messagesSink.WaitAllReceivedAsync(cts.Token); } }
public async Task Should_work_with_default_options() { using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5)); var queue = Guid.NewGuid().ToString(); var messagesSink = new MessagesSink(MessagesCount); var messages = MessagesFactories.Create(MessagesCount); using ( await bus.SendReceive.ReceiveAsync(queue, x => x.Add <Message>(messagesSink.Receive), cts.Token) ) { await bus.SendReceive.SendBatchAsync(queue, messages, cts.Token); await messagesSink.WaitAllReceivedAsync(cts.Token); messagesSink.ReceivedMessages.Should().Equal(messages); } }
public async Task Test() { using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5)); var firstConsumerMessagesSink = new MessagesSink(MessagesCount); var secondConsumerMessagesSink = new MessagesSink(0); var messages = MessagesFactories.Create(MessagesCount); using ( await bus.PubSub.SubscribeAsync <Message>( Guid.NewGuid().ToString(), firstConsumerMessagesSink.Receive, x => x.AsExclusive(), cts.Token ) ) { // To ensure that ^ subscriber started successfully await Task.Delay(TimeSpan.FromSeconds(1), cts.Token).ConfigureAwait(false); using ( await bus.PubSub.SubscribeAsync <Message>( Guid.NewGuid().ToString(), secondConsumerMessagesSink.Receive, x => x.AsExclusive(), cts.Token ) ) { await bus.PubSub.PublishBatchAsync(messages, cts.Token).ConfigureAwait(false); await Task.WhenAll( firstConsumerMessagesSink.WaitAllReceivedAsync(cts.Token), secondConsumerMessagesSink.WaitAllReceivedAsync(cts.Token) ).ConfigureAwait(false); firstConsumerMessagesSink.ReceivedMessages.Should().Equal(messages); secondConsumerMessagesSink.ReceivedMessages.Should().Equal(); } } }
public async Task Test() { using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5)); var subscriptionId = Guid.NewGuid().ToString(); var bunniesSink = new MessagesSink(MessagesCount); var rabbitsSink = new MessagesSink(MessagesCount); var bunnies = MessagesFactories.Create(MessagesCount, i => new BunnyMessage(i)); var rabbits = MessagesFactories.Create(MessagesCount, MessagesCount, i => new RabbitMessage(i)); using (await bus.PubSub.SubscribeAsync <Message>(subscriptionId, x => { switch (x) { case BunnyMessage _: bunniesSink.Receive(x); break; case RabbitMessage _: rabbitsSink.Receive(x); break; default: throw new ArgumentOutOfRangeException(nameof(x), x, null); } }, cts.Token)) { await bus.PubSub.PublishBatchAsync(bunnies.Concat(rabbits), cts.Token) .ConfigureAwait(false); await Task.WhenAll( bunniesSink.WaitAllReceivedAsync(cts.Token), rabbitsSink.WaitAllReceivedAsync(cts.Token) ).ConfigureAwait(false); bunniesSink.ReceivedMessages.Should().Equal(bunnies); rabbitsSink.ReceivedMessages.Should().Equal(rabbits); } }