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

Commit 62e3a4e

Browse files
author
Anton Vorontsov
committed
Added ssl configuration documentation.
1 parent 5415991 commit 62e3a4e

File tree

1 file changed

+82
-1
lines changed

1 file changed

+82
-1
lines changed

docs/rabbit-configuration.md

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# RabbitMQ configuration
22

3+
## Basic configuration
4+
35
To connect to a RabbitMQ server, it is necessary to instantiate `IQueueService` and configure it to use a desired endpoint, credentials and other valuable connection settings.
46
`IQueueService` allows clients to configure queues to exchange bindings, and to consume and produce messages in different ways (sync or async, with or without delay). To add `IQueueService` in your application simply use the `AddRabbitMqClient` extension method as in the example below.
57

@@ -48,7 +50,7 @@ A RabbitMQ client can be configured via a configuration section located in the `
4850
```
4951

5052
A RabbitMQ connection can be configured with properties:
51-
- `HostName` - RabbitMQ server,
53+
- `HostName` - RabbitMQ server,
5254
- `HostNames` - collection of RabbitMQ hostnames,
5355
- `TcpEndpoints` - collection of AMPQ TCP endpoints,
5456
- `Port` - port RabbitMQ running on,
@@ -89,6 +91,8 @@ For high availability RabbitMQ clusters with multiple nodes you can set hosts co
8991
}
9092
```
9193

94+
## Multiple nodes configuration
95+
9296
If nodes are running on different hosts with different ports you have an option of configuring that via `TcpEndpoints`.
9397

9498
```json
@@ -149,4 +153,81 @@ public class Startup
149153

150154
There is also the `AddRabbitMqClientTransient` method which takes `RabbitMqClientOptions`.
151155

156+
## Ssl configuration
157+
158+
In case you want to establish an ssl connection you can use advanced `TcpEndpoints` configuration.
159+
`RabbitMqTcpEndpoint` has following properties:
160+
- `HostName` - RabbitMQ server.
161+
- `Port` - tcp connection port. The default ssl port is 5671.
162+
- `SslOption` - ssl options model `RabbitMqSslOption`.
163+
164+
Ssl options model `RabbitMqSslOption` consists of:
165+
- `ServerName` - canonical server name (CA).
166+
- `CertificatePath` - path to your certificate (a key store).
167+
- `CertificatePassphrase` - passphrase for client certificate.
168+
- `Enabled` - flag that defines if certificate should be used. The default value is true.
169+
- `AcceptablePolicyErrors` - acceptable policy errors. Flags enum `SslPolicyErrors`. The default value is null.
170+
171+
The key part is to make a proper configuration - right `ServerName`, `CertificatePath` (if needed) and `AcceptablePolicyErrors`.
172+
173+
```c#
174+
var rabbitMqConfiguration = new RabbitMqClientOptions
175+
{
176+
UserName = "guest",
177+
Password = "guest",
178+
TcpEndpoints = new List<RabbitMqTcpEndpoint>
179+
{
180+
new RabbitMqTcpEndpoint
181+
{
182+
HostName = "127.0.0.1",
183+
Port = 5671,
184+
SslOption = new RabbitMqSslOption
185+
{
186+
Enabled = true,
187+
ServerName = "yourCA",
188+
CertificatePath = "/path/tp/client-key-store.p12",
189+
CertificatePassphrase = "yourPathPhrase",
190+
AcceptablePolicyErrors = SslPolicyErrors.RemoteCertificateChainErrors | SslPolicyErrors.RemoteCertificateNameMismatch
191+
}
192+
}
193+
}
194+
};
195+
```
196+
197+
The same configuration can be in appsettings.json file.
198+
199+
```json
200+
{
201+
"RabbitMq": {
202+
"TcpEndpoints": [
203+
{
204+
"HostName": "127.0.0.1",
205+
"Port": 5671,
206+
"SslOption": {
207+
"Enabled": true,
208+
"ServerName": "yourCA",
209+
"CertificatePath": "/path/tp/client-key-store.p12",
210+
"CertificatePassphrase": "yourPathPhrase",
211+
"AcceptablePolicyErrors": "RemoteCertificateChainErrors, RemoteCertificateNameMismatch"
212+
}
213+
}
214+
],
215+
"UserName": "guest",
216+
"Password": "guest"
217+
}
218+
}
219+
```
220+
221+
Map that configuration using standard `GetSection` method.
222+
223+
```c#
224+
var rabbitMqConfiguration = Configuration.GetSection("RabbitMq");
225+
```
226+
227+
And pass it to the `AddRabbitMqClient` extension method as always.
228+
229+
```c#
230+
services.AddRabbitMqClient(rabbitMqConfiguration);
231+
```
232+
152233
For the exchange configuration see the [Next page](exchange-configuration.md)

0 commit comments

Comments
 (0)