public async Task Test() { using var cts = 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, cts.Token)) { await bus.PubSub.PublishBatchAsync(messages, cts.Token); await messagesSink.WaitAllReceivedAsync(cts.Token); messagesSink.ReceivedMessages.Should().Equal(messages); } }
public async Task Test() { using var timeoutCts = new CancellationTokenSource(TimeSpan.FromSeconds(10)); var subscriptionId = Guid.NewGuid().ToString(); var messagesSink = new MessagesSink(MessagesCount); var messages = MessagesFactories.Create(MessagesCount); using (bus.Subscribe <Message>(subscriptionId, messagesSink.Receive)) { await bus.FuturePublishBatchAsync(messages, TimeSpan.FromSeconds(5), timeoutCts.Token) .ConfigureAwait(false); await messagesSink.WaitAllReceivedAsync(timeoutCts.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).ConfigureAwait(false); await messagesSink.WaitAllReceivedAsync(timeoutCts.Token).ConfigureAwait(false); 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 ).ConfigureAwait(false); await bus.PubSub.PublishBatchAsync( secondTopicMessages, x => x.WithTopic("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_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 Should_publish_and_consume_with_same_subscription_ids() { 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)) using (bus.Subscribe <Message>(subscriptionId, messagesSink.Receive)) 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().BeEquivalentTo(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); } }
public async Task Should_publish_and_consume_with_multiple_subscription_ids() { using var timeoutCts = new CancellationTokenSource(TimeSpan.FromSeconds(5)); var firstConsumerMessagesSink = new MessagesSink(MessagesCount); var secondConsumerMessagesSink = new MessagesSink(MessagesCount); var messages = MessagesFactories.Create(MessagesCount); using (bus.Subscribe <Message>(Guid.NewGuid().ToString(), firstConsumerMessagesSink.Receive)) using (bus.Subscribe <Message>(Guid.NewGuid().ToString(), secondConsumerMessagesSink.Receive)) { await bus.PublishBatchAsync(messages, timeoutCts.Token).ConfigureAwait(false); await Task.WhenAll( firstConsumerMessagesSink.WaitAllReceivedAsync(timeoutCts.Token), secondConsumerMessagesSink.WaitAllReceivedAsync(timeoutCts.Token) ).ConfigureAwait(false); firstConsumerMessagesSink.ReceivedMessages.Should().BeEquivalentTo(messages); secondConsumerMessagesSink.ReceivedMessages.Should().BeEquivalentTo(messages); } }
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 ( await bus.PubSub.SubscribeAsync <Message>( subscriptionId, messagesSink.Receive, x => x.WithMaxPriority(2), cts.Token ) ) { } await bus.PubSub.PublishBatchAsync( lowPriorityMessages, x => x.WithPriority(LowPriority), cts.Token ); await bus.PubSub.PublishBatchAsync( highPriorityMessages, x => x.WithPriority(HighPriority), cts.Token ); using ( await bus.PubSub.SubscribeAsync <Message>( subscriptionId, messagesSink.Receive, x => x.WithMaxPriority(2), cts.Token ) ) { await messagesSink.WaitAllReceivedAsync(cts.Token); messagesSink.ReceivedMessages.Should().Equal(highPriorityMessages.Concat(lowPriorityMessages)); } }