From 4b2c68f4c93f815325e63f8559b6fc789d94e4a4 Mon Sep 17 00:00:00 2001 From: Ery Lee Date: Sun, 18 Jan 2015 14:27:30 +0800 Subject: [PATCH 01/11] slimpp -> emqtt --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c4e51fa93..02283797c 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ eMQTT requires Erlang R17+. ## Startup in Five Minutes ``` -$ git clone git://github.com/slimpp/emqtt.git +$ git clone git://github.com/emqtt/emqtt.git $ cd emqtt From f637aa45c8a2cf8a244f16843026d4245c4d5c75 Mon Sep 17 00:00:00 2001 From: Ery Lee Date: Sun, 18 Jan 2015 16:11:53 +0800 Subject: [PATCH 02/11] fix issue#44: HTTP API should add Qos parameter --- README.md | 12 ++++++----- apps/emqtt/src/emqtt_http.erl | 40 +++++++++++++++++++++++++++-------- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 02283797c..15f2609e8 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,7 @@ eMQTT support http to publish message. Example: ``` -curl -v --basic -u user:passwd -d "topic=/a/b/c&message=hello from http..." -k http://localhost:8883/mqtt/publish +curl -v --basic -u user:passwd -d "qos=1&retain=0&topic=/a/b/c&message=hello from http..." -k http://localhost:8883/mqtt/publish ``` ### URL @@ -135,10 +135,12 @@ HTTP POST http://host:8883/mqtt/publish ### Parameters -Name | Description ------|------------- -topic | MQTT Topic -message | Text Message +Name | Description +--------|--------------- +qos | QoS(0, 1, 2) +retain | Retain(0, 1) +topic | Topic +message | Message ## Design diff --git a/apps/emqtt/src/emqtt_http.erl b/apps/emqtt/src/emqtt_http.erl index e6aa3ccec..481293174 100644 --- a/apps/emqtt/src/emqtt_http.erl +++ b/apps/emqtt/src/emqtt_http.erl @@ -43,15 +43,26 @@ handle(Req) -> handle('POST', "/mqtt/publish", Req) -> Params = mochiweb_request:parse_post(Req), - lager:info("~p~n", [Params]), - Topic = list_to_binary(get_value("topic", Params)), - Message = list_to_binary(get_value("message", Params)), - emqtt_pubsub:publish(#mqtt_message { - topic = Topic, - payload = Message - }), - Req:ok({"text/plan", "ok"}); - + lager:info("HTTP Publish: ~p~n", [Params]), + Qos = int(get_value("qos", "0")), + Retain = bool(get_value("retain", "0")), + Topic = list_to_binary(get_value("topic", Params)), + Message = list_to_binary(get_value("message", Params)), + case {validate(qos, Qos), validate(topic, Topic)} of + {true, true} -> + emqtt_pubsub:publish(#mqtt_message { + qos = Qos, + retain = bool(Retain), + topic = Topic, + payload = Message + }), + Req:ok({"text/plan", <<"ok">>}); + {false, _} -> + Req:respond({400, [], <<"Bad QoS">>}); + {_, false} -> + Req:respond({400, [], <<"Bad Topic">>}) + end; + handle(_Method, _Path, Req) -> Req:not_found(). @@ -69,3 +80,14 @@ authorized(Req) -> user_passwd(BasicAuth) -> list_to_tuple(binary:split(base64:decode(BasicAuth), <<":">>)). +validate(qos, Qos) -> + (Qos >= ?QOS_0) and (Qos =< ?QOS_2); + +validate(topic, Topic) -> + emqtt_topic:validate({publish, Topic}). + +int(S) -> list_to_integer(S). + +bool("0") -> false; +bool("1") -> true. + From e7a4be9669c27c606617d5377330a48250d29027 Mon Sep 17 00:00:00 2001 From: Ery Lee Date: Sun, 18 Jan 2015 16:17:41 +0800 Subject: [PATCH 03/11] fix get_value --- apps/emqtt/src/emqtt_http.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/emqtt/src/emqtt_http.erl b/apps/emqtt/src/emqtt_http.erl index 481293174..d228f1147 100644 --- a/apps/emqtt/src/emqtt_http.erl +++ b/apps/emqtt/src/emqtt_http.erl @@ -44,8 +44,8 @@ handle(Req) -> handle('POST', "/mqtt/publish", Req) -> Params = mochiweb_request:parse_post(Req), lager:info("HTTP Publish: ~p~n", [Params]), - Qos = int(get_value("qos", "0")), - Retain = bool(get_value("retain", "0")), + Qos = int(get_value("qos", Params, "0")), + Retain = bool(get_value("retain", Params, "0")), Topic = list_to_binary(get_value("topic", Params)), Message = list_to_binary(get_value("message", Params)), case {validate(qos, Qos), validate(topic, Topic)} of From 0b09d8a695ab5be684c26421d0a58168bbb6fed5 Mon Sep 17 00:00:00 2001 From: Ery Lee Date: Sun, 18 Jan 2015 16:22:46 +0800 Subject: [PATCH 04/11] fix bool, and route --- apps/emqtt/src/emqtt_http.erl | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/apps/emqtt/src/emqtt_http.erl b/apps/emqtt/src/emqtt_http.erl index d228f1147..5994f6b34 100644 --- a/apps/emqtt/src/emqtt_http.erl +++ b/apps/emqtt/src/emqtt_http.erl @@ -50,12 +50,11 @@ handle('POST', "/mqtt/publish", Req) -> Message = list_to_binary(get_value("message", Params)), case {validate(qos, Qos), validate(topic, Topic)} of {true, true} -> - emqtt_pubsub:publish(#mqtt_message { - qos = Qos, - retain = bool(Retain), - topic = Topic, - payload = Message - }), + emqtt_router:route( + #mqtt_message { qos = Qos, + retain = Retain, + topic = Topic, + payload = Message }), Req:ok({"text/plan", <<"ok">>}); {false, _} -> Req:respond({400, [], <<"Bad QoS">>}); From 9afa7c978785ab2d6c44be5837f7bf629d28d2b4 Mon Sep 17 00:00:00 2001 From: Ery Lee Date: Sun, 18 Jan 2015 16:26:44 +0800 Subject: [PATCH 05/11] fix route dump --- apps/emqtt/src/emqtt_router.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/emqtt/src/emqtt_router.erl b/apps/emqtt/src/emqtt_router.erl index 43e6bd419..618de9303 100644 --- a/apps/emqtt/src/emqtt_router.erl +++ b/apps/emqtt/src/emqtt_router.erl @@ -65,7 +65,7 @@ start_link() -> gen_server:start_link({local, ?SERVER}, ?MODULE, [], []). route(Msg) -> - lager:info("Route message: ~s", [emqtt_message:dump(Msg)]), + lager:info("Route ~s", [emqtt_message:dump(Msg)]), % need to retain? emqtt_server:retain(Msg), % unset flag and pubsub From 3ae463960f4355d6f60b6b1e6e42be67c98e1f39 Mon Sep 17 00:00:00 2001 From: Ery Lee Date: Sun, 18 Jan 2015 16:34:01 +0800 Subject: [PATCH 06/11] ok\n --- apps/emqtt/src/emqtt_http.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/emqtt/src/emqtt_http.erl b/apps/emqtt/src/emqtt_http.erl index 5994f6b34..dfb19e430 100644 --- a/apps/emqtt/src/emqtt_http.erl +++ b/apps/emqtt/src/emqtt_http.erl @@ -55,7 +55,7 @@ handle('POST', "/mqtt/publish", Req) -> retain = Retain, topic = Topic, payload = Message }), - Req:ok({"text/plan", <<"ok">>}); + Req:ok({"text/plan", <<"ok\n">>}); {false, _} -> Req:respond({400, [], <<"Bad QoS">>}); {_, false} -> From 2e3f0bda11ce7d8d8f64656bd3fd131d7e9ad92d Mon Sep 17 00:00:00 2001 From: Ery Lee Date: Sun, 18 Jan 2015 16:36:34 +0800 Subject: [PATCH 07/11] 8883 -> 8083 --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 15f2609e8..3081d6804 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ cd $INSTALL_DIR/emqtt {max_conns, 1024}, {acceptor_pool, 4} ]}, - {http, 8883, [ + {http, 8083, [ {max_conns, 512}, {acceptor_pool, 1} ]} @@ -65,7 +65,7 @@ cd $INSTALL_DIR/emqtt ``` --sname emqtt +-name emqtt@127.0.0.1 -setcookie emqtt @@ -124,13 +124,13 @@ eMQTT support http to publish message. Example: ``` -curl -v --basic -u user:passwd -d "qos=1&retain=0&topic=/a/b/c&message=hello from http..." -k http://localhost:8883/mqtt/publish +curl -v --basic -u user:passwd -d "qos=1&retain=0&topic=/a/b/c&message=hello from http..." -k http://localhost:8083/mqtt/publish ``` ### URL ``` -HTTP POST http://host:8883/mqtt/publish +HTTP POST http://host:8083/mqtt/publish ``` ### Parameters @@ -157,5 +157,6 @@ feng at emqtt.io ## Thanks @hejin1026 (260495915 at qq.com) + @desoulter (assoulter123 at gmail.com) From 0c0f068fc97062bceecbfe9ebf120fd5f36e18ce Mon Sep 17 00:00:00 2001 From: Feng Lee Date: Sun, 18 Jan 2015 22:13:24 +0800 Subject: [PATCH 08/11] closed issues --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d582ef4f7..6523d485a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,8 @@ Test: passed org.eclipse.paho.mqtt.testing/interoperability Test: simple cluster test +Closed Issues: #22, #24, #27, #28, #29, #30, #31, #32, #33, #34, #36, #37, #38, #39, #41, #42, #43 + v0.2.1-beta (2015-01-08) ------------------------ From 2cfcf2bff6fb6af4258a9c7eaf644c0d1342ca0f Mon Sep 17 00:00:00 2001 From: Ery Lee Date: Sun, 18 Jan 2015 22:17:06 +0800 Subject: [PATCH 09/11] 0.3.1-beta --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d582ef4f7..89aefd182 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ eMQTT ChangeLog ================== +v0.3.1-beta (2015-01-24) +------------------------ + +Feature: HTTP POST API to support 'qos', 'retain' parameters + v0.3.0-alpha (2015-01-18) ------------------------ From 91d06f42033337d0ecf70bab139a18d5f03afbb6 Mon Sep 17 00:00:00 2001 From: Feng Lee Date: Sun, 18 Jan 2015 22:17:17 +0800 Subject: [PATCH 10/11] 8083 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 15f2609e8..a1b8fbea7 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ cd $INSTALL_DIR/emqtt {max_conns, 1024}, {acceptor_pool, 4} ]}, - {http, 8883, [ + {http, 8083, [ {max_conns, 512}, {acceptor_pool, 1} ]} From f7a290b1001055996ca2d2f5b84b7cebc33230d6 Mon Sep 17 00:00:00 2001 From: Ery Lee Date: Sun, 18 Jan 2015 22:24:13 +0800 Subject: [PATCH 11/11] v3.1.1 --- README.md | 4 ++-- TODO | 14 -------------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 3081d6804..504f32c17 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # eMQTT -eMQTT is a scalable, fault-tolerant and extensible mqtt broker written in Erlang/OTP. +eMQTT is a scalable, fault-tolerant and extensible MQTT V3.1.1 broker written in Erlang/OTP. -eMQTT support MQTT V3.1 Protocol Specification. +eMQTT support MQTT V3.1/V3.1.1 Protocol Specification. eMQTT requires Erlang R17+. diff --git a/TODO b/TODO index d3ebc89cd..a54ea4635 100644 --- a/TODO +++ b/TODO @@ -27,10 +27,6 @@ fucking stupid..... esockd locked 0.2.1 ===== -full MQTT 3.1.1 support... - -node cluster.... - one million connections test... topic match benchmark tests... @@ -41,14 +37,4 @@ full test cases... spawn_link to replace 'spawn' and 'link' -keepalive - -retained - -QOS - -dural sub - -packet dump... -