Upgrade Spring Cloud Stream to Horsham.SR6 and Spring Cloud Function to 3.0.8.RELEASE
This commit is contained in:
@@ -129,7 +129,7 @@ or any combination of the above, without requiring a separate processor.
|
||||
For example, the time source executed, as shown below, will perform a series of transformations to publish a task launch request every second to the rabbit exchange `time-test`.
|
||||
|
||||
```
|
||||
java -jar target/time-source-rabbit-3.0.0-SNAPSHOT.jar --spring.cloud.stream.bindings.output.destination=time-test --spring.cloud.stream.function.definition="timeSupplier|toMessage|spelFunction|headerEnricherFunction|taskLaunchRequestFunction" --spel.function.expression="payload.length()" --header.enricher.headers=task-id=payload*2 --task.launch.request.task-name-expression="'task-'+headers['task-id']"
|
||||
java -jar target/time-source-rabbit-3.0.0-SNAPSHOT.jar --spring.cloud.stream.bindings.output.destination=time-test --spring.cloud.stream.function.definition="timeSupplier|spelFunction|headerEnricherFunction|taskLaunchRequestFunction" --spel.function.expression="payload.length()" --header.enricher.headers=task-id=payload*2 --task.launch.request.task-name-expression="'task-'+headers['task-id']"
|
||||
```
|
||||
|
||||
The transformed message looks like this:
|
||||
@@ -146,14 +146,11 @@ Encoding: string
|
||||
|
||||
Let's upack this function definition:
|
||||
|
||||
`timeSupplier|toMessage|spelFunction|headerEnricherFunction|taskLaunchRequestFunction`
|
||||
`timeSupplier|spelFunction|headerEnricherFunction|taskLaunchRequestFunction`
|
||||
|
||||
This creates a composed Supplier beginning with the default `timeSupplier` which is the foundation for `time-source`.
|
||||
This produces a String like `06/18/20 16:01:38`. We transform this using the SpEL expression `payload.length()`.
|
||||
The `spelFunction` applies to a `Message` from which we can extract and transform the `payload` or `headers`, in accordance with common Spring Integration conventions.
|
||||
We first need to wrap the date String in a message, using `toMessage`.
|
||||
|
||||
NOTE: This step will be incorporated into a future release of Spring Cloud Function so may be omitted.
|
||||
|
||||
The output of `spelFunction` is the length of the date-time String, `17`.
|
||||
From here we apply the header enricher to add a Message header, `task-id` with the value of `payload*2` or ,`34`.
|
||||
@@ -168,7 +165,7 @@ Please see the individual function documentation for an explanation of its confi
|
||||
|
||||
NOTE: Support for composite functions includes auto-configuration for conventional binding name mappings (`input` and `output`) derived from the function definition and the presence of `spring.cloud.stream.bindings.output...`.
|
||||
In this example, `--spring.cloud.stream.bindings.output.destination=time-test` is enabled behind the scenes by the auto-configured property
|
||||
`--spring.cloud.stream.function.bindings.timeSuppliertoMessagespelFunctionheaderEnricherFunctiontaskLaunchRequestFunction-out-0=output`.
|
||||
`--spring.cloud.stream.function.bindings.timeSupplierspelFunctionheaderEnricherFunctiontaskLaunchRequestFunction-out-0=output`.
|
||||
|
||||
=== Build
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ public class TimeSourceTests {
|
||||
TestChannelBinderConfiguration
|
||||
.getCompleteConfiguration(TimeSourceTestApplication.class))
|
||||
.web(WebApplicationType.NONE)
|
||||
.run("--spring.cloud.stream.function.definition=timeSupplier|toMessage|spelFunction",
|
||||
.run("--spring.cloud.stream.function.definition=timeSupplier|spelFunction",
|
||||
"--spel.function.expression=payload.length()")) {
|
||||
|
||||
OutputDestination target = context.getBean(OutputDestination.class);
|
||||
@@ -88,7 +88,7 @@ public class TimeSourceTests {
|
||||
TestChannelBinderConfiguration
|
||||
.getCompleteConfiguration(TimeSourceTestApplication.class))
|
||||
.web(WebApplicationType.NONE)
|
||||
.run("--spring.cloud.stream.function.definition=timeSupplier|toMessage|spelFunction|headerEnricherFunction|taskLaunchRequestFunction",
|
||||
.run("--spring.cloud.stream.function.definition=timeSupplier|spelFunction|headerEnricherFunction|taskLaunchRequestFunction",
|
||||
"--spel.function.expression=payload.length()",
|
||||
"--header.enricher.headers=task-id=payload*2",
|
||||
"--spring.cloud.stream.bindings.output.destination=foo",
|
||||
@@ -100,7 +100,7 @@ public class TimeSourceTests {
|
||||
TaskLaunchRequest.class);
|
||||
assertThat(taskLaunchRequest.getTaskName()).isEqualTo("task-34");
|
||||
assertThat(context.getEnvironment().getProperty(
|
||||
"spring.cloud.stream.function.bindings.timeSuppliertoMessagespelFunctionheaderEnricherFunctiontaskLaunchRequestFunction-out-0"))
|
||||
"spring.cloud.stream.function.bindings.timeSupplierspelFunctionheaderEnricherFunctiontaskLaunchRequestFunction-out-0"))
|
||||
.isEqualTo("output");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,9 +23,9 @@
|
||||
<scst-app-maven-plugin.version>2.0.0.M2</scst-app-maven-plugin.version>
|
||||
<stream-apps-docs-plugin.version>3.0.0.M1</stream-apps-docs-plugin.version>
|
||||
<spring-cloud-stream.version>3.0.2.RELEASE</spring-cloud-stream.version>
|
||||
<spring-cloud-function-dependencies.version>3.0.7.RELEASE</spring-cloud-function-dependencies.version>
|
||||
<spring-cloud-function-dependencies.version>3.0.8.RELEASE</spring-cloud-function-dependencies.version>
|
||||
<spring-cloud-dependencies.version>Hoxton.BUILD-SNAPSHOT</spring-cloud-dependencies.version>
|
||||
<spring-cloud-stream-dependencies.version>Horsham.BUILD-SNAPSHOT</spring-cloud-stream-dependencies.version>
|
||||
<spring-cloud-stream-dependencies.version>Horsham.SR6</spring-cloud-stream-dependencies.version>
|
||||
<java-cfenv-boot.version>2.1.2.RELEASE</java-cfenv-boot.version>
|
||||
<java-functions.version>1.0.0-SNAPSHOT</java-functions.version>
|
||||
<prometheus-rsocket.version>0.9.0</prometheus-rsocket.version>
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Copyright 2020-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package functions;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
|
||||
/**
|
||||
* Wrap a POJO as a message.
|
||||
*
|
||||
*/
|
||||
// TODO: Remove when https://github.com/spring-cloud/spring-cloud-function/issues/550 is
|
||||
// resolved.
|
||||
public class ToMessage implements Function<Object, Message<?>> {
|
||||
@Override
|
||||
public Message<?> apply(Object o) {
|
||||
return MessageBuilder.withPayload(o).build();
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
<properties>
|
||||
<spring-boot.version>2.3.0.RELEASE</spring-boot.version>
|
||||
<spring-cloud-function.version>3.0.7.RELEASE</spring-cloud-function.version>
|
||||
<spring-cloud-function.version>3.0.8.RELEASE</spring-cloud-function.version>
|
||||
<spring-cloud-fn.version>${project.version}</spring-cloud-fn.version>
|
||||
</properties>
|
||||
<dependencyManagement>
|
||||
|
||||
Reference in New Issue
Block a user