Files
spring-functions-catalog/samples/time-spel-log
dependabot[bot] 3f041a9399 Bump org.springframework.cloud:spring-cloud-dependencies
Bumps [org.springframework.cloud:spring-cloud-dependencies](https://github.com/spring-cloud/spring-cloud-release) from 2023.0.3 to 2023.0.4.
- [Release notes](https://github.com/spring-cloud/spring-cloud-release/releases)
- [Commits](https://github.com/spring-cloud/spring-cloud-release/compare/v2023.0.3...v2023.0.4)

---
updated-dependencies:
- dependency-name: org.springframework.cloud:spring-cloud-dependencies
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-12-02 14:46:52 -05:00
..
2024-01-12 16:58:51 -05:00
2024-01-12 16:58:51 -05:00
2024-01-12 16:58:51 -05:00
2024-01-12 16:58:51 -05:00
2024-01-12 16:58:51 -05:00
2024-01-12 16:58:51 -05:00

= Simple Function Composition from Catalog

This sample demonstrates a composition of functions from the catalog based on https://spring.io/projects/spring-cloud-function[Spring Cloud Function] framework.
The goal and configuration of the sample is very simple and straightforward.

It uses these dependencies:

[source,groovy]
----
implementation 'org.springframework.cloud:spring-cloud-function-context'
implementation 'org.springframework.cloud.fn:spring-time-supplier'
implementation 'org.springframework.cloud.fn:spring-spel-function'
implementation 'org.springframework.cloud.fn:spring-log-consumer'
----

The first one is for `FunctionCatalog` and functions composition configuration.
The rest are artifacts from Spring Functions Catalog with auto-configuration for respective function.

These functions are composed via standard property: `spring.cloud.function.definition = timeSupplier|spelFunction|logConsumer`.
Then we provide some customization for specific function using its configuration properties:

[source,properties]
----
#Emit only seconds from time supplier
time.date-format = ss
#Suffix seconds emitted by the time supplier with some text
spel.function.expression = "'Current seconds: ' + payload"
----

The Log Consumer is left without any customization deliberately to demonstrate that there is some default auto-configuration applied.

Since we deal in this sample with pure Spring Cloud Function framework, there is no any out-of-the-box triggers to initiate data flow from our function composition.
Therefore, we use `@Scheduled` API in the sample application to call `Runnable.run()` every second which was provided by the default `FunctionCatalog.lookup(null)`.

You can see this function composition in action running the application from the IDE or using Spring Boot Gradle plugin via `./gradlew bootRun`.

The `@SpringBootTest` in this sample ensures that log output contains `Current seconds:` text.