Skip to content

Commit 2845f4e

Browse files
authored
Merge pull request #2075 from rabbitmq/configure-cluster-name
Make it possible to pre-configure cluster name via config
2 parents f47a339 + 107bd08 commit 2845f4e

File tree

4 files changed

+36
-5
lines changed

4 files changed

+36
-5
lines changed

docs/rabbitmq.conf.example

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@
200200
# ssl_handshake_timeout = 5000
201201

202202

203+
## Cluster name
204+
##
205+
# cluster_name = dev3.eng.megacorp.local
206+
203207
## Password hashing implementation. Will only affect newly
204208
## created users. To recalculate hash for an existing user
205209
## it's necessary to update her password.
@@ -512,7 +516,7 @@
512516
# net_ticktime = 60
513517

514518
## Inter-node communication port range.
515-
## The parameters inet_dist_listen_min and inet_dist_listen_max
519+
## The parameters inet_dist_listen_min and inet_dist_listen_max
516520
## can be configured in the classic config format only.
517521
## Related doc guide: https://www.rabbitmq.com/networking.html#epmd-inet-dist-port-range.
518522

priv/schema/rabbit.schema

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,14 +383,20 @@ end}.
383383
{datatype, {enum, [distinguished_name, common_name]}}
384384
]}.
385385

386-
%% SSL handshake timeout, in milliseconds.
386+
%% TLS handshake timeout, in milliseconds.
387387
%%
388388
%% {ssl_handshake_timeout, 5000},
389389

390390
{mapping, "ssl_handshake_timeout", "rabbit.ssl_handshake_timeout", [
391391
{datatype, integer}
392392
]}.
393393

394+
%% Cluster name
395+
396+
{mapping, "cluster_name", "rabbit.cluster_name", [
397+
{datatype, string}
398+
]}.
399+
394400
%% Default worker process pool size. Used to limit maximum concurrency rate
395401
%% of certain operations, e.g. queue initialisation and recovery on node boot.
396402

src/rabbit.erl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,12 @@
226226
[{description, "ready to communicate with peers and clients"},
227227
{requires, [core_initialized, recovery, routing_ready]}]}).
228228

229+
-rabbit_boot_step({cluster_name,
230+
[{description, "sets cluster name if configured"},
231+
{mfa, {rabbit_nodes, boot, []}},
232+
{requires, pre_flight}
233+
]}).
234+
229235
-rabbit_boot_step({direct_client,
230236
[{description, "direct client"},
231237
{mfa, {rabbit_direct, boot, []}},

src/rabbit_nodes.erl

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,28 @@
1919

2020
-export([names/1, diagnostics/1, make/1, parts/1, cookie_hash/0,
2121
is_running/2, is_process_running/2,
22-
cluster_name/0, set_cluster_name/2, ensure_epmd/0,
22+
cluster_name/0, set_cluster_name/1, set_cluster_name/2, ensure_epmd/0,
2323
all_running/0, name_type/0, running_count/0,
24-
await_running_count/2]).
24+
await_running_count/2,
25+
boot/0]).
2526

2627
-include_lib("kernel/include/inet.hrl").
28+
-include_lib("rabbit_common/include/rabbit.hrl").
2729

2830
-define(SAMPLING_INTERVAL, 1000).
2931

3032
%%----------------------------------------------------------------------------
31-
%% Specs
33+
%% API
3234
%%----------------------------------------------------------------------------
3335

36+
boot() ->
37+
case application:get_env(rabbit, cluster_name) of
38+
undefined -> ok;
39+
{ok, Name} ->
40+
rabbit_log:info("Setting cluster name to '~s' as configured", [Name]),
41+
set_cluster_name(rabbit_data_coercion:to_binary(Name))
42+
end.
43+
3444
name_type() ->
3545
case os:getenv("RABBITMQ_USE_LONGNAME") of
3646
"true" -> longnames;
@@ -80,6 +90,11 @@ cluster_name_default() ->
8090
FQDN = rabbit_net:hostname(),
8191
list_to_binary(atom_to_list(make({ID, FQDN}))).
8292

93+
-spec set_cluster_name(binary()) -> 'ok'.
94+
95+
set_cluster_name(Name) ->
96+
set_cluster_name(Name, ?INTERNAL_USER).
97+
8398
-spec set_cluster_name(binary(), rabbit_types:username()) -> 'ok'.
8499

85100
set_cluster_name(Name, Username) ->

0 commit comments

Comments
 (0)