You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/modules/ROOT/pages/spring-cloud-function/programming-model.adoc
+33-1Lines changed: 33 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -125,7 +125,39 @@ public Supplier<Flux<String>> someSupplier() {
125
125
Function can also be written in imperative or reactive way, yet unlike Supplier and Consumer there are
126
126
no special considerations for the implementor other then understanding that when used within frameworks
127
127
such as https://spring.io/projects/spring-cloud-stream[Spring Cloud Stream] and others, reactive function is
128
-
invoked only once to pass a reference to the stream (Flux or Mono) and imperative is invoked once per event.
128
+
invoked only once to pass a reference to the stream (i.e., Flux or Mono) and imperative is invoked once per event.
129
+
130
+
[source, java]
131
+
----
132
+
public Function<String, String> uppercase() {
133
+
. . . .
134
+
}
135
+
----
136
+
137
+
[[bifunction]]
138
+
=== BiFunction
139
+
In the event you need to receive some additional data (metadata) with your payload you can always make your function
140
+
signature to receive a Message which contains a map of headers containing such additional information.
141
+
142
+
[source, java]
143
+
----
144
+
public Function<Message<String>, String> uppercase() {
145
+
. . . .
146
+
}
147
+
----
148
+
149
+
To make your function signature a bit lighter and more POJO like there is another approach. You can use `BiFunction`.
150
+
[source, java]
151
+
----
152
+
public BiFunction<String, Map, String> uppercase() {
153
+
. . . .
154
+
}
155
+
----
156
+
157
+
Given that a `Message` only contains two attributes (payload and headers) and `BiFunction` requiring two input parameters the framework will automatically recognise this paradigm and will extract payload from the `Message` passing it as a first argument and the map of headers as the second.
158
+
In this case your functions is also not coupled to Spring’s messaging API.
159
+
Keep in mind that BiFunction requires a strict signature where second argument *must* be a Map.
0 commit comments