In your VerneMQ plugin's rebar.config
:
{deps, [
{vmq_util, {git, "https://github.com/dcy/vmq_util", {branch, "master"}}}
]}.
- is_register/1
- is_online/1
- disconnect/1
- get_online_amount/0
- get_all_amount/0
- get_registers_info/0
- sub_topic/2
- sub_topics/2
- unsub_topic/2
- unsub_topics/2
- get_subed_topics/1
-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
-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
-spec disconnect(Id :: binary() | tuple()) -> ok | ignore.
([email protected])56> vmq_util:disconnect({[], <<"test6">>}).
ok
([email protected])57> vmq_util:disconnect(<<"test1">>).
ok
-spec get_online_amount() -> integer().
([email protected])58> vmq_util:get_online_amount().
1
-spec get_all_amount() -> integer().
([email protected])59> vmq_util:get_all_amount().
3
-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}
-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
-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
-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
-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
-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}]