Skip to content

Commit 5e711a4

Browse files
acogoluegnesmergify[bot]
authored andcommitted
Use advertised TLS host setting in metadata frame
The rabbitmq_stream.advertised_tls_host setting is not used in the metadata frame of the stream protocol, even if it is set. This commit makes sure the setting is used if set. References rabbitmq/rabbitmq-stream-java-client#803 (cherry picked from commit 22a9593) # Conflicts: # deps/rabbitmq_stream/src/rabbit_stream.erl # deps/rabbitmq_stream/src/rabbit_stream_utils.hrl
1 parent dd95f23 commit 5e711a4

File tree

4 files changed

+223
-96
lines changed

4 files changed

+223
-96
lines changed

deps/rabbitmq_stream/src/rabbit_stream.erl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
-include_lib("rabbitmq_stream_common/include/rabbit_stream.hrl").
3838

3939
-include("rabbit_stream_metrics.hrl").
40+
<<<<<<< HEAD
41+
=======
42+
-include_lib("kernel/include/logger.hrl").
43+
-include_lib("rabbitmq_stream/src/rabbit_stream_utils.hrl").
44+
>>>>>>> 22a959331 (Use advertised TLS host setting in metadata frame)
4045

4146
start(_Type, _Args) ->
4247
rabbit_stream_metrics:init(),
@@ -47,7 +52,7 @@ start(_Type, _Args) ->
4752
rabbit_stream_sup:start_link().
4853

4954
tls_host() ->
50-
case application:get_env(rabbitmq_stream, advertised_tls_host,
55+
case application:get_env(rabbitmq_stream, ?K_AD_TLS_HOST,
5156
undefined)
5257
of
5358
undefined ->
@@ -57,7 +62,7 @@ tls_host() ->
5762
end.
5863

5964
host() ->
60-
case application:get_env(rabbitmq_stream, advertised_host, undefined)
65+
case application:get_env(rabbitmq_stream, ?K_AD_HOST, undefined)
6166
of
6267
undefined ->
6368
hostname_from_node();
@@ -78,7 +83,7 @@ hostname_from_node() ->
7883
end.
7984

8085
port() ->
81-
case application:get_env(rabbitmq_stream, advertised_port, undefined)
86+
case application:get_env(rabbitmq_stream, ?K_AD_PORT, undefined)
8287
of
8388
undefined ->
8489
port_from_listener();
@@ -102,7 +107,7 @@ port_from_listener() ->
102107
end.
103108

104109
tls_port() ->
105-
case application:get_env(rabbitmq_stream, advertised_tls_port,
110+
case application:get_env(rabbitmq_stream, ?K_AD_TLS_PORT,
106111
undefined)
107112
of
108113
undefined ->

deps/rabbitmq_stream/src/rabbit_stream_reader.erl

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,32 +1470,17 @@ handle_frame_pre_auth(Transport,
14701470
VirtualHost,
14711471
{socket, S},
14721472
#{}),
1473-
AdvertisedHost =
1474-
case TransportLayer of
1475-
tcp ->
1476-
rabbit_stream:host();
1477-
ssl ->
1478-
rabbit_stream:tls_host()
1479-
end,
1480-
AdvertisedPort =
1481-
case TransportLayer of
1482-
tcp ->
1483-
rabbit_data_coercion:to_binary(
1484-
rabbit_stream:port());
1485-
ssl ->
1486-
rabbit_data_coercion:to_binary(
1487-
rabbit_stream:tls_port())
1488-
end,
14891473

1490-
ConnectionProperties =
1491-
#{<<"advertised_host">> => AdvertisedHost,
1492-
<<"advertised_port">> => AdvertisedPort},
1474+
AdHost = advertised_host(TransportLayer),
1475+
AdPort = rabbit_data_coercion:to_binary(advertised_port(TransportLayer)),
1476+
ConnProps = #{<<"advertised_host">> => AdHost,
1477+
<<"advertised_port">> => AdPort},
14931478

14941479
rabbit_log:debug("sending open response ok ~ts", [VirtualHost]),
14951480
Frame =
14961481
rabbit_stream_core:frame({response, CorrelationId,
14971482
{open, ?RESPONSE_CODE_OK,
1498-
ConnectionProperties}}),
1483+
ConnProps}}),
14991484

15001485
send(Transport, S, Frame),
15011486
%% FIXME check if vhost is alive (see rabbit_reader:is_vhost_alive/2)
@@ -2334,13 +2319,10 @@ handle_frame_post_auth(Transport,
23342319
Nodes0),
23352320
NodeEndpoints =
23362321
lists:foldr(fun(Node, Acc) ->
2337-
PortFunction =
2338-
case TransportLayer of
2339-
tcp -> port;
2340-
ssl -> tls_port
2341-
end,
2342-
Host = rpc:call(Node, rabbit_stream, host, []),
2343-
Port = rpc:call(Node, rabbit_stream, PortFunction, []),
2322+
HostFun = advertised_host_fun(TransportLayer),
2323+
PortFun = advertised_port_fun(TransportLayer),
2324+
Host = rpc:call(Node, rabbit_stream, HostFun, []),
2325+
Port = rpc:call(Node, rabbit_stream, PortFun, []),
23442326
case {is_binary(Host), is_integer(Port)} of
23452327
{true, true} -> Acc#{Node => {Host, Port}};
23462328
_ ->
@@ -4074,3 +4056,21 @@ retry_sac_call(Call, N) ->
40744056
R ->
40754057
R
40764058
end.
4059+
4060+
advertised_host(Transport) ->
4061+
F = advertised_host_fun(Transport),
4062+
rabbit_stream:F().
4063+
4064+
advertised_port(Transport) ->
4065+
F = advertised_port_fun(Transport),
4066+
rabbit_stream:F().
4067+
4068+
advertised_host_fun(tcp) ->
4069+
host;
4070+
advertised_host_fun(ssl) ->
4071+
tls_host.
4072+
4073+
advertised_port_fun(tcp) ->
4074+
port;
4075+
advertised_port_fun(ssl) ->
4076+
tls_port.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
%% The contents of this file are subject to the Mozilla Public License
2+
%% at https://www.mozilla.org/en-US/MPL/2.0/
3+
%%
4+
%% Software distributed under the License is distributed on an "AS IS"
5+
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
6+
%% the License for the specific language governing rights and
7+
%% limitations under the License.
8+
%%
9+
%% The Original Code is RabbitMQ.
10+
%%
11+
%% The Initial Developer of the Original Code is Pivotal Software, Inc.
12+
%% Copyright (c) 2025 Broadcom. All Rights Reserved.
13+
%% The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
14+
%%
15+
16+
-define(IS_INVALID_REF(Ref), is_binary(Ref) andalso byte_size(Ref) > 255).
17+
-define(K_AD_HOST, advertised_host).
18+
-define(K_AD_PORT, advertised_port).
19+
-define(K_AD_TLS_HOST, advertised_tls_host).
20+
-define(K_AD_TLS_PORT, advertised_tls_port).

0 commit comments

Comments
 (0)