diff --git a/src/endpoint/endpoint_subscription.erl b/src/endpoint/endpoint_subscription.erl index 0369af0..8dfcbc2 100644 --- a/src/endpoint/endpoint_subscription.erl +++ b/src/endpoint/endpoint_subscription.erl @@ -90,6 +90,7 @@ init([]) -> %% 同一个SubscriberPid只能订阅同一个topic一次 handle_call(get_subscribers, _From, State = #state{subscribers = Subscribers}) -> {reply, {ok, Subscribers}, State}; + handle_call({subscribe, Topic, SubscriberPid}, _From, State = #state{subscribers = Subscribers}) -> Components = of_components(Topic), case is_valid_components(Components) of @@ -112,6 +113,7 @@ handle_call({subscribe, Topic, SubscriberPid}, _From, State = #state{subscribers false -> {reply, {error, <<"invalid topic name">>}, State} end; + handle_call({unsubscribe, Topic, SubscriberPid}, _From, State = #state{subscribers = Subscribers}) -> {Removed, Reserved} = lists:partition(fun(#subscriber{topic = Topic0, subscriber_pid = SubscriberPid0}) -> Topic =:= Topic0 andalso SubscriberPid =:= SubscriberPid0