From 84be602aa503f2bc7f221337d66597368ccb4f2e Mon Sep 17 00:00:00 2001 From: Riccardo Binetti Date: Mon, 4 May 2020 19:00:42 +0200 Subject: [PATCH] vernemq_dev_api: add has_session/1 function Allow checking if a given SubscriberID has an existing session --- doc/vernemq_dev_api.html | 10 ++++++++++ src/vernemq_dev_api.erl | 15 +++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/doc/vernemq_dev_api.html b/doc/vernemq_dev_api.html index 7131dc7..8467599 100644 --- a/doc/vernemq_dev_api.html +++ b/doc/vernemq_dev_api.html @@ -37,6 +37,7 @@

topic()

Function Index

+
disconnect_by_subscriber_id/2Disconnect a client by subscriber_id()
has_session/1Check if a subscriber_id() has an existing session.
unword_topic/1Convert a topic() list into an iolist() which can be flattened into a binary.
@@ -52,6 +53,15 @@

disconnect_by_subsc Given a subscriber_id the client is looked up in the cluster and disconnected.

+

has_session/1

+
+

has_session(SId) -> true | false +

+

Check if a subscriber_id() has an existing session

+ + Given a subscriber_id, this function checks if it has an existing + session.

+

unword_topic/1

unword_topic(Topic) -> iolist() diff --git a/src/vernemq_dev_api.erl b/src/vernemq_dev_api.erl index 222408f..9063f4e 100644 --- a/src/vernemq_dev_api.erl +++ b/src/vernemq_dev_api.erl @@ -17,6 +17,7 @@ -export([unword_topic/1, disconnect_by_subscriber_id/2, + has_session/1, reauthorize_subscriptions/3]). -type disconnect_flag() :: do_cleanup. @@ -36,6 +37,20 @@ disconnect_by_subscriber_id(SubscriberId, Opts) -> vmq_queue:force_disconnect(QueuePid, normal, proplists:get_bool(do_cleanup, Opts)) end. +%% @doc Check if a {@link subscriber_id().} has an existing session +%% +%% Given a subscriber_id, this function checks if it has an existing +%% session. +-spec has_session(SId) -> true | false when + SId :: subscriber_id(). +has_session(SubscriberId) -> + case vmq_subscriber_db:read(SubscriberId) of + undefined -> + false; + _Subs -> + true + end. + %% @doc Reauthorize subscriptions by username and subscriber_id %% %% Given a username and subscriber_id all subscriptions