Skip to content
This repository was archived by the owner on Apr 29, 2022. It is now read-only.

Commit 4ec23c7

Browse files
FIxed examples and made summary for RabbitMQ options.
1 parent 037cfe7 commit 4ec23c7

File tree

8 files changed

+33
-20
lines changed

8 files changed

+33
-20
lines changed

examples/Examples.ConsumerConsole/CustomAsyncMessageHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public CustomAsyncMessageHandler(ILogger<CustomAsyncMessageHandler> logger)
1515

1616
public async Task Handle(string message, string routingKey)
1717
{
18-
await Task.Run(() => _logger.LogInformation("A weird example of runnig something async.")).ConfigureAwait(false);
18+
_logger.LogInformation($"A weird example of running something async with message {message}.");
1919
}
2020
}
2121
}

examples/Examples.ConsumerConsole/CustomAsyncNonCyclicMessageHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public CustomAsyncNonCyclicMessageHandler(ILogger<CustomAsyncNonCyclicMessageHan
1515

1616
public async Task Handle(string message, string routingKey, IQueueService queueService)
1717
{
18-
_logger.LogInformation("A weird example of runnig something async.");
18+
_logger.LogInformation("A weird example of running something async.");
1919
var response = new { message, routingKey };
2020
await queueService.SendAsync(response, "exchange.name", "routing.key");
2121
}

examples/Examples.ConsumerConsole/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ static void ConfigureServices(IServiceCollection services)
3232

3333
services.AddRabbitMqClient(rabbitMqSection)
3434
.AddConsumptionExchange("exchange.name", exchangeSection)
35-
.AddAsyncMessageHandlerSingleton<CustomAsyncMessageHandler>("routing.key")
36-
.AddAsyncNonCyclicMessageHandlerSingleton<CustomAsyncNonCyclicMessageHandler>("routing.key");
35+
.AddAsyncMessageHandlerSingleton<CustomAsyncMessageHandler>("routing.key");
36+
//.AddAsyncNonCyclicMessageHandlerSingleton<CustomAsyncNonCyclicMessageHandler>("routing.key");
3737
}
3838
}
3939
}

examples/Examples.ConsumerConsole/appsettings.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
}
66
},
77
"RabbitMq": {
8-
"HostName": "127.0.0.1",
8+
"TcpEndpoints": [
9+
{
10+
"HostName": "127.0.0.1",
11+
"Port": 5672
12+
}
13+
],
914
"Port": "5672",
1015
"UserName": "guest",
1116
"Password": "guest"

examples/Examples.ConsumerHost/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ public static async Task Main()
2727

2828
services.AddRabbitMqClient(rabbitMqSection)
2929
.AddConsumptionExchange("exchange.name", exchangeSection)
30-
.AddMessageHandlerTransient<CustomMessageHandler>("routing.key")
31-
.AddNonCyclicMessageHandlerSingleton<CustomNonCyclicMessageHandler>("routing.key");
30+
.AddMessageHandlerTransient<CustomMessageHandler>("routing.key");
31+
//.AddNonCyclicMessageHandlerSingleton<CustomNonCyclicMessageHandler>("routing.key");
3232

3333
services.AddSingleton<IHostedService, ConsumingService>();
3434
});

src/RabbitMQ.Client.Core.DependencyInjection/Configuration/RabbitMqClientOptions.cs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,35 @@ namespace RabbitMQ.Client.Core.DependencyInjection.Configuration
88
public class RabbitMqClientOptions
99
{
1010
/// <summary>
11-
/// RabbitMQ server.
11+
/// Collection of AMPQ TCP endpoints.
12+
/// It can be used when RabbitMQ HA cluster is set up and you have to connect multiple hosts with different ports.
1213
/// </summary>
13-
public string HostName { get; set; } = "127.0.0.1";
14+
/// <remarks>
15+
/// Has the first priority between properties TcpEndpoints, HostNames and HostName.
16+
/// If all properties are set, TcpEndpoints will be used.
17+
/// </remarks>
18+
public IEnumerable<RabbitMqTcpEndpoint> TcpEndpoints { get; set; }
1419

1520
/// <summary>
1621
/// Collection of RabbitMQ server host names.
17-
/// </summary>
18-
/// <remarks>
1922
/// It can be used when RabbitMQ HA cluster is set up and you have to connect multiple hosts.
2023
/// If HostNames collection is null or empty then HostName will be used to create connection.
2124
/// Otherwise HostNames collection will be used and HostName property value will be ignored.
25+
/// </summary>
26+
/// <remarks>
27+
/// Has the second priority between properties TcpEndpoints, HostNames and HostName.
28+
/// If HostNames collection property and HostName property both set then HostNames will be used.
2229
/// </remarks>
2330
public IEnumerable<string> HostNames { get; set; }
24-
31+
2532
/// <summary>
26-
/// Collection of AMPQ TCP endpoints.
33+
/// RabbitMQ server.
2734
/// </summary>
2835
/// <remarks>
29-
/// Usage is the same as collection of HostNames but
36+
/// Has the third priority between properties TcpEndpoints, HostNames and HostName.
37+
/// HostName will be used if only TcpEndpoints and HostNames properties are not set.
3038
/// </remarks>
31-
public IEnumerable<RabbitMqTcpEndpoint> TcpEndpoints { get; set; }
39+
public string HostName { get; set; } = "127.0.0.1";
3240

3341
/// <summary>
3442
/// Port.

src/RabbitMQ.Client.Core.DependencyInjection/Configuration/RabbitMqTcpEndpoint.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class RabbitMqTcpEndpoint
99
/// RabbitMQ server.
1010
/// </summary>
1111
public string HostName { get; set; }
12-
12+
1313
/// <summary>
1414
/// Tcp connection port.
1515
/// </summary>

src/RabbitMQ.Client.Core.DependencyInjection/QueueService.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -555,15 +555,15 @@ static IConnection CreateRabbitMqConnection(RabbitMqClientOptions options)
555555
RequestedConnectionTimeout = options.RequestedConnectionTimeout,
556556
RequestedHeartbeat = options.RequestedHeartbeat
557557
};
558-
558+
559559
if (options.TcpEndpoints?.Any() == true)
560560
{
561561
var clientEndpoints = options.TcpEndpoints.Select(x => new AmqpTcpEndpoint(x.HostName, x.Port)).ToList();
562562
return factory.CreateConnection(clientEndpoints);
563563
}
564-
565-
return string.IsNullOrEmpty(options.ClientProvidedName)
566-
? CreateConnection(options, factory)
564+
565+
return string.IsNullOrEmpty(options.ClientProvidedName)
566+
? CreateConnection(options, factory)
567567
: CreateNamedConnection(options, factory);
568568
}
569569

0 commit comments

Comments
 (0)