Browse Source
Merge pull request #7897 from real-zony/rabbit-cluster-support
Add support for RabbitMQ cluster.
pull/7919/head
maliming
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with
68 additions and
5 deletions
docs/en/Background-Jobs-RabbitMq.md
docs/en/Distributed-Event-Bus-RabbitMQ-Integration.md
docs/zh-Hans/Distributed-Event-Bus-RabbitMQ-Integration.md
framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/ConnectionPool.cs
@ -66,6 +66,26 @@ Defining multiple connections is allowed. In this case, you can use different co
}
````
If you need to connect to the RabbitMQ cluster, you can use the `;` character to separate the host names.
**Example: Connect to the RabbitMQ cluster**
```json
{
"RabbitMQ": {
"Connections": {
"Default": {
"HostName": "123.123.123.123;234.234.234.234"
}
},
"EventBus": {
"ClientName": "MyClientName",
"ExchangeName": "MyExchangeName"
}
}
}
```
#### AbpRabbitMqOptions
`AbpRabbitMqOptions` class can be used to configure the connection strings for the RabbitMQ. You can configure this options inside the `ConfigureServices` of your [module ](Module-Development-Basics.md ).
@ -90,7 +90,7 @@ You can use any of the [ConnectionFactry](http://rabbitmq.github.io/rabbitmq-dot
**Example: Specify the connection port**
````csharp
````json
{
"RabbitMQ": {
"Connections": {
@ -103,6 +103,26 @@ You can use any of the [ConnectionFactry](http://rabbitmq.github.io/rabbitmq-dot
}
````
If you need to connect to the RabbitMQ cluster, you can use the `;` character to separate the host names.
**Example: Connect to the RabbitMQ cluster**
```json
{
"RabbitMQ": {
"Connections": {
"Default": {
"HostName": "123.123.123.123;234.234.234.234"
}
},
"EventBus": {
"ClientName": "MyClientName",
"ExchangeName": "MyExchangeName"
}
}
}
```
### The Options Classes
`AbpRabbitMqOptions` and `AbpRabbitMqEventBusOptions` classes can be used to configure the connection strings and event bus options for the RabbitMQ.
@ -103,6 +103,26 @@
}
````
如果需要连接到 RabbitMQ 集群,你可以指定多个 HostName。
**示例: 连接到 RabbitMQ 集群**
```json
{
"RabbitMQ": {
"Connections": {
"Default": {
"HostName": "123.123.123.123;234.234.234.234"
}
},
"EventBus": {
"ClientName": "MyClientName",
"ExchangeName": "MyExchangeName"
}
}
}
```
### 选项类
`AbpRabbitMqOptions` 和 `AbpRabbitMqEventBusOptions` 类用于配置RabbitMQ的连接字符串和事件总线选项.
@ -26,10 +26,13 @@ namespace Volo.Abp.RabbitMQ
return Connections . GetOrAdd (
connectionName ,
( ) = > Options
. Connections
. GetOrDefault ( connectionName )
. CreateConnection ( )
( ) = >
{
var connection = Options . Connections . GetOrDefault ( connectionName ) ;
var hostnames = connection . HostName . TrimEnd ( ';' ) . Split ( ';' ) ;
// Handle Rabbit MQ Cluster.
return hostnames . Length = = 1 ? connection . CreateConnection ( ) : connection . CreateConnection ( hostnames ) ;
}
) ;
}