Add doc for custom result handling [Azure sample]

Fixes #757
This commit is contained in:
onobc
2022-02-28 22:36:14 -06:00
committed by Oleg Zhurakousky
parent 5cdb4b17e6
commit a0d96ffbda

View File

@@ -8,7 +8,7 @@ $ mvn azure-functions:run
---- ----
The `uppercase` function is of the following signature `Function<Message<String>, String> uppercase()`. Its expected input is JSON, The `uppercase` function is of the following signature `Function<Message<String>, String> uppercase()`. Its expected input is JSON,
therefore we need t0 provide the appropriate content-type (in this case `application/json`). therefore we need to provide the appropriate content-type (in this case `application/json`).
Test the function using _curl_ and notice that the URL is formed by concatenating `<function url>/api/<function name>` Test the function using _curl_ and notice that the URL is formed by concatenating `<function url>/api/<function name>`
---- ----
@@ -28,7 +28,7 @@ It is done in implementation of `UppercaseHandler` which extends `FunctionInvoke
NOTE: Implementation of `FunctionInvoker` (your handler), should contain the least amount of code. It is really a type-safe way to define NOTE: Implementation of `FunctionInvoker` (your handler), should contain the least amount of code. It is really a type-safe way to define
and configure function to be recognized as Azure Function. and configure function to be recognized as Azure Function.
Everything else should be delegated to the base `FunctionInvoker` via `handleRequest(..)` callback which will invoke your function, taking care of Everything else should be delegated to the base `FunctionInvoker` via `handleRequest(..)` callback which will invoke your function, taking care of
necessary type conversion, transformation etc. necessary type conversion, transformation etc. One exception to this rule is when custom result handling is required. In that case, the proper post-process method can be overridden as well in order to take control of the results processing.
---- ----
@FunctionName("uppercase") @FunctionName("uppercase")
@@ -111,3 +111,27 @@ Alternatively you can test the function in the Azure Dashboard UI:
---- ----
Please note that the Dashhboard provides by default information on Function Execution Count, Memory Consumption and Execution Time. Please note that the Dashhboard provides by default information on Function Execution Count, Memory Consumption and Execution Time.
==== Custom Result Handling
As noted above, the implementation of `FunctionInvoker` (your handler), should contain the least amount of code possible. However, if custom result handling needs to occur there is a set of methods (named `postProcess**`) that can be overridden in link:../../spring-cloud-function-adapters/spring-cloud-function-adapter-azure/src/main/java/org/springframework/cloud/function/adapter/azure/FunctionInvoker.java[FunctionInvoker.java].
One such example can be seen in link:src/main/java/example/ReactiveEchoCustomResultHandler.java[ReactiveEchoCustomResultHandler.java].
Once the function is deployed it can be tested using _curl_
----
$ curl -H "Content-Type: application/json" localhost:7071/api/echoStream -d '["hello","peepz"]'
# result
Kicked off job for [hello, peepz]
----
The custom result handling takes the Flux returned from the `echoStream` function and adds logging, uppercase mapping, and then subscribes to the publisher. The Azure logs output the following:
----
[2022-03-01T01:36:57.439Z] 2022-02-28 19:36:57.439 INFO 20587 --- [pool-2-thread-2] o.s.boot.SpringApplication : Started application in 0.466 seconds (JVM running for 57.906)
[2022-03-01T01:36:57.462Z] BEGIN echo post-processing work ...
[2022-03-01T01:36:57.462Z] HELLO
[2022-03-01T01:36:57.462Z] PEEPZ
[2022-03-01T01:36:57.463Z] END echo post-processing work
[2022-03-01T01:36:57.463Z] Function "echoStream" (Id: 678cff0b-d958-4fab-967b-e19e0d5d67e8) invoked by Java Worker
----