Provide new config options for streams enabling composition

User can switch off source or sink behaviour (the default is to bind
to input and output streams), and then configure the name of a
supplier (for a source) or consumer (for a sink).
This commit is contained in:
Dave Syer
2018-03-16 11:10:54 -04:00
parent efc99d2af0
commit 0be5f14766
10 changed files with 921 additions and 55 deletions

View File

@@ -58,13 +58,13 @@ one-per-jar. It's up to the developer to choose. An app with multiple
functions can be deployed multiple times in different "personalities",
exposing different functions over different physical transports.
== Deploying a Packaged Function
TBD: describe the deployer app.
== Dynamic Compilation
To run these examples, change into the `scripts` directory:
There is a sample app that uses the function compiler to create a
function from a configuration property. The vanilla "function-sample"
also has that feature. And there are some examples that you can run to
see the compilation happening at run time. To run these examples,
change into the `scripts` directory:
----
cd scripts

View File

@@ -18,3 +18,58 @@ include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/maste
== Getting Started
include::getting-started.adoc[]
== Standalone Web Applications
The `spring-cloud-function-web` module has autoconfiguration that
activates when it is included in a Spring Boot web application (with
MVC support). There is also a `spring-cloud-starter-function-web` to
collect all the optional dependnecies in case you just want a simple
getting started experience.
With the web configurations activated your app will have an MVC
endpoint (on "/" by default, but configurable with
`spring.cloud.function.web.path`) that can be used to access the
functions in the application context. The supported content types are
plain text and JSON.
|===
| Method | Path | Request | Response | Status
| GET | /{supplier} | - | Items from the named supplier | 200 OK
| POST | /{consumer} | JSON object or text | Mirrors input and pushes request body into consumer | 202 Accepted
| POST | /{consumer} | JSON array or text with new lines | Mirrors input and pushes body into consumer one by one | 202 Accepted
| POST | /{function} | JSON object or text | The result of applying the named function | 200 OK
| POST | /{function} | JSON array or text with new lines | The result of applying the named function | 200 OK
| GET | /{function}/{item} | - | Convert the item into an object and return the result of applying the function | 200 OK
|===
As the table above shows the behaviour of the endpoint depends on the method and also the type of incoming request data. When the incoming data is single valued, and the target function is declared as obviously single valued (i.e. not returning a collection or `Flux`), then the response will also contain a single value. For multi-valued responses the client can ask for a server-sent event stream by sending `Accept: text/event-stream". If there is only one function (consumer etc.) then the name in the path is optional. Composite functions can be addressed using pipes or commas to separate function names (pipes are legal in URL paths, but a bit awkward to type on the command line).
Functions and consumers that are declared with input and output in `Message<?>` will see the request headers on the input messages, and the output message headers will be converted to HTTP headers.
== Standalone Streaming Applications
To send or receive messages from a broker (such as RabbitMQ or Kafka) you can use the `spring-cloud-function-stream` adapter. Add the adapter to your classpath along with the appropriate binder from Spring Cloud Stream. The adapter will bind to the message broker as a `Processor` (input and output streams) unless the user explicitly disables one or the other using `spring.cloud.function.stream.{source,sink}.enabled=false`.
An incoming message is routed to a function (or consumer). If there is only one, then the choice is obvious. If there are multiple functions that can accept an incoming message, the message is inspected to see if there is a `stream_routekey` header containing the name of a function. The header is also added to outgoing messages from a supplier. Messages with no route key can be routed exclusively to a function or consumer by specifying `spring.cloud.function.stream.{processor,sink}.name`. A single supplier can be chosen for output messages (if more than one is available) using the `spring.cloud.function.stream.supplier.name`. Routing headers or function names can be composed using a comma or pipe separated name.
NOTE: some binders will fail on startup if the message broker is not available and the function catalog contains suppliers that immediately produce messages when accessed. You can switch off the automatic publishing from suppliers on startup using the `spring.cloud.function.strean.supplier.enabled=false` flag.
== Serverless Platform Adapters
As well as being able to run as a standalone process, a Spring Cloud
Function application can be adapted to run one of the existing
servlerless platforms. In the project there are adapters for
https://github.com/spring-cloud/spring-cloud-function/tree/master/spring-cloud-function-adapters/spring-cloud-function-adapter-aws[AWS
Lambda],
https://github.com/spring-cloud/spring-cloud-function/tree/master/spring-cloud-function-adapters/spring-cloud-function-adapter-azure[Azure],
and
https://github.com/spring-cloud/spring-cloud-function/tree/master/spring-cloud-function-adapters/spring-cloud-function-adapter-openwhisk[Apache
OpenWhisk]. The Oracle Fn platform has its own Spring Cloud Function adapter.
== Deploying a Packaged Function
TBD: describe the deployer app.