Sfoglia il codice sorgente

feat: support array bridge_mqtt conf

Turtle 4 anni fa
parent
commit
e4f5e9332e

+ 1 - 1
apps/emqx/rebar.config

@@ -15,7 +15,7 @@
     , {esockd, {git, "https://github.com/emqx/esockd", {tag, "5.8.2"}}}
     , {ekka, {git, "https://github.com/emqx/ekka", {tag, "0.10.8"}}}
     , {gen_rpc, {git, "https://github.com/emqx/gen_rpc", {tag, "2.5.1"}}}
-    , {hocon, {git, "https://github.com/emqx/hocon.git", {tag, "0.11.1"}}}
+    , {hocon, {git, "https://github.com/emqx/hocon.git", {tag, "0.12.1"}}}
     , {pbkdf2, {git, "https://github.com/emqx/erlang-pbkdf2.git", {tag, "2.0.4"}}}
     , {recon, {git, "https://github.com/ferd/recon", {tag, "2.5.1"}}}
     , {snabbkaffe, {git, "https://github.com/kafka4beam/snabbkaffe.git", {tag, "0.14.1"}}}

+ 4 - 1
apps/emqx/src/emqx_config.erl

@@ -299,7 +299,7 @@ save_schema_mod_and_names(SchemaMod) ->
     RootNames = SchemaMod:structs(),
     OldMods = get_schema_mod(),
     OldNames = get_root_names(),
-    NewMods = maps:from_list([{bin(Name), SchemaMod} || Name <- RootNames]),
+    NewMods = maps:from_list([{root_bin(Name), SchemaMod} || Name <- RootNames]),
     persistent_term:put(?PERSIS_SCHEMA_MODS, #{
         mods => maps:merge(OldMods, NewMods),
         names => lists:usort(OldNames ++ RootNames)
@@ -440,3 +440,6 @@ conf_key(?CONF, RootName) ->
     atom(RootName);
 conf_key(?RAW_CONF, RootName) ->
     bin(RootName).
+
+root_bin({array, Bin}) -> bin(Bin);
+root_bin(Bin) -> bin(Bin).

+ 52 - 54
apps/emqx_bridge_mqtt/etc/emqx_bridge_mqtt.conf

@@ -2,57 +2,55 @@
 ## Configuration for EMQ X MQTT Broker Bridge
 ##====================================================================
 
-emqx_bridge_mqtt {
-    bridges:[
-        # {
-        #     name: "mqtt1"
-        #     start_type: auto
-        #     forwards: ["test/#"],
-        #     forward_mountpoint: ""
-        #     reconnect_interval: "30s"
-        #     batch_size: 100
-        #     queue {
-        #         replayq_dir: "{{ platform_data_dir }}/replayq/bridge_mqtt/"
-        #         replayq_seg_bytes: "100MB"
-        #         replayq_offload_mode: false
-        #         replayq_max_total_bytes: "1GB"
-        #     },
-        #     config {
-        #         conn_type: mqtt
-        #         address: "127.0.0.1:1883"
-        #         proto_ver: v4
-        #         bridge_mode: true
-        #         clientid: "client1"
-        #         clean_start: true
-        #         username: "username1"
-        #         password: ""
-        #         keepalive: 300
-        #         subscriptions: [{
-        #             topic: "t/#"
-        #             qos: 1
-        #         }]
-        #         receive_mountpoint: ""
-        #         retry_interval: "30s"
-        #         max_inflight: 32
-        #     }
-        # },
-        # {
-        #     name: "rpc1"
-        #     start_type: auto
-        #     forwards: ["test/#"],
-        #     forward_mountpoint: ""
-        #     reconnect_interval: "30s"
-        #     batch_size: 100
-        #     queue {
-        #         replayq_dir: "{{ platform_data_dir }}/replayq/bridge_mqtt/"
-        #         replayq_seg_bytes: "100MB"
-        #         replayq_offload_mode: false
-        #         replayq_max_total_bytes: "1GB"
-        #     },
-        #     config {
-        #         conn_type: rpc
-        #         node: "emqx@127.0.0.1"
-        #     }
-        # }
-    ]
-}
+bridge_mqtt: [
+    # {
+    #     name: "mqtt1"
+    #     start_type: auto
+    #     forwards: ["test/#"],
+    #     forward_mountpoint: ""
+    #     reconnect_interval: "30s"
+    #     batch_size: 100
+    #     queue {
+    #         replayq_dir: "{{ platform_data_dir }}/replayq/bridge_mqtt/"
+    #         replayq_seg_bytes: "100MB"
+    #         replayq_offload_mode: false
+    #         replayq_max_total_bytes: "1GB"
+    #     },
+    #     config {
+    #         conn_type: mqtt
+    #         address: "127.0.0.1:1883"
+    #         proto_ver: v4
+    #         bridge_mode: true
+    #         clientid: "client1"
+    #         clean_start: true
+    #         username: "username1"
+    #         password: ""
+    #         keepalive: 300
+    #         subscriptions: [{
+    #             topic: "t/#"
+    #             qos: 1
+    #         }]
+    #         receive_mountpoint: ""
+    #         retry_interval: "30s"
+    #         max_inflight: 32
+    #     }
+    # },
+    # {
+    #     name: "rpc1"
+    #     start_type: auto
+    #     forwards: ["test/#"],
+    #     forward_mountpoint: ""
+    #     reconnect_interval: "30s"
+    #     batch_size: 100
+    #     queue {
+    #         replayq_dir: "{{ platform_data_dir }}/replayq/bridge_mqtt/"
+    #         replayq_seg_bytes: "100MB"
+    #         replayq_offload_mode: false
+    #         replayq_max_total_bytes: "1GB"
+    #     },
+    #     config {
+    #         conn_type: rpc
+    #         node: "emqx@127.0.0.1"
+    #     }
+    # }
+]

+ 2 - 6
apps/emqx_bridge_mqtt/src/emqx_bridge_mqtt_schema.erl

@@ -23,13 +23,9 @@
 -export([ structs/0
         , fields/1]).
 
-structs() -> ["emqx_bridge_mqtt"].
+structs() -> [{array, "bridge_mqtt"}].
 
-fields("emqx_bridge_mqtt") ->
-    [ {bridges, hoconsc:array(hoconsc:ref(?MODULE, "bridges"))}
-    ];
-
-fields("bridges") ->
+fields("bridge_mqtt") ->
     [ {name, emqx_schema:t(string(), undefined, true)}
     , {start_type, fun start_type/1}
     , {forwards, fun forwards/1}

+ 2 - 1
apps/emqx_machine/src/emqx_machine_schema.erl

@@ -204,7 +204,8 @@ fields(Name) ->
 find_field(Name, []) ->
     error({unknown_config_struct_field, Name});
 find_field(Name, [SchemaModule | Rest]) ->
-    case lists:member(Name, SchemaModule:structs()) of
+    case lists:member(Name, SchemaModule:structs()) orelse
+        lists:keymember(Name, 2, SchemaModule:structs()) of
         true -> SchemaModule:fields(Name);
         false -> find_field(Name, Rest)
     end.

+ 1 - 1
rebar.config

@@ -61,7 +61,7 @@
     , {observer_cli, "1.6.1"} % NOTE: depends on recon 2.5.1
     , {getopt, "1.0.2"}
     , {snabbkaffe, {git, "https://github.com/kafka4beam/snabbkaffe.git", {tag, "0.14.1"}}}
-    , {hocon, {git, "https://github.com/emqx/hocon.git", {tag, "0.11.1"}}}
+    , {hocon, {git, "https://github.com/emqx/hocon.git", {tag, "0.12.1"}}}
     , {emqx_http_lib, {git, "https://github.com/emqx/emqx_http_lib.git", {tag, "0.4.0"}}}
     , {esasl, {git, "https://github.com/emqx/esasl", {tag, "0.2.0"}}}
     ]}.