Forráskód Böngészése

fix: topic rewrite action type add all

DDDHuang 4 éve
szülő
commit
60e815fb9a

+ 12 - 0
apps/emqx_modules/etc/emqx_modules.conf

@@ -33,6 +33,18 @@ rewrite: [
     #     source_topic = "x/#"
     #     re = "^x/y/(.+)$"
     #     dest_topic = "z/y/$1"
+    # },
+    # {
+    #     action = subscribe
+    #     source_topic = "x1/#"
+    #     re = "^x1/y/(.+)$"
+    #     dest_topic = "z1/y/$1"
+    # },
+    # {
+    #     action = all
+    #     source_topic = "x2/#"
+    #     re = "^x2/y/(.+)$"
+    #     dest_topic = "z2/y/$1"
     # }
 ]
 

+ 1 - 1
apps/emqx_modules/src/emqx_modules_schema.erl

@@ -45,7 +45,7 @@ fields("delayed") ->
     ];
 
 fields("rewrite") ->
-    [ {action, hoconsc:enum([publish, subscribe])}
+    [ {action, hoconsc:enum([publish, subscribe, all])}
     , {source_topic, sc(binary(), #{})}
     , {re, sc(binary(), #{})}
     , {dest_topic, sc(binary(), #{})}

+ 3 - 1
apps/emqx_modules/src/emqx_rewrite.erl

@@ -95,7 +95,9 @@ compile(Rules) ->
             publish ->
                 {[{Topic, MP, Dest} | Acc1], Acc2};
             subscribe ->
-                {Acc1, [{Topic, MP, Dest} | Acc2]}
+                {Acc1, [{Topic, MP, Dest} | Acc2]};
+            all ->
+                {[{Topic, MP, Dest} | Acc1], [{Topic, MP, Dest} | Acc2]}
         end
     end, {[], []}, Rules).
 

+ 1 - 1
apps/emqx_modules/src/emqx_rewrite_api.erl

@@ -35,7 +35,7 @@ api_spec() ->
     {[rewrite_api()], []}.
 
 properties() ->
-    properties([{action, string, <<"Node">>, [subscribe, publish]},
+    properties([{action, string, <<"Action">>, [subscribe, publish, all]},
                 {source_topic, string, <<"Topic">>},
                 {re, string, <<"Regular expressions">>},
                 {dest_topic, string, <<"Destination topic">>}]).