add publish/1 api
This commit is contained in:
parent
2c8bb114f9
commit
8b85ce4278
|
@ -418,7 +418,8 @@ validate_frame(?UNSUBSCRIBE, Frame) ->
|
||||||
validate_frame(?SUBSCRIBE, Frame);
|
validate_frame(?SUBSCRIBE, Frame);
|
||||||
|
|
||||||
validate_frame(?SUBSCRIBE, #mqtt_frame{variable = #mqtt_frame_subscribe{topic_table = Topics}}) ->
|
validate_frame(?SUBSCRIBE, #mqtt_frame{variable = #mqtt_frame_subscribe{topic_table = Topics}}) ->
|
||||||
ErrTopics = [Topic || Topic <- Topics, not emqtt_topic:validate({subscribe, Topic})],
|
ErrTopics = [Topic || #mqtt_topic{name=Topic} <- Topics,
|
||||||
|
not emqtt_topic:validate({subscribe, Topic})],
|
||||||
case ErrTopics of
|
case ErrTopics of
|
||||||
[] -> ok;
|
[] -> ok;
|
||||||
_ -> ?ERROR("error topics: ~p", [ErrTopics]), {error, badtopic}
|
_ -> ?ERROR("error topics: ~p", [ErrTopics]), {error, badtopic}
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
-export([topics/0,
|
-export([topics/0,
|
||||||
subscribe/2,
|
subscribe/2,
|
||||||
unsubscribe/2,
|
unsubscribe/2,
|
||||||
|
publish/1,
|
||||||
publish/2,
|
publish/2,
|
||||||
route/2,
|
route/2,
|
||||||
match/1,
|
match/1,
|
||||||
|
@ -52,6 +53,9 @@ subscribe({Topic, Qos}, Client) when is_pid(Client) ->
|
||||||
unsubscribe(Topic, Client) when is_list(Topic) and is_pid(Client) ->
|
unsubscribe(Topic, Client) when is_list(Topic) and is_pid(Client) ->
|
||||||
gen_server2:cast(?MODULE, {unsubscribe, Topic, Client}).
|
gen_server2:cast(?MODULE, {unsubscribe, Topic, Client}).
|
||||||
|
|
||||||
|
publish(Msg=#mqtt_msg{topic=Topic}) ->
|
||||||
|
publish(Topic, Msg).
|
||||||
|
|
||||||
%publish to cluster node.
|
%publish to cluster node.
|
||||||
publish(Topic, Msg) when is_list(Topic) and is_record(Msg, mqtt_msg) ->
|
publish(Topic, Msg) when is_list(Topic) and is_record(Msg, mqtt_msg) ->
|
||||||
lists:foreach(fun(#topic{name=Name, node=Node}) ->
|
lists:foreach(fun(#topic{name=Name, node=Node}) ->
|
||||||
|
|
Loading…
Reference in New Issue