fix: update relup.lux
This commit is contained in:
parent
5d81f159d6
commit
efffc450d0
|
@ -1,36 +1,41 @@
|
||||||
-module(http_server).
|
-module(http_server).
|
||||||
|
|
||||||
-import(minirest, [ return/0
|
-import(minirest, [
|
||||||
, return/1
|
return/0,
|
||||||
]).
|
return/1
|
||||||
|
]).
|
||||||
|
|
||||||
-export([ start/0
|
-export([
|
||||||
, stop/0
|
start/0,
|
||||||
]).
|
stop/0
|
||||||
|
]).
|
||||||
|
|
||||||
-rest_api(#{ name => get_counter
|
-rest_api(#{
|
||||||
, method => 'GET'
|
name => get_counter,
|
||||||
, path => "/counter"
|
method => 'GET',
|
||||||
, func => get_counter
|
path => "/counter",
|
||||||
, descr => "Check counter"
|
func => get_counter,
|
||||||
}).
|
descr => "Check counter"
|
||||||
-rest_api(#{ name => add_counter
|
}).
|
||||||
, method => 'POST'
|
-rest_api(#{
|
||||||
, path => "/counter"
|
name => add_counter,
|
||||||
, func => add_counter
|
method => 'POST',
|
||||||
, descr => "Counter plus one"
|
path => "/counter",
|
||||||
}).
|
func => add_counter,
|
||||||
|
descr => "Counter plus one"
|
||||||
|
}).
|
||||||
|
|
||||||
-export([ get_counter/2
|
-export([
|
||||||
, add_counter/2
|
get_counter/2,
|
||||||
]).
|
add_counter/2
|
||||||
|
]).
|
||||||
|
|
||||||
start() ->
|
start() ->
|
||||||
application:ensure_all_started(minirest),
|
application:ensure_all_started(minirest),
|
||||||
ets:new(relup_test_message, [named_table, public]),
|
ets:new(relup_test_message, [named_table, public]),
|
||||||
Handlers = [{"/", minirest:handler(#{modules => [?MODULE]})}],
|
Handlers = [{"/", minirest:handler(#{modules => [?MODULE]})}],
|
||||||
Dispatch = [{"/[...]", minirest, Handlers}],
|
Dispatch = [{"/[...]", minirest, Handlers}],
|
||||||
minirest:start_http(?MODULE, #{socket_opts => [inet, {port, 8080}]}, Dispatch).
|
minirest:start_http(?MODULE, #{socket_opts => [inet, {port, 7077}]}, Dispatch).
|
||||||
|
|
||||||
stop() ->
|
stop() ->
|
||||||
ets:delete(relup_test_message),
|
ets:delete(relup_test_message),
|
||||||
|
@ -39,12 +44,12 @@ stop() ->
|
||||||
get_counter(_Binding, _Params) ->
|
get_counter(_Binding, _Params) ->
|
||||||
return({ok, ets:info(relup_test_message, size)}).
|
return({ok, ets:info(relup_test_message, size)}).
|
||||||
|
|
||||||
add_counter(_Binding, Params) ->
|
add_counter(_Binding, Params) ->
|
||||||
case lists:keymember(<<"payload">>, 1, Params) of
|
case lists:keymember(<<"payload">>, 1, Params) of
|
||||||
true ->
|
true ->
|
||||||
{value, {<<"id">>, ID}, Params1} = lists:keytake(<<"id">>, 1, Params),
|
{value, {<<"id">>, ID}, Params1} = lists:keytake(<<"id">>, 1, Params),
|
||||||
ets:insert(relup_test_message, {ID, Params1});
|
ets:insert(relup_test_message, {ID, Params1});
|
||||||
_ ->
|
_ ->
|
||||||
ok
|
ok
|
||||||
end,
|
end,
|
||||||
return().
|
return().
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
???Eshell
|
???Eshell
|
||||||
???>
|
???>
|
||||||
!http_server:start().
|
!http_server:start().
|
||||||
?Start http_server listener on 8080 successfully.
|
?Start http_server listener on 7077 successfully.
|
||||||
?ok
|
?ok
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
@ -27,9 +27,6 @@
|
||||||
?SH-PROMPT
|
?SH-PROMPT
|
||||||
|
|
||||||
!cd emqx
|
!cd emqx
|
||||||
!sed -i 's|listener.wss.external[ \t]*=.*|listener.wss.external = 8085|g' etc/emqx.conf
|
|
||||||
!sed -i '/emqx_telemetry/d' data/loaded_plugins
|
|
||||||
|
|
||||||
!./bin/emqx start
|
!./bin/emqx start
|
||||||
?EMQ X .* is started successfully!
|
?EMQ X .* is started successfully!
|
||||||
?SH-PROMPT
|
?SH-PROMPT
|
||||||
|
@ -53,24 +50,27 @@
|
||||||
|
|
||||||
!./bin/emqx_ctl cluster status
|
!./bin/emqx_ctl cluster status
|
||||||
"""???
|
"""???
|
||||||
Cluster status: #{running_nodes => ['emqx2@127.0.0.1','emqx@127.0.0.1'],
|
Cluster status: #{running_nodes => ['emqx2@127.0.0.1','emqx@127.0.0.1'],stopped_nodes => []}
|
||||||
stopped_nodes => []}
|
|
||||||
"""
|
"""
|
||||||
?SH-PROMPT
|
?SH-PROMPT
|
||||||
|
|
||||||
!./bin/emqx_ctl resources create 'web_hook' -i 'resource:691c29ba' -c '{"url": "http://127.0.0.1:8080/counter", "method": "POST"}'
|
## create a webhook data bridge with id "my_webhook"
|
||||||
?created
|
!curl --user admin:public --silent --show-error 'http://localhost:18083/api/v5/bridges' -X 'POST' -H 'Content-Type: application/json' --data-binary '{"name":"my_webhook","method":"post","url":"http://127.0.0.1:7077/counter","headers":{"content-type":"application/json"},"pool_size":4,"enable_pipelining":100,"connect_timeout":"5s","request_timeout":"5s","max_retries":3,"type":"webhook","ssl":{"enable":false,"verify":"verify_none"}}' | jq '.status'
|
||||||
|
?connected
|
||||||
?SH-PROMPT
|
?SH-PROMPT
|
||||||
!./bin/emqx_ctl rules create 'SELECT * FROM "t/#"' '[{"name":"data_to_webserver", "params": {"$$resource": "resource:691c29ba"}}]'
|
|
||||||
?created
|
## create a rule that uses the webhook as action, the rule id = "rule_edsy"
|
||||||
|
!curl --user admin:public --silent --show-error 'http://localhost:18083/api/v5/rules' -X 'POST' -H 'Content-Type: application/json' --data-binary '{"id":"rule_edsy","sql":"SELECT\n *\nFROM\n \"t/#\"","actions":["webhook:my_webhook"]}' | jq '.id'
|
||||||
|
?rule_edsy
|
||||||
?SH-PROMPT
|
?SH-PROMPT
|
||||||
|
|
||||||
[shell emqx]
|
[shell emqx]
|
||||||
!./bin/emqx_ctl resources list
|
## verify the bridges and rules are sync to the other node
|
||||||
?691c29ba
|
!curl --user admin:public --silent --show-error 'http://localhost:18083/api/v5/bridges/webhook:my_webhook' -X 'GET' -H 'Content-Type: application/json' | jq '.name'
|
||||||
|
?my_webhook
|
||||||
?SH-PROMPT
|
?SH-PROMPT
|
||||||
!./bin/emqx_ctl rules list
|
!curl --user admin:public --silent --show-error 'http://localhost:18083/api/v5/rules/rule_edsy' -X 'GET' -H 'Content-Type: application/json' | jq '.id'
|
||||||
?691c29ba
|
?rule_edsy
|
||||||
?SH-PROMPT
|
?SH-PROMPT
|
||||||
|
|
||||||
[shell bench]
|
[shell bench]
|
||||||
|
@ -116,15 +116,10 @@
|
||||||
|
|
||||||
!./bin/emqx_ctl cluster status
|
!./bin/emqx_ctl cluster status
|
||||||
"""???
|
"""???
|
||||||
Cluster status: #{running_nodes => ['emqx2@127.0.0.1','emqx@127.0.0.1'],
|
Cluster status: #{running_nodes => ['emqx2@127.0.0.1','emqx@127.0.0.1'],stopped_nodes => []}
|
||||||
stopped_nodes => []}
|
|
||||||
"""
|
"""
|
||||||
?SH-PROMPT
|
?SH-PROMPT
|
||||||
|
|
||||||
!./bin/emqx_ctl plugins list | grep emqx_management
|
|
||||||
?Plugin\(emqx_management.*active=true\)
|
|
||||||
?SH-PROMPT
|
|
||||||
|
|
||||||
[shell emqx2]
|
[shell emqx2]
|
||||||
!echo "" > log/emqx.log.1
|
!echo "" > log/emqx.log.1
|
||||||
?SH-PROMPT
|
?SH-PROMPT
|
||||||
|
@ -162,15 +157,10 @@
|
||||||
|
|
||||||
!./bin/emqx_ctl cluster status
|
!./bin/emqx_ctl cluster status
|
||||||
"""???
|
"""???
|
||||||
Cluster status: #{running_nodes => ['emqx2@127.0.0.1','emqx@127.0.0.1'],
|
Cluster status: #{running_nodes => ['emqx2@127.0.0.1','emqx@127.0.0.1'],stopped_nodes => []}
|
||||||
stopped_nodes => []}
|
|
||||||
"""
|
"""
|
||||||
?SH-PROMPT
|
?SH-PROMPT
|
||||||
|
|
||||||
!./bin/emqx_ctl plugins list | grep emqx_management
|
|
||||||
?Plugin\(emqx_management.*active=true\)
|
|
||||||
?SH-PROMPT
|
|
||||||
|
|
||||||
## We don't guarantee not to lose a single message!
|
## We don't guarantee not to lose a single message!
|
||||||
## So even if we received 290~300 messages, we consider it as success
|
## So even if we received 290~300 messages, we consider it as success
|
||||||
[shell bench]
|
[shell bench]
|
||||||
|
@ -187,6 +177,11 @@
|
||||||
?\{"data":(29[0-9])|(300),"code":0\}
|
?\{"data":(29[0-9])|(300),"code":0\}
|
||||||
?SH-PROMPT
|
?SH-PROMPT
|
||||||
|
|
||||||
|
## The /counter API is provided by .ci/fvt_test/http_server
|
||||||
|
!curl http://127.0.0.1:7077/counter
|
||||||
|
?\{"data":(29[0-9])|(300),"code":0\}
|
||||||
|
?SH-PROMPT
|
||||||
|
|
||||||
[shell emqx2]
|
[shell emqx2]
|
||||||
!cat log/emqx.log.1 |grep -v 691c29ba |tail -n 100
|
!cat log/emqx.log.1 |grep -v 691c29ba |tail -n 100
|
||||||
-error
|
-error
|
||||||
|
|
Loading…
Reference in New Issue