Skip to content
Permalink
Browse files
optimize register result check
  • Loading branch information
DLive committed Aug 20, 2019
1 parent 9e22b0f commit a6785db690953ac393fdfbf0e19fe06ed0fae842
Showing 2 changed files with 42 additions and 16 deletions.
@@ -31,21 +31,28 @@ refer(Url, Acc) ->
{ok, RegistryName} = dubbo_registry:setup_register(RegistryUrlInfo),

ConsumerUrl = gen_consumer_url(UrlInfo),
dubbo_registry:register(RegistryName, ConsumerUrl),

case dubbo_registry:register(RegistryName, ConsumerUrl) of
{ok,Result}->
logger:info("registry ~p register success ~p",[RegistryName,Result]);
{error,Reason1} ->
logger:warning("registry ~p register fail ~p ~p",[RegistryName,Reason1,ConsumerUrl])
end,
dubbo_directory:subscribe(RegistryName, ConsumerUrl),
{ok,Acc}.

export(Invoker, Acc) ->
{ok, UrlInfo} = dubbo_common_fun:parse_url(Invoker#invoker.url),
%% url = registry://127.0.0.1:2181/org.apache.dubbo.registry.RegistryService?application=hello-world&dubbo=2.0.2&export=dubbo%3A%2F%2F192.168.1.5%3A20880%2Forg.apache.dubbo.erlang.sample.service.facade.UserOperator%3Fanyhost%3Dtrue%26application%3Dhello-world%26bean.name%3Dorg.apache.dubbo.erlang.sample.service.facade.UserOperator%26bind.ip%3D192.168.1.5%26bind.port%3D20880%26default.deprecated%3Dfalse%26default.dynamic%3Dfalse%26default.register%3Dtrue%26deprecated%3Dfalse%26dubbo%3D2.0.2%26dynamic%3Dfalse%26generic%3Dfalse%26interface%3Dorg.apache.dubbo.erlang.sample.service.facade.UserOperator%26methods%3DqueryUserInfo%2CqueryUserList%2CgenUserId%2CgetUserInfo%26pid%3D11272%26register%3Dtrue%26release%3D2.7.1%26side%3Dprovider%26timestamp%3D1563110211090&pid=11272&registry=zookeeper&release=2.7.1&timestamp=1563110211064
ProtocolUrl = get_provider_url(UrlInfo),
{ok, InterfaceKey} = do_local_export(Invoker, ProtocolUrl),

RegistryUrlInfo = gen_registry_urlinfo(UrlInfo),
{ok, RegistryName} = dubbo_registry:setup_register(RegistryUrlInfo),
dubbo_registry:register(RegistryName, ProtocolUrl),

case dubbo_registry:register(RegistryName, ProtocolUrl) of
{ok,Result}->
logger:info("registry ~p register success ~p",[RegistryName,Result]);
{error,Reason1} ->
logger:warning("registry ~p register fail ~p ~p",[RegistryName,Reason1,ProtocolUrl])
end,
register_export_info(ProtocolUrl, RegistryName, InterfaceKey),
{ok, Acc}.

@@ -63,7 +70,6 @@ unexport(RegistryModule, Url) ->
ok.

do_local_export(Invoker, Url) ->
%% Url = dubbo://127.0.0.1:20880/org.apache.dubbo.erlang.sample.service.facade.UserOperator?anyhost=true&application=hello-world&bean.name=org.apache.dubbo.erlang.sample.service.facade.UserOperator&bind.ip=127.0.0.1&bind.port=20880&default.deprecated=false&default.dynamic=false&default.register=true&deprecated=false&dubbo=2.0.2&dynamic=false&generic=false&interface=org.apache.dubbo.erlang.sample.service.facade.UserOperator&methods=queryUserInfo,queryUserList,genUserId,getUserInfo&pid=90956&register=true&release=2.7.1&side=provider&timestamp=1562725983984
{ok, UrlInfo} = dubbo_common_fun:parse_url(Url),
Protocol = UrlInfo#dubbo_url.scheme,
ProtocolModule = binary_to_existing_atom(<<<<"dubbo_protocol_">>/binary, Protocol/binary>>, latin1),
@@ -33,7 +33,7 @@
code_change/3]).

-define(SERVER, ?MODULE).

-define(CALL_TIMEOUT,20000).
-record(state, {zk_pid, provider_notify_fun}).

%%%===================================================================
@@ -89,11 +89,11 @@ init([]) ->
{stop, Reason :: term(), Reply :: term(), NewState :: #state{}} |
{stop, Reason :: term(), NewState :: #state{}}).
handle_call({do_register, Url}, _From, State) ->
do_register(State#state.zk_pid, Url),
{reply, ok, State};
Result = do_register(State#state.zk_pid, Url),
{reply, Result, State};
handle_call({do_unregister, Url}, _From, State) ->
do_unregister(State#state.zk_pid, Url),
{reply, ok, State};
Result = do_unregister(State#state.zk_pid, Url),
{reply, Result, State};
handle_call({subscribe_provider, InterfaceName, NotifyFun}, _From, #state{zk_pid = ZkPid} = State) ->
logger:debug("subscribe provider ~p notify fun ~p", [InterfaceName, NotifyFun]),
NewState = State#state{provider_notify_fun = NotifyFun},
@@ -177,13 +177,33 @@ start(_Url) ->
dubbo_registry_sup:start_child(?MODULE, {?MODULE, start_link, []}, ?MODULE),
ok.

-spec(register(binary()) -> {ok, Result :: binary()} | {error, any()}).
register(Url) ->
gen_server:call(?SERVER, {do_register, Url}, 10000),
ok.
try gen_server:call(?SERVER, {do_register, Url}, ?CALL_TIMEOUT) of
Result ->
Result
catch
exit:{timeout, _} ->
{error, timeout};
exit:{badrpc, _} ->
{error, badrpc};
_:Reason ->
{error, Reason}
end.

-spec(unregister(binary()) -> {ok, Result :: binary()} | {error, any()}).
unregister(Url) ->
gen_server:call(?SERVER, {do_unregister, Url}, 10000),
ok.
try gen_server:call(?SERVER, {do_unregister, Url}, ?CALL_TIMEOUT) of
Result ->
Result
catch
exit:{timeout, _} ->
{error, timeout};
exit:{badrpc, _} ->
{error, badrpc};
_:Reason ->
{error, Reason}
end.

do_register(Pid, Url) ->
case dubbo_common_fun:parse_url(Url) of
@@ -333,6 +353,6 @@ check_and_create_path(Pid, RootPath, [{Item, CreateType} | Rst]) ->
create_path(Pid, CheckPath, CreateType),
check_and_create_path(Pid, CheckPath, Rst);
{error, R1} ->
logger:debug("check_and_create_path unexist ~p", [R1]),
logger:error("check_and_create_path error ~p", [R1]),
check_and_create_path(Pid, CheckPath, Rst)
end.

0 comments on commit a6785db

Please sign in to comment.