Search code examples
springspring-cloud-dataflow

Passing arguments to the task in the Spring Cloud Dataflow


I need a Spring Cloud Dataflow Task to pass on the parameters during startup. While I found out how to run it in Spring Data Flow Shell (e. g.: task create my-composed-task --definition "mytaskapp --displayMessage=hello"), I don't know how to refer to these parameters in Java code. Can anyone guide me?


Solution

  • The simplest example can be found in Spring Cloud Task timestamp sample.

    Here, the application prints the current timestamp when it starts; however, there's also the ability to override the format of the timestamp through the setFormat(String format) function.

    For instance, you can create and launch the application as:

    task create myTaskDefinition --definition "timestamp --format='yyyy'"

    task launch myTaskDefinition

    When the launch is successful, instead of the default yyyy-MM-dd HH:mm:ss.SSS, you will see the resulting output in yyyy format.