From e37b00a9e46919118f9f22f4b114735dbda61d01 Mon Sep 17 00:00:00 2001 From: Feng Date: Wed, 16 Dec 2015 11:04:51 +0800 Subject: [PATCH] fix subscriptions cli --- src/emqttd_cli.erl | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/emqttd_cli.erl b/src/emqttd_cli.erl index a7656f9a3..8e6000b4d 100644 --- a/src/emqttd_cli.erl +++ b/src/emqttd_cli.erl @@ -241,19 +241,26 @@ subscriptions(["list"]) -> subscriptions(["show", ClientId]) -> if_subscription(fun() -> - case emqttd_pubsub:lookup(subscription, ClientId) of + case emqttd_pubsub:lookup(subscription, bin(ClientId)) of [] -> ?PRINT_MSG("Not Found.~n"); Records -> print(subscription, ClientId, Records) end end); subscriptions(["add", ClientId, Topic, QoS]) -> - Create = fun(IntQos) -> emqttd_pubsub:create(subscription, {ClientId, Topic, IntQos}) end, + Create = fun(IntQos) -> + Subscription = {bin(ClientId), bin(Topic), IntQos}, + case emqttd_pubsub:create(subscription, Subscription) of + ok -> ?PRINT_MSG("ok~n"); + {error, Error} -> ?PRINT("Error: ~p~n", [Error]) + end + end, if_subscription(fun() -> if_valid_qos(QoS, Create) end); subscriptions(["del", ClientId, Topic]) -> if_subscription(fun() -> - emqttd_pubsub:delete(subscription, {ClientId, Topic}) + Ok = emqttd_pubsub:delete(subscription, {bin(ClientId), bin(Topic)}), + ?PRINT("~p~n", [Ok]) end); subscriptions(_) -> @@ -279,7 +286,8 @@ if_could_print(Tab, Fun) -> if_valid_qos(QoS, Fun) -> try list_to_integer(QoS) of - Int when ?IS_QOS(Int) -> Fun(Int) + Int when ?IS_QOS(Int) -> Fun(Int); + _ -> ?PRINT_MSG("QoS should be 0, 1, 2~n") catch _:_ -> ?PRINT_MSG("QoS should be 0, 1, 2~n") end.