Skip to content

Latest commit

 

History

History
138 lines (113 loc) · 3.6 KB

README.md

File metadata and controls

138 lines (113 loc) · 3.6 KB

vmq_util

Install

In your VerneMQ plugin's rebar.config:

{deps, [
  {vmq_util, {git, "https://github.com/dcy/vmq_util", {branch, "master"}}}
]}.

API

is_register

-spec is_register(Id :: binary() | tuple()) -> true | false.

([email protected])38> vmq_util:is_register(<<"test1">>).
true
([email protected])39> vmq_util:is_register({[], <<"test100">>}).
false

is_online

-spec is_online(Id :: binary() | tuple()) -> true | false.

([email protected])50> vmq_util:is_online(<<"test1">>).
false
([email protected])51> vmq_util:is_online({[], <<"test6">>}).
true

disconnect

-spec disconnect(Id :: binary() | tuple()) -> ok | ignore.

([email protected])56> vmq_util:disconnect({[], <<"test6">>}).
ok
([email protected])57> vmq_util:disconnect(<<"test1">>).      
ok

get_online_amount

-spec get_online_amount() -> integer().

([email protected])58> vmq_util:get_online_amount().
1

get_all_amount

-spec get_all_amount() -> integer().

([email protected])59> vmq_util:get_all_amount().   
3

get_registers_info

-type register_info() :: #{all => integer(), online => integer()}.
-spec get_registers_info() -> register_info().

([email protected])60> vmq_util:get_registers_info().
#{all => 3,online => 1}

sub_topic

-type topic() :: {binary(), integer()}.
-type topics() :: list(topic()).
-spec sub_topic(Id :: binary() | tuple(), Topic :: topic()) -> ok | {error, any()}.
%%sub_topic(<<"test1">>, {<<"inbox/test1">>, 1}).

([email protected])61> vmq_util:sub_topic(<<"test6">>, {<<"inbox/test6">>, 1}).
ok
([email protected])62> vmq_util:sub_topic({[], <<"test8">>}, {<<"inbox/test8">>, 1}).
no_the_subscriber_id
([email protected])63> vmq_util:sub_topic({[], <<"test6">>}, {<<"inbox/test8">>, 1}).
ok

sub_topics

-spec sub_topics(Id :: binary() | tuple(), Topics :: topics()) -> ok | {error, any()}.
%%sub_topics(<<"test1">>, [{<<"inbox/test1">>, 1}]).

([email protected])65> vmq_util:sub_topics(<<"test6">>, [{<<"inbox/test1">>, 1}, {<<"inbox/test2">>, 1}]).
ok
([email protected])66> vmq_util:sub_topics({[], <<"test6">>}, [{<<"inbox/test1">>, 1}, {<<"inbox/test2">>, 1}]).
ok

unsub_topic

-spec unsub_topic(Id :: binary() | tuple(), Topic :: binary()) -> ok | {error, any()}.
%%unsub_topic(<<"test1">>, <<"inbox/test">>).

([email protected])68> vmq_util:unsub_topic(<<"test6">>, <<"inbox/test1">>).
ok
([email protected])69> vmq_util:unsub_topic({[], <<"test6">>}, <<"inbox/test1">>).
ok

unsub_topics

-spec unsub_topics(Id :: binary() | tuple(), Topics :: topics()) -> ok | {error, any()}.

([email protected])70> vmq_util:unsub_topics({[], <<"test6">>}, [<<"inbox/test1">>, <<"inbox/test2">>]).
ok
([email protected])71> vmq_util:unsub_topics(<<"test6">>, [<<"inbox/test1">>, <<"inbox/test2">>]).      
ok

get_subed_topics

-spec get_subed_topics(Id :: binary() | tuple()) -> list({topic(), integer()}).

([email protected])72> vmq_util:get_subed_topics(<<"test6">>).
[{[<<"inbox">>,<<"test6">>],1},
 {[<<"inbox">>,<<"test8">>],1}]
([email protected])73> vmq_util:get_subed_topics({[], <<"test6">>}).
[{[<<"inbox">>,<<"test6">>],1},
 {[<<"inbox">>,<<"test8">>],1}]