Skip to content

Commit

Permalink
Rename method to
Browse files Browse the repository at this point in the history
LookupLeaderOrRandomReplicasConnection

Signed-off-by: Gabriele Santomaggio <G.santomaggio@gmail.com>
  • Loading branch information
Gsantomaggio committed Feb 6, 2024
1 parent 8138f53 commit cfb6b24
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion RabbitMQ.Stream.Client/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -301,4 +301,4 @@ static RabbitMQ.Stream.Client.RawSuperStreamProducer.Create(RabbitMQ.Stream.Clie
static RabbitMQ.Stream.Client.Reliable.DeduplicatingProducer.Create(RabbitMQ.Stream.Client.Reliable.DeduplicatingProducerConfig producerConfig, Microsoft.Extensions.Logging.ILogger<RabbitMQ.Stream.Client.Reliable.Producer> logger = null) -> System.Threading.Tasks.Task<RabbitMQ.Stream.Client.Reliable.DeduplicatingProducer>
static RabbitMQ.Stream.Client.Reliable.ReliableBase.RandomWait() -> System.Threading.Tasks.Task
static RabbitMQ.Stream.Client.RoutingHelper<T>.LookupLeaderConnection(RabbitMQ.Stream.Client.ClientParameters clientParameters, RabbitMQ.Stream.Client.StreamInfo metaDataInfo, RabbitMQ.Stream.Client.ConnectionsPool pool, Microsoft.Extensions.Logging.ILogger logger = null) -> System.Threading.Tasks.Task<RabbitMQ.Stream.Client.IClient>
static RabbitMQ.Stream.Client.RoutingHelper<T>.LookupRandomConnection(RabbitMQ.Stream.Client.ClientParameters clientParameters, RabbitMQ.Stream.Client.StreamInfo metaDataInfo, RabbitMQ.Stream.Client.ConnectionsPool pool, Microsoft.Extensions.Logging.ILogger logger = null) -> System.Threading.Tasks.Task<RabbitMQ.Stream.Client.IClient>
static RabbitMQ.Stream.Client.RoutingHelper<T>.LookupLeaderOrRandomReplicasConnection(RabbitMQ.Stream.Client.ClientParameters clientParameters, RabbitMQ.Stream.Client.StreamInfo metaDataInfo, RabbitMQ.Stream.Client.ConnectionsPool pool, Microsoft.Extensions.Logging.ILogger logger = null) -> System.Threading.Tasks.Task<RabbitMQ.Stream.Client.IClient>
2 changes: 1 addition & 1 deletion RabbitMQ.Stream.Client/RawConsumer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public static async Task<IConsumer> Create(
)
{
var client = await RoutingHelper<Routing>
.LookupRandomConnection(clientParameters, metaStreamInfo, config.Pool, logger)
.LookupLeaderOrRandomReplicasConnection(clientParameters, metaStreamInfo, config.Pool, logger)
.ConfigureAwait(false);
var consumer = new RawConsumer((Client)client, config, logger);
await consumer.Init().ConfigureAwait(false);
Expand Down
7 changes: 4 additions & 3 deletions RabbitMQ.Stream.Client/RoutingClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,13 @@ await LookupConnection(clientParameters, metaDataInfo.Leader, MaxAttempts(metaDa
}

/// <summary>
/// Gets a random connection. The consumer can connect to a replica or leader.
/// Gets a random connection a random replica.
/// If the replicas are not available it will connect to the leader.
/// </summary>
public static async Task<IClient> LookupRandomConnection(ClientParameters clientParameters,
public static async Task<IClient> LookupLeaderOrRandomReplicasConnection(ClientParameters clientParameters,
StreamInfo metaDataInfo, ConnectionsPool pool, ILogger logger = null)
{
var brokers = new List<Broker>() { };
var brokers = new List<Broker>();
if (metaDataInfo.Replicas is { Count: <= 0 })
{
brokers.Add(metaDataInfo.Leader);
Expand Down
4 changes: 2 additions & 2 deletions Tests/ConnectionsPoolTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ public async void RoutingShouldReturnTwoConnectionsGivenOneItemPerConnection()
var metaDataInfo = new StreamInfo("stream", ResponseCode.Ok, new Broker("localhost", 3939),
new List<Broker>());
var pool = new ConnectionsPool(0, 1);
var c1 = await RoutingHelper<PoolRouting>.LookupRandomConnection(clientParameters, metaDataInfo, pool);
var c1 = await RoutingHelper<PoolRouting>.LookupLeaderOrRandomReplicasConnection(clientParameters, metaDataInfo, pool);
c1.Consumers.Add(1, default);
var c2 = await RoutingHelper<PoolRouting>.LookupRandomConnection(clientParameters, metaDataInfo, pool);
var c2 = await RoutingHelper<PoolRouting>.LookupLeaderOrRandomReplicasConnection(clientParameters, metaDataInfo, pool);
c2.Consumers.Add(1, default);
// here we have two different connections
// and must be different since we have only one id per connection
Expand Down
6 changes: 3 additions & 3 deletions Tests/UnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public async Task GiveProperExceptionWhenUnableToConnect()
var metaDataInfo = new StreamInfo("stream", ResponseCode.Ok, new Broker("localhost", 3939),
new List<Broker>());
await Assert.ThrowsAsync<AggregateException>(() =>
RoutingHelper<Routing>.LookupRandomConnection(clientParameters, metaDataInfo,
RoutingHelper<Routing>.LookupLeaderOrRandomReplicasConnection(clientParameters, metaDataInfo,
new ConnectionsPool(1, 1)));
}

Expand Down Expand Up @@ -233,7 +233,7 @@ public void RandomReplicaLeader()
var metaDataInfo = new StreamInfo("stream", ResponseCode.Ok, new Broker("leader", 5552),
new List<Broker>());
var client =
RoutingHelper<LeaderRouting>.LookupRandomConnection(clientParameters, metaDataInfo,
RoutingHelper<LeaderRouting>.LookupLeaderOrRandomReplicasConnection(clientParameters, metaDataInfo,
new ConnectionsPool(1, 1));
Assert.Equal("5552", client.Result.ConnectionProperties["advertised_port"]);
var res = (client.Result.ConnectionProperties["advertised_host"] == "leader" ||
Expand All @@ -254,7 +254,7 @@ public void RandomOnlyReplicaIfThereAre()
new Broker("replica2", 5553),
});
var client =
RoutingHelper<ReplicaseRouting>.LookupRandomConnection(clientParameters, metaDataInfo,
RoutingHelper<ReplicaseRouting>.LookupLeaderOrRandomReplicasConnection(clientParameters, metaDataInfo,
new ConnectionsPool(1, 1));
Assert.Equal("5553", client.Result.ConnectionProperties["advertised_port"]);
var res = (client.Result.ConnectionProperties["advertised_host"] == "replica2");
Expand Down
4 changes: 2 additions & 2 deletions docs/ReliableClient/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
{
ProducersPerConnection = 2,
ConsumersPerConnection = 100,
Host = "node1",
Port = 5553,
Host = "localhost",
Port = 5552,
LoadBalancer = true,
SuperStream = false,
Streams = 10,
Expand Down

0 comments on commit cfb6b24

Please sign in to comment.