Files
spring-functions-catalog/samples/time-spel-log
dependabot[bot] fd853f6cf1 Bump org.springframework.boot in /samples/time-spel-log (#100)
Bumps [org.springframework.boot](https://github.com/spring-projects/spring-boot) from 3.2.11 to 3.2.12.
- [Release notes](https://github.com/spring-projects/spring-boot/releases)
- [Commits](https://github.com/spring-projects/spring-boot/compare/v3.2.11...v3.2.12)

---
updated-dependencies:
- dependency-name: org.springframework.boot
  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-11-22 16:58:08 +00: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.