refactor(mqtt connector): to use emqx_connector_info
This commit refactors the mqtt connector to use the `emqx_connector_info` behavior.
This commit is contained in:
parent
223bbc05fe
commit
12717baa0b
|
@ -10,7 +10,10 @@
|
||||||
emqx_resource,
|
emqx_resource,
|
||||||
emqtt
|
emqtt
|
||||||
]},
|
]},
|
||||||
{env, []},
|
{env, [
|
||||||
|
{emqx_action_info_modules, [emqx_bridge_mqtt_pubsub_action_info]},
|
||||||
|
{emqx_connector_info_modules, [emqx_bridge_mqtt_pubsub_connector_info]}
|
||||||
|
]},
|
||||||
{modules, []},
|
{modules, []},
|
||||||
{licenses, ["Apache 2.0"]},
|
{licenses, ["Apache 2.0"]},
|
||||||
{links, []}
|
{links, []}
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
%% Copyright (c) 2020-2024 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_bridge_mqtt_pubsub_connector_info).
|
||||||
|
|
||||||
|
-behaviour(emqx_connector_info).
|
||||||
|
|
||||||
|
-export([
|
||||||
|
type_name/0,
|
||||||
|
bridge_types/0,
|
||||||
|
resource_callback_module/0,
|
||||||
|
config_schema/0,
|
||||||
|
schema_module/0,
|
||||||
|
api_schema/1
|
||||||
|
]).
|
||||||
|
|
||||||
|
type_name() ->
|
||||||
|
mqtt.
|
||||||
|
|
||||||
|
bridge_types() ->
|
||||||
|
[mqtt].
|
||||||
|
|
||||||
|
resource_callback_module() ->
|
||||||
|
emqx_bridge_mqtt_connector.
|
||||||
|
|
||||||
|
config_schema() ->
|
||||||
|
{mqtt,
|
||||||
|
hoconsc:mk(
|
||||||
|
hoconsc:map(name, hoconsc:ref(emqx_bridge_mqtt_connector_schema, "config_connector")),
|
||||||
|
#{
|
||||||
|
desc => <<"MQTT Connector Config">>,
|
||||||
|
required => false
|
||||||
|
}
|
||||||
|
)}.
|
||||||
|
|
||||||
|
schema_module() ->
|
||||||
|
emqx_bridge_mqtt_connector_schema.
|
||||||
|
|
||||||
|
api_schema(Method) ->
|
||||||
|
emqx_connector_schema:api_ref(
|
||||||
|
emqx_bridge_mqtt_connector_schema, <<"mqtt">>, Method ++ "_connector"
|
||||||
|
).
|
|
@ -81,7 +81,10 @@ hard_coded_connector_info_modules_ee() ->
|
||||||
-endif.
|
-endif.
|
||||||
|
|
||||||
hard_coded_connector_info_modules_common() ->
|
hard_coded_connector_info_modules_common() ->
|
||||||
[emqx_bridge_http_connector_info].
|
[
|
||||||
|
emqx_bridge_http_connector_info,
|
||||||
|
emqx_bridge_mqtt_pubsub_connector_info
|
||||||
|
].
|
||||||
|
|
||||||
hard_coded_connector_info_modules() ->
|
hard_coded_connector_info_modules() ->
|
||||||
hard_coded_connector_info_modules_common() ++ hard_coded_connector_info_modules_ee().
|
hard_coded_connector_info_modules_common() ++ hard_coded_connector_info_modules_ee().
|
||||||
|
|
|
@ -88,10 +88,6 @@ connector_impl_module(ConnectorType) ->
|
||||||
|
|
||||||
-endif.
|
-endif.
|
||||||
|
|
||||||
connector_to_resource_type_ce(mqtt) ->
|
|
||||||
emqx_bridge_mqtt_connector;
|
|
||||||
% connector_to_resource_type_ce(mqtt_subscriber) ->
|
|
||||||
% emqx_bridge_mqtt_subscriber_connector;
|
|
||||||
connector_to_resource_type_ce(ConnectorType) ->
|
connector_to_resource_type_ce(ConnectorType) ->
|
||||||
try
|
try
|
||||||
emqx_connector_info:resource_callback_module(ConnectorType)
|
emqx_connector_info:resource_callback_module(ConnectorType)
|
||||||
|
|
|
@ -88,11 +88,7 @@ enterprise_fields_connectors() -> [].
|
||||||
-endif.
|
-endif.
|
||||||
|
|
||||||
api_schemas(Method) ->
|
api_schemas(Method) ->
|
||||||
[
|
[].
|
||||||
%% We need to map the `type' field of a request (binary) to a
|
|
||||||
%% connector schema module.
|
|
||||||
api_ref(emqx_bridge_mqtt_connector_schema, <<"mqtt">>, Method ++ "_connector")
|
|
||||||
].
|
|
||||||
|
|
||||||
api_ref(Module, Type, Method) ->
|
api_ref(Module, Type, Method) ->
|
||||||
{Type, ref(Module, Method)}.
|
{Type, ref(Module, Method)}.
|
||||||
|
@ -111,11 +107,10 @@ examples(Method) ->
|
||||||
|
|
||||||
-if(?EMQX_RELEASE_EDITION == ee).
|
-if(?EMQX_RELEASE_EDITION == ee).
|
||||||
schema_modules() ->
|
schema_modules() ->
|
||||||
[emqx_bridge_mqtt_connector_schema] ++
|
emqx_connector_ee_schema:schema_modules() ++ connector_info_schema_modules().
|
||||||
emqx_connector_ee_schema:schema_modules() ++ connector_info_schema_modules().
|
|
||||||
-else.
|
-else.
|
||||||
schema_modules() ->
|
schema_modules() ->
|
||||||
[emqx_bridge_mqtt_connector_schema] ++ connector_info_schema_modules().
|
connector_info_schema_modules().
|
||||||
-endif.
|
-endif.
|
||||||
|
|
||||||
connector_info_schema_modules() ->
|
connector_info_schema_modules() ->
|
||||||
|
@ -127,8 +122,6 @@ connector_info_schema_modules() ->
|
||||||
|
|
||||||
%% @doc Return old bridge(v1) and/or connector(v2) type
|
%% @doc Return old bridge(v1) and/or connector(v2) type
|
||||||
%% from the latest connector type name.
|
%% from the latest connector type name.
|
||||||
connector_type_to_bridge_types(mqtt) ->
|
|
||||||
[mqtt];
|
|
||||||
connector_type_to_bridge_types(redis) ->
|
connector_type_to_bridge_types(redis) ->
|
||||||
[redis, redis_single, redis_sentinel, redis_cluster];
|
[redis, redis_single, redis_sentinel, redis_cluster];
|
||||||
connector_type_to_bridge_types(rocketmq) ->
|
connector_type_to_bridge_types(rocketmq) ->
|
||||||
|
@ -505,16 +498,7 @@ roots() ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
fields(connectors) ->
|
fields(connectors) ->
|
||||||
[
|
[] ++ enterprise_fields_connectors() ++ connector_info_fields_connectors();
|
||||||
{mqtt,
|
|
||||||
mk(
|
|
||||||
hoconsc:map(name, ref(emqx_bridge_mqtt_connector_schema, "config_connector")),
|
|
||||||
#{
|
|
||||||
desc => <<"MQTT Publisher Connector Config">>,
|
|
||||||
required => false
|
|
||||||
}
|
|
||||||
)}
|
|
||||||
] ++ enterprise_fields_connectors() ++ connector_info_fields_connectors();
|
|
||||||
fields("node_status") ->
|
fields("node_status") ->
|
||||||
[
|
[
|
||||||
node_name(),
|
node_name(),
|
||||||
|
|
Loading…
Reference in New Issue