docs(message transformation): add api examples

Fixes https://emqx.atlassian.net/browse/EMQX-12645
This commit is contained in:
Thales Macedo Garitezi 2024-07-05 09:59:27 -03:00
parent c7f4e85760
commit 36ee7bed77
1 changed files with 24 additions and 28 deletions

View File

@ -452,18 +452,12 @@ ref(Struct) -> hoconsc:ref(?MODULE, Struct).
mk(Type, Opts) -> hoconsc:mk(Type, Opts). mk(Type, Opts) -> hoconsc:mk(Type, Opts).
array(Type) -> hoconsc:array(Type). array(Type) -> hoconsc:array(Type).
%% FIXME: all examples
example_input_create() -> example_input_create() ->
#{ #{
<<"sql_check">> => <<"message_transformation">> =>
#{ #{
summary => <<"Using a SQL check">>, summary => <<"Simple message transformation">>,
value => example_transformation([example_sql_check()]) value => example_transformation()
},
<<"avro_check">> =>
#{
summary => <<"Using an Avro schema check">>,
value => example_transformation([example_avro_check()])
} }
}. }.
@ -472,7 +466,7 @@ example_input_update() ->
<<"update">> => <<"update">> =>
#{ #{
summary => <<"Update">>, summary => <<"Update">>,
value => example_transformation([example_sql_check()]) value => example_transformation()
} }
}. }.
@ -493,20 +487,28 @@ example_input_dryrun_transformation() ->
#{ #{
summary => <<"Test an input against a configuration">>, summary => <<"Test an input against a configuration">>,
value => #{ value => #{
todo => true message => #{
client_attrs => #{},
payload => <<"{}">>,
qos => 2,
retain => true,
topic => <<"t/u/v">>,
user_property => #{}
},
transformation => example_transformation()
} }
} }
}. }.
example_return_list() -> example_return_list() ->
OtherVal0 = example_transformation([example_avro_check()]), OtherVal0 = example_transformation(),
OtherVal = OtherVal0#{name => <<"other_transformation">>}, OtherVal = OtherVal0#{name => <<"other_transformation">>},
#{ #{
<<"list">> => <<"list">> =>
#{ #{
summary => <<"List">>, summary => <<"List">>,
value => [ value => [
example_transformation([example_sql_check()]), example_transformation(),
OtherVal OtherVal
] ]
} }
@ -547,29 +549,23 @@ example_return_metrics() ->
} }
}. }.
example_transformation(Checks) -> example_transformation() ->
#{ #{
name => <<"my_transformation">>, name => <<"my_transformation">>,
enable => true, enable => true,
description => <<"my transformation">>, description => <<"my transformation">>,
tags => [<<"transformation">>], tags => [<<"transformation">>],
topics => [<<"t/+">>], topics => [<<"t/+">>],
strategy => <<"all_pass">>,
failure_action => <<"drop">>, failure_action => <<"drop">>,
log_failure => #{<<"level">> => <<"info">>}, log_failure => #{<<"level">> => <<"info">>},
checks => Checks payload_decoder => #{<<"type">> => <<"json">>},
}. payload_encoder => #{<<"type">> => <<"json">>},
operations => [
example_sql_check() -> #{
#{ key => <<"topic">>,
type => <<"sql">>, value => <<"concat([topic, '/', payload.t])">>
sql => <<"select payload.temp as t where t > 10">> }
}. ]
example_avro_check() ->
#{
type => <<"avro">>,
schema => <<"my_avro_schema">>
}. }.
error_schema(Code, Message) -> error_schema(Code, Message) ->