Revert "chore: mv emqx_connector to emqx_data_bridge"
This reverts commit d640e2ccfa
.
This commit is contained in:
parent
786fd6fe3e
commit
271869b817
|
@ -0,0 +1,19 @@
|
||||||
|
.rebar3
|
||||||
|
_*
|
||||||
|
.eunit
|
||||||
|
*.o
|
||||||
|
*.beam
|
||||||
|
*.plt
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
.erlang.cookie
|
||||||
|
ebin
|
||||||
|
log
|
||||||
|
erl_crash.dump
|
||||||
|
.rebar
|
||||||
|
logs
|
||||||
|
_build
|
||||||
|
.idea
|
||||||
|
*.iml
|
||||||
|
rebar3.crashdump
|
||||||
|
*~
|
|
@ -0,0 +1,27 @@
|
||||||
|
# emqx_connector
|
||||||
|
|
||||||
|
This application is a collection of `connectors`.
|
||||||
|
|
||||||
|
A `connector` is a callback module of `emqx_resource` that maintains the data related to
|
||||||
|
external resources. Put all resource related callback modules in a single application is good as
|
||||||
|
we can put some util functions/modules here for reusing purpose.
|
||||||
|
|
||||||
|
For example, a mysql connector is an emqx resource that maintains all the mysql connection
|
||||||
|
related parameters (configs) and the TCP connections to the mysql server.
|
||||||
|
|
||||||
|
An mysql connector can be used as following:
|
||||||
|
|
||||||
|
```
|
||||||
|
(emqx@127.0.0.1)5> emqx_resource:list_instances_verbose().
|
||||||
|
[#{config =>
|
||||||
|
#{auto_reconnect => true,cacertfile => [],certfile => [],
|
||||||
|
database => "mqtt",keyfile => [],password => "public",
|
||||||
|
pool_size => 1,
|
||||||
|
server => {{127,0,0,1},3306},
|
||||||
|
ssl => false,user => "root",verify => false},
|
||||||
|
id => <<"mysql-abc">>,mod => emqx_connector_mysql,
|
||||||
|
state => #{poolname => 'mysql-abc'},
|
||||||
|
status => started}]
|
||||||
|
(emqx@127.0.0.1)6> emqx_resource:query(<<"mysql-abc">>, {sql, <<"SELECT count(1)">>}).
|
||||||
|
{ok,[<<"count(1)">>],[[1]]}
|
||||||
|
```
|
|
@ -0,0 +1,4 @@
|
||||||
|
##--------------------------------------------------------------------
|
||||||
|
## EMQ X CONNECTOR Plugin
|
||||||
|
##--------------------------------------------------------------------
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
%%-*- mode: erlang -*-
|
||||||
|
%% emqx_connector config mapping
|
|
@ -0,0 +1,13 @@
|
||||||
|
{erl_opts, [
|
||||||
|
nowarn_unused_import,
|
||||||
|
debug_info
|
||||||
|
]}.
|
||||||
|
|
||||||
|
{deps, [
|
||||||
|
{mysql, {git, "https://github.com/emqx/mysql-otp", {tag, "1.7.1"}}}
|
||||||
|
]}.
|
||||||
|
|
||||||
|
{shell, [
|
||||||
|
% {config, "config/sys.config"},
|
||||||
|
{apps, [emqx_connector]}
|
||||||
|
]}.
|
|
@ -0,0 +1,17 @@
|
||||||
|
{application, emqx_connector,
|
||||||
|
[{description, "An OTP application"},
|
||||||
|
{vsn, "0.1.0"},
|
||||||
|
{registered, []},
|
||||||
|
{mod, {emqx_connector_app, []}},
|
||||||
|
{applications,
|
||||||
|
[kernel,
|
||||||
|
stdlib,
|
||||||
|
emqx_resource,
|
||||||
|
ecpool
|
||||||
|
]},
|
||||||
|
{env,[]},
|
||||||
|
{modules, []},
|
||||||
|
|
||||||
|
{licenses, ["Apache 2.0"]},
|
||||||
|
{links, []}
|
||||||
|
]}.
|
|
@ -0,0 +1,16 @@
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
%% Copyright (c) 2020-2021 EMQ Technologies Co., Ltd. All Rights Reserved.
|
||||||
|
%%
|
||||||
|
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
%% you may not use this file except in compliance with the License.
|
||||||
|
%% You may obtain a copy of the License at
|
||||||
|
%%
|
||||||
|
%% http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
%%
|
||||||
|
%% Unless required by applicable law or agreed to in writing, software
|
||||||
|
%% distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
%% See the License for the specific language governing permissions and
|
||||||
|
%% limitations under the License.
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
-module(emqx_connector).
|
|
@ -0,0 +1,31 @@
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
%% Copyright (c) 2020-2021 EMQ Technologies Co., Ltd. All Rights Reserved.
|
||||||
|
%%
|
||||||
|
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
%% you may not use this file except in compliance with the License.
|
||||||
|
%% You may obtain a copy of the License at
|
||||||
|
%%
|
||||||
|
%% http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
%%
|
||||||
|
%% Unless required by applicable law or agreed to in writing, software
|
||||||
|
%% distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
%% See the License for the specific language governing permissions and
|
||||||
|
%% limitations under the License.
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
|
-module(emqx_connector_app).
|
||||||
|
|
||||||
|
-behaviour(application).
|
||||||
|
|
||||||
|
-emqx_plugin(?MODULE).
|
||||||
|
|
||||||
|
-export([start/2, stop/1]).
|
||||||
|
|
||||||
|
start(_StartType, _StartArgs) ->
|
||||||
|
emqx_connector_sup:start_link().
|
||||||
|
|
||||||
|
stop(_State) ->
|
||||||
|
ok.
|
||||||
|
|
||||||
|
%% internal functions
|
|
@ -15,7 +15,7 @@
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-module(emqx_connector_ldap).
|
-module(emqx_connector_ldap).
|
||||||
|
|
||||||
-include("emqx_data_bridge.hrl").
|
-include("emqx_connector.hrl").
|
||||||
-include_lib("typerefl/include/types.hrl").
|
-include_lib("typerefl/include/types.hrl").
|
||||||
-include_lib("emqx_resource/include/emqx_resource_behaviour.hrl").
|
-include_lib("emqx_resource/include/emqx_resource_behaviour.hrl").
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-module(emqx_connector_mongo).
|
-module(emqx_connector_mongo).
|
||||||
|
|
||||||
-include("emqx_data_bridge.hrl").
|
-include("emqx_connector.hrl").
|
||||||
-include_lib("typerefl/include/types.hrl").
|
-include_lib("typerefl/include/types.hrl").
|
||||||
-include_lib("emqx_resource/include/emqx_resource_behaviour.hrl").
|
-include_lib("emqx_resource/include/emqx_resource_behaviour.hrl").
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-module(emqx_connector_redis).
|
-module(emqx_connector_redis).
|
||||||
|
|
||||||
-include("emqx_data_bridge.hrl").
|
-include("emqx_connector.hrl").
|
||||||
-include_lib("typerefl/include/types.hrl").
|
-include_lib("typerefl/include/types.hrl").
|
||||||
-include_lib("emqx_resource/include/emqx_resource_behaviour.hrl").
|
-include_lib("emqx_resource/include/emqx_resource_behaviour.hrl").
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-module(emqx_connector_schema_lib).
|
-module(emqx_connector_schema_lib).
|
||||||
|
|
||||||
-include("emqx_data_bridge.hrl").
|
-include("emqx_connector.hrl").
|
||||||
-include_lib("typerefl/include/types.hrl").
|
-include_lib("typerefl/include/types.hrl").
|
||||||
|
|
||||||
-export([ relational_db_fields/0
|
-export([ relational_db_fields/0
|
|
@ -0,0 +1,36 @@
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
%% Copyright (c) 2020-2021 EMQ Technologies Co., Ltd. All Rights Reserved.
|
||||||
|
%%
|
||||||
|
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
%% you may not use this file except in compliance with the License.
|
||||||
|
%% You may obtain a copy of the License at
|
||||||
|
%%
|
||||||
|
%% http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
%%
|
||||||
|
%% Unless required by applicable law or agreed to in writing, software
|
||||||
|
%% distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
%% See the License for the specific language governing permissions and
|
||||||
|
%% limitations under the License.
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
-module(emqx_connector_sup).
|
||||||
|
|
||||||
|
-behaviour(supervisor).
|
||||||
|
|
||||||
|
-export([start_link/0]).
|
||||||
|
|
||||||
|
-export([init/1]).
|
||||||
|
|
||||||
|
-define(SERVER, ?MODULE).
|
||||||
|
|
||||||
|
start_link() ->
|
||||||
|
supervisor:start_link({local, ?SERVER}, ?MODULE, []).
|
||||||
|
|
||||||
|
init([]) ->
|
||||||
|
SupFlags = #{strategy => one_for_all,
|
||||||
|
intensity => 0,
|
||||||
|
period => 1},
|
||||||
|
ChildSpecs = [],
|
||||||
|
{ok, {SupFlags, ChildSpecs}}.
|
||||||
|
|
||||||
|
%% internal functions
|
|
@ -0,0 +1,16 @@
|
||||||
|
%%-*- mode: erlang -*-
|
||||||
|
%% emqx_data_bridge config mapping
|
||||||
|
|
||||||
|
{mapping, "emqx_data_bridge.bridges", "emqx_data_bridge.bridges", [
|
||||||
|
{default, []},
|
||||||
|
{datatype, string}
|
||||||
|
]}.
|
||||||
|
|
||||||
|
% fields("emqx_data_bridge") ->
|
||||||
|
% [
|
||||||
|
% {bridges,
|
||||||
|
% [fun(mapping) -> "emqx_data_bridge.bridges";
|
||||||
|
% (type) -> list();
|
||||||
|
% (_) -> undefined
|
||||||
|
% end]}
|
||||||
|
% ]
|
|
@ -1,6 +1,5 @@
|
||||||
{erl_opts, [debug_info]}.
|
{erl_opts, [debug_info]}.
|
||||||
{deps, []}.
|
{deps, []}.
|
||||||
% {extra_src_dirs, [{"src", [{recursive, true}]}]}.
|
|
||||||
|
|
||||||
{shell, [
|
{shell, [
|
||||||
% {config, "config/sys.config"},
|
% {config, "config/sys.config"},
|
||||||
|
|
|
@ -5,8 +5,7 @@
|
||||||
{mod, {emqx_data_bridge_app, []}},
|
{mod, {emqx_data_bridge_app, []}},
|
||||||
{applications,
|
{applications,
|
||||||
[kernel,
|
[kernel,
|
||||||
stdlib,
|
stdlib
|
||||||
ecpool
|
|
||||||
]},
|
]},
|
||||||
{env,[]},
|
{env,[]},
|
||||||
{modules, []},
|
{modules, []},
|
||||||
|
|
|
@ -25,9 +25,8 @@
|
||||||
]).
|
]).
|
||||||
|
|
||||||
load_bridges() ->
|
load_bridges() ->
|
||||||
ConfFile = filename:join([emqx:get_env(plugins_etc_dir), ?MODULE]) ++ ".conf",
|
Bridges = proplists:get_value(bridges,
|
||||||
{ok, #{<<"emqx_data_bridge">> := RawConfig}} = hocon:load(ConfFile),
|
application:get_all_env(emqx_data_bridge), []),
|
||||||
Bridges = maps:get(<<"bridges">>, RawConfig, []),
|
|
||||||
emqx_data_bridge_monitor:ensure_all_started(Bridges).
|
emqx_data_bridge_monitor:ensure_all_started(Bridges).
|
||||||
|
|
||||||
resource_type(<<"mysql">>) -> emqx_connector_mysql;
|
resource_type(<<"mysql">>) -> emqx_connector_mysql;
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
%%-*- mode: erlang -*-
|
||||||
|
%% emqx-resource config mapping
|
|
@ -5,4 +5,7 @@
|
||||||
{emqx_retainer, {{enable_plugin_emqx_retainer}}}.
|
{emqx_retainer, {{enable_plugin_emqx_retainer}}}.
|
||||||
{emqx_telemetry, {{enable_plugin_emqx_telemetry}}}.
|
{emqx_telemetry, {{enable_plugin_emqx_telemetry}}}.
|
||||||
{emqx_rule_engine, {{enable_plugin_emqx_rule_engine}}}.
|
{emqx_rule_engine, {{enable_plugin_emqx_rule_engine}}}.
|
||||||
|
{emqx_resource, {{enable_plugin_emqx_resource}}}.
|
||||||
|
{emqx_connector, {{enable_plugin_emqx_connector}}}.
|
||||||
|
{emqx_data_bridge, {{enable_plugin_emqx_data_bridge}}}.
|
||||||
{emqx_bridge_mqtt, {{enable_plugin_emqx_bridge_mqtt}}}.
|
{emqx_bridge_mqtt, {{enable_plugin_emqx_bridge_mqtt}}}.
|
||||||
|
|
|
@ -193,6 +193,9 @@ overlay_vars_rel(RelType) ->
|
||||||
end,
|
end,
|
||||||
[ {enable_plugin_emqx_rule_engine, RelType =:= cloud}
|
[ {enable_plugin_emqx_rule_engine, RelType =:= cloud}
|
||||||
, {enable_plugin_emqx_bridge_mqtt, RelType =:= edge}
|
, {enable_plugin_emqx_bridge_mqtt, RelType =:= edge}
|
||||||
|
, {enable_plugin_emqx_resource, true}
|
||||||
|
, {enable_plugin_emqx_connector, true}
|
||||||
|
, {enable_plugin_emqx_data_bridge, true}
|
||||||
, {enable_plugin_emqx_modules, false} %% modules is not a plugin in ce
|
, {enable_plugin_emqx_modules, false} %% modules is not a plugin in ce
|
||||||
, {enable_plugin_emqx_recon, true}
|
, {enable_plugin_emqx_recon, true}
|
||||||
, {enable_plugin_emqx_retainer, true}
|
, {enable_plugin_emqx_retainer, true}
|
||||||
|
@ -251,8 +254,6 @@ relx_apps(ReleaseType) ->
|
||||||
, {emqx_plugin_libs, load}
|
, {emqx_plugin_libs, load}
|
||||||
, observer_cli
|
, observer_cli
|
||||||
, emqx_http_lib
|
, emqx_http_lib
|
||||||
, emqx_resource
|
|
||||||
, emqx_data_bridge
|
|
||||||
]
|
]
|
||||||
++ [emqx_modules || not is_enterprise()]
|
++ [emqx_modules || not is_enterprise()]
|
||||||
++ [emqx_license || is_enterprise()]
|
++ [emqx_license || is_enterprise()]
|
||||||
|
@ -290,8 +291,10 @@ relx_plugin_apps(ReleaseType) ->
|
||||||
, emqx_auth_mnesia
|
, emqx_auth_mnesia
|
||||||
, emqx_web_hook
|
, emqx_web_hook
|
||||||
, emqx_recon
|
, emqx_recon
|
||||||
, emqx_rule_engine
|
, emqx_resource
|
||||||
|
, emqx_connector
|
||||||
, emqx_data_bridge
|
, emqx_data_bridge
|
||||||
|
, emqx_rule_engine
|
||||||
, emqx_sasl
|
, emqx_sasl
|
||||||
]
|
]
|
||||||
++ [emqx_telemetry || not is_enterprise()]
|
++ [emqx_telemetry || not is_enterprise()]
|
||||||
|
|
Loading…
Reference in New Issue