From 60a3fe9af40841b1f4eb71c3ad6da222fbfec1a2 Mon Sep 17 00:00:00 2001 From: anlicheng <244108715@qq.com> Date: Wed, 10 Sep 2025 11:06:14 +0800 Subject: [PATCH] endpoint alias name use gproc --- apps/iot/src/endpoint/endpoint.erl | 2 +- apps/iot/src/endpoint/endpoint_http.erl | 2 +- apps/iot/src/endpoint/endpoint_kafka.erl | 3 ++- apps/iot/src/endpoint/endpoint_mqtt.erl | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/apps/iot/src/endpoint/endpoint.erl b/apps/iot/src/endpoint/endpoint.erl index 14319b0..250f013 100644 --- a/apps/iot/src/endpoint/endpoint.erl +++ b/apps/iot/src/endpoint/endpoint.erl @@ -47,7 +47,7 @@ get_alias_name(Name) when is_binary(Name) -> -spec get_alias_pid(Name :: binary()) -> undefined | pid(). get_alias_pid(Name) when is_binary(Name) -> - iot_name_server:whereis_alias(get_alias_name(Name)). + gproc:whereis_name({n, l, get_alias_name(Name)}). -spec forward(Pid :: pid(), ServiceId :: binary(), Metric :: binary()) -> no_return(). forward(Pid, ServiceId, Metric) when is_pid(Pid), is_binary(ServiceId), is_binary(Metric) -> diff --git a/apps/iot/src/endpoint/endpoint_http.erl b/apps/iot/src/endpoint/endpoint_http.erl index fe2f77a..ecfd4fc 100644 --- a/apps/iot/src/endpoint/endpoint_http.erl +++ b/apps/iot/src/endpoint/endpoint_http.erl @@ -46,7 +46,7 @@ start_link(LocalName, AliasName, Endpoint = #endpoint{config = #http_endpoint{}} {stop, Reason :: term()} | ignore). init([AliasName, Endpoint]) -> Buffer = endpoint_buffer:new(Endpoint, 10), - iot_name_server:register(AliasName, self()), + true = gproc:reg({n, l, AliasName}), {ok, #state{endpoint = Endpoint, buffer = Buffer}}. %% @private diff --git a/apps/iot/src/endpoint/endpoint_kafka.erl b/apps/iot/src/endpoint/endpoint_kafka.erl index 273b866..ccd9e99 100644 --- a/apps/iot/src/endpoint/endpoint_kafka.erl +++ b/apps/iot/src/endpoint/endpoint_kafka.erl @@ -51,8 +51,9 @@ start_link(LocalName, AliasName, Endpoint = #endpoint{}) when is_atom(LocalName) %% gen_statem:start_link/[3,4], this function is called by the new %% process to initialize. init([AliasName, Endpoint = #endpoint{id = Id}]) -> - iot_name_server:register(AliasName, self()), erlang:process_flag(trap_exit, true), + true = gproc:reg({n, l, AliasName}), + %% 创建转发器, 避免阻塞当前进程的创建,因此采用了延时初始化的机制 erlang:start_timer(0, self(), connect), %% 初始化存储 diff --git a/apps/iot/src/endpoint/endpoint_mqtt.erl b/apps/iot/src/endpoint/endpoint_mqtt.erl index 6133b1f..59dfc43 100644 --- a/apps/iot/src/endpoint/endpoint_mqtt.erl +++ b/apps/iot/src/endpoint/endpoint_mqtt.erl @@ -53,8 +53,8 @@ start_link(LocalName, AliasName, Endpoint = #endpoint{}) when is_atom(LocalName) %% gen_statem:start_link/[3,4], this function is called by the new %% process to initialize. init([AliasName, Endpoint]) -> - iot_name_server:register(AliasName, self()), erlang:process_flag(trap_exit, true), + true = gproc:reg({n, l, AliasName}), %% 创建转发器, 避免阻塞当前进程的创建,因此采用了延时初始化的机制 erlang:start_timer(0, self(), create_postman), %% 初始化存储