emqx/apps/emqx_resource
Zaiming Shi e6232665a3 refactor(emqx): ensure app shutdown and reboot order
make use of application dependency to ensure start order.
also the same dependency top-sorted for shutdown and reboot order
2021-08-04 08:40:03 +02:00
..
examples The config handler phase2 (#5052) 2021-06-25 11:47:18 +08:00
include change resource,connectors,data_bridges as normal apps (#5034) 2021-06-19 16:27:21 +08:00
scripts feat(emqx_resource): add behaviour emqx_resource 2021-05-28 21:43:54 +08:00
src refactor(emqx): ensure app shutdown and reboot order 2021-08-04 08:40:03 +02:00
Makefile feat(emqx_resource): add behaviour emqx_resource 2021-05-28 21:43:54 +08:00
README.md feat(emqx_resource): update the demo.md 2021-06-08 21:46:52 +08:00
demo.sh feat(emqx_resource): add behaviour emqx_resource 2021-05-28 21:43:54 +08:00
elvis.config feat(emqx_resource): add behaviour emqx_resource 2021-05-28 21:43:54 +08:00
rebar.config fix(emqx_resource): disable the debug print for parse-transformed code 2021-06-07 22:11:05 +08:00

README.md

emqx_resource

The emqx_resource is a behavior that manages configuration specs and runtime states for resources like mysql or redis backends.

It is intended to be used by the emqx_data_bridges and all other resources that need CRUD operations to their configs, and need to initialize the states when creating.

There can be foreign references between resource instances via resource-id. So they may find each other via this Id.

The main idea of the emqx resource is to put all the general code in a common lib, including the config operations (like config validation, config dump back to files), and the state management. And we put all the specific codes to the callback modules.

Try it out

$ ./demo.sh
Eshell V11.1.8  (abort with ^G)
1> == the demo log tracer <<"log_tracer_clientid_shawn">> started.
config: #{<<"config">> =>
            #{<<"bulk">> => <<"10KB">>,<<"cache_log_dir">> => <<"/tmp">>,
                <<"condition">> => #{<<"clientid">> => <<"abc">>},
                <<"level">> => <<"debug">>},
        <<"id">> => <<"log_tracer_clientid_shawn">>,
        <<"resource_type">> => <<"log_tracer">>}
1> emqx_resource_instance:health_check(<<"log_tracer_clientid_shawn">>).
== the demo log tracer <<"log_tracer_clientid_shawn">> is working well
state: #{health_checked => 1,logger_handler_id => abc}
ok

2> emqx_resource_instance:health_check(<<"log_tracer_clientid_shawn">>).
== the demo log tracer <<"log_tracer_clientid_shawn">> is working well
state: #{health_checked => 2,logger_handler_id => abc}
ok

3> emqx_resource_instance:query(<<"log_tracer_clientid_shawn">>, get_log).
== the demo log tracer <<"log_tracer_clientid_shawn">> received request: get_log
state: #{health_checked => 2,logger_handler_id => abc}
"this is a demo log messages..."

4> emqx_resource_instance:remove(<<"log_tracer_clientid_shawn">>).
== the demo log tracer <<"log_tracer_clientid_shawn">> stopped.
state: #{health_checked => 0,logger_handler_id => abc}
ok

5> emqx_resource_instance:query(<<"log_tracer_clientid_shawn">>, get_log).
** exception error: {get_instance,{<<"log_tracer_clientid_shawn">>,not_found}}