chore: cosmetic changes

This commit is contained in:
zmstone 2024-06-10 14:22:25 +02:00
parent 7b2b2b527c
commit 7a09b0470d
1 changed files with 7 additions and 6 deletions

View File

@ -57,7 +57,9 @@
-define(HEALTH_CHECK_TIMEOUT, 1000). -define(HEALTH_CHECK_TIMEOUT, 1000).
-define(INGRESS, "I"). -define(INGRESS, "I").
-define(EGRESS, "E"). -define(EGRESS, "E").
-define(IS_NO_PREFIX(P), (P =:= undefined orelse P =:= <<>>)). -define(NO_PREFIX, <<>>).
-define(IS_NO_PREFIX(P), (P =:= undefined orelse P =:= ?NO_PREFIX)).
-define(MAX_PREFIX_BYTES, 19).
%% =================================================================== %% ===================================================================
%% When use this bridge as a data source, ?MODULE:on_message_received will be called %% When use this bridge as a data source, ?MODULE:on_message_received will be called
@ -444,7 +446,7 @@ clientid(Name, _Conf = #{clientid_prefix := Prefix}) when
-> ->
{Prefix, emqx_bridge_mqtt_lib:clientid_base(Name)}; {Prefix, emqx_bridge_mqtt_lib:clientid_base(Name)};
clientid(Name, _Conf) -> clientid(Name, _Conf) ->
{undefined, emqx_bridge_mqtt_lib:clientid_base(Name)}. {?NO_PREFIX, emqx_bridge_mqtt_lib:clientid_base(Name)}.
%% @doc Start an ingress bridge worker. %% @doc Start an ingress bridge worker.
-spec connect([option() | {ecpool_worker_id, pos_integer()}]) -> -spec connect([option() | {ecpool_worker_id, pos_integer()}]) ->
@ -485,10 +487,9 @@ mk_client_opts(
mk_clientid(WorkerId, {Prefix, ClientId}) when ?IS_NO_PREFIX(Prefix) -> mk_clientid(WorkerId, {Prefix, ClientId}) when ?IS_NO_PREFIX(Prefix) ->
%% When there is no prefix, try to keep the client ID length within 23 bytes %% When there is no prefix, try to keep the client ID length within 23 bytes
emqx_bridge_mqtt_lib:bytes23(ClientId, WorkerId); emqx_bridge_mqtt_lib:bytes23(ClientId, WorkerId);
mk_clientid(WorkerId, {Prefix, ClientId}) when size(Prefix) < 20 -> mk_clientid(WorkerId, {Prefix, ClientId}) when size(Prefix) =< ?MAX_PREFIX_BYTES ->
%% Try to respect client ID prefix when it's less than 20 bytes %% Try to respect client ID prefix when it's no more than 19 bytes,
%% meaning there is at least 3 bytes to randomize %% meaning there are at least 4 bytes as hash space.
%% Must add $: for backward compatibility
emqx_bridge_mqtt_lib:bytes23_with_prefix(Prefix, ClientId, WorkerId); emqx_bridge_mqtt_lib:bytes23_with_prefix(Prefix, ClientId, WorkerId);
mk_clientid(WorkerId, {Prefix, ClientId}) -> mk_clientid(WorkerId, {Prefix, ClientId}) ->
%% There is no other option but to use a long client ID %% There is no other option but to use a long client ID