diff --git a/README.adoc b/README.adoc index f633a434..53eace02 100644 --- a/README.adoc +++ b/README.adoc @@ -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 diff --git a/applications/source/time-source/src/test/java/org/springframework/cloud/stream/app/source/time/TimeSourceTests.java b/applications/source/time-source/src/test/java/org/springframework/cloud/stream/app/source/time/TimeSourceTests.java index b62361f8..5b1b507f 100644 --- a/applications/source/time-source/src/test/java/org/springframework/cloud/stream/app/source/time/TimeSourceTests.java +++ b/applications/source/time-source/src/test/java/org/springframework/cloud/stream/app/source/time/TimeSourceTests.java @@ -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"); } } diff --git a/applications/stream-applications-core/pom.xml b/applications/stream-applications-core/pom.xml index 5b10107f..5e87ac5d 100644 --- a/applications/stream-applications-core/pom.xml +++ b/applications/stream-applications-core/pom.xml @@ -23,9 +23,9 @@ 2.0.0.M2 3.0.0.M1 3.0.2.RELEASE - 3.0.7.RELEASE + 3.0.8.RELEASE Hoxton.BUILD-SNAPSHOT - Horsham.BUILD-SNAPSHOT + Horsham.SR6 2.1.2.RELEASE 1.0.0-SNAPSHOT 0.9.0 diff --git a/functions/function/payload-converter-function/src/main/java/functions/ToMessage.java b/functions/function/payload-converter-function/src/main/java/functions/ToMessage.java deleted file mode 100644 index f0d80a26..00000000 --- a/functions/function/payload-converter-function/src/main/java/functions/ToMessage.java +++ /dev/null @@ -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> { - @Override - public Message apply(Object o) { - return MessageBuilder.withPayload(o).build(); - } -} diff --git a/functions/spring-functions-parent/pom.xml b/functions/spring-functions-parent/pom.xml index cdeea218..a26b2e22 100644 --- a/functions/spring-functions-parent/pom.xml +++ b/functions/spring-functions-parent/pom.xml @@ -16,7 +16,7 @@ 2.3.0.RELEASE - 3.0.7.RELEASE + 3.0.8.RELEASE ${project.version}