-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathRabbitMqConsistentHashExchangeTest.cs
52 lines (46 loc) · 1.9 KB
/
RabbitMqConsistentHashExchangeTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using NUnit.Framework;
using Rebus.Activation;
using Rebus.Config;
using Rebus.Tests.Contracts;
using Rebus.Tests.Contracts.Extensions;
// ReSharper disable ArgumentsStyleNamedExpression
#pragma warning disable 1998
namespace Rebus.RabbitMq.Tests
{
[TestFixture]
public class RabbitMqConsistentHashExchangeTest : FixtureBase
{
[Test]
public async Task WorksWithConsistentHashExchange()
{
const string connectionString = RabbitMqTransportFactory.ConnectionString;
const string exchangeName = "RebusTestConsistentHashExchange";
const string queueNamePattern = "consistent-hash-xchange-bound-queue";
using (var activator = new BuiltinHandlerActivator())
{
Configure.With(activator)
.Transport(t =>
{
t
.UseRabbitMq(connectionString, queueNamePattern)
// Create 2 Queues & bind to the same consistent hash exchange:
.UseConsistentHashExchange(2, exchangeName);
})
.Start();
// Send N messages to spread semi-evenly among queues
for (int i = 1; i <= 10; i++)
{
await activator.Bus.Advanced.Routing.Send($"{i}@{exchangeName}", $"test_{i}", new Dictionary<string, string>());
}
}
// Assert the exchange and all queues were created:
Assert.That(RabbitMqTransportFactory.ExchangeExists(exchangeName), Is.True);
Assert.That(RabbitMqTransportFactory.QueueExists(queueNamePattern + "_1"), Is.True);
Assert.That(RabbitMqTransportFactory.QueueExists(queueNamePattern + "_2"), Is.True);
}
}
}