@@ -59,6 +59,43 @@ transmit headers from any adapter that supports key-value metadata
|
||||
|
||||
|===
|
||||
|
||||
==== Supplier
|
||||
As you can see from the table above Supplier can be _reactive_ - `Supplier<Flux<T>>`
|
||||
or _imperative_ - `Supplier<T>`. From the invocation standpoint this should make no difference
|
||||
to the implementor of such Supplier. However, when used within frameworks
|
||||
(e.g., https://spring.io/projects/spring-cloud-stream[Spring Cloud Stream]), Suppliers, especially reactive,
|
||||
often used to represent the source of the stream, therefore they are invoked once to get the stream (e.g., Flux)
|
||||
to which consumers can subscribe to. In other words such suppliers represent an equivalent of an _infinite stream_.
|
||||
However, the same reactive suppliers can also represent _finite_ stream(s) (e.g., result set on the polled JDBC data).
|
||||
In those cases such reactive suppliers must be hooked up to some polling mechanism of the underlying framework.
|
||||
|
||||
To assist with that Spring Cloud Function provides a marker annotation
|
||||
`org.springframework.cloud.function.context.PollableSupplier` to signal that such supplier produces a
|
||||
finite stream and may need to be polled again. That said, it is important to understand that Spring Cloud Function itself
|
||||
provides no behavior for this annotation.
|
||||
|
||||
In addition `PollableSupplier` annotation exposes a _splittable_ attribute to signal that produced stream
|
||||
needs to be split (see https://www.enterpriseintegrationpatterns.com/patterns/messaging/Sequencer.html[Splitter EIP])
|
||||
|
||||
Here is the example:
|
||||
|
||||
[source, java]
|
||||
----
|
||||
@PollableSupplier(splittable = true)
|
||||
public Supplier<Flux<String>> someSupplier() {
|
||||
return () -> {
|
||||
String v1 = String.valueOf(System.nanoTime());
|
||||
String v2 = String.valueOf(System.nanoTime());
|
||||
String v3 = String.valueOf(System.nanoTime());
|
||||
return Flux.just(v1, v2, v3);
|
||||
};
|
||||
}
|
||||
----
|
||||
|
||||
==== Function
|
||||
TBD
|
||||
|
||||
==== Consumer
|
||||
Consumer is a little bit special because it has a `void` return type,
|
||||
which implies blocking, at least potentially. Most likely you will not
|
||||
need to write `Consumer<Flux<?>>`, but if you do need to do that,
|
||||
|
||||
Reference in New Issue
Block a user