Skip to content

Commit a1ac3cd

Browse files
Make it possible to pre-configure cluster name via config
Per discussion with @gerhard. (cherry picked from commit 1aba6fa) Conflicts: src/rabbit.erl src/rabbit_nodes.erl
1 parent 6ebf50b commit a1ac3cd

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,18 @@
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({os_signal_handler,
230236
[{description, "registers an OS signal handler"},
231237
{mfa, {rabbit_sup, start_restartable_child,
232238
[rabbit_os_signal_handler]}},
233239
{requires, pre_flight}]}).
234240

235-
>>>>>>> aa48d22d0... Merge pull request #2227 from rabbitmq/rabbitmq-server-2222
236241
-rabbit_boot_step({direct_client,
237242
[{description, "direct client"},
238243
{mfa, {rabbit_direct, boot, []}},

src/rabbit_nodes.erl

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,18 @@
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

3436
-spec names(string()) ->
@@ -38,12 +40,18 @@
3840
-spec is_running(node(), atom()) -> boolean().
3941
-spec is_process_running(node(), atom()) -> boolean().
4042
-spec cluster_name() -> binary().
41-
-spec set_cluster_name(binary(), rabbit_types:username()) -> 'ok'.
4243
-spec all_running() -> [node()].
4344
-spec running_count() -> integer().
44-
4545
%%----------------------------------------------------------------------------
4646

47+
boot() ->
48+
case application:get_env(rabbit, cluster_name) of
49+
undefined -> ok;
50+
{ok, Name} ->
51+
rabbit_log:info("Setting cluster name to '~s' as configured", [Name]),
52+
set_cluster_name(rabbit_data_coercion:to_binary(Name))
53+
end.
54+
4755
name_type() ->
4856
case os:getenv("RABBITMQ_USE_LONGNAME") of
4957
"true" -> longnames;
@@ -80,6 +88,13 @@ cluster_name_default() ->
8088
FQDN = rabbit_net:hostname(),
8189
list_to_binary(atom_to_list(make({ID, FQDN}))).
8290

91+
-spec set_cluster_name(binary()) -> 'ok'.
92+
93+
set_cluster_name(Name) ->
94+
set_cluster_name(Name, ?INTERNAL_USER).
95+
96+
-spec set_cluster_name(binary(), rabbit_types:username()) -> 'ok'.
97+
8398
set_cluster_name(Name, Username) ->
8499
%% Cluster name should be binary
85100
BinaryName = rabbit_data_coercion:to_binary(Name),

0 commit comments

Comments
 (0)