Allows a user to launch tasks from a stream. This is done by creating a sink that
listens for a message that contains a TaskLaunchRequest
as its payload. The
TaskLaunchRequest contains the maven coordinates to the Task that is to be executed. It
also has a Map that contains the environment variables that will be used by the Task.
If the payload is of a different type then the sink will throw an exception.
For example a stream can be created that has a processor that takes in data from a
http source and creates a GenericMessage
that contains the TaskLaunchRequest
and sends
the message to its output channel. The task sink would then receive the message from its
input channnel and then launch the task.
To create a taskSink a user needs to only create a spring boot app that includes the
following annotation EnableTaskLauncher
. The code would look something like this:
@SpringBootApplication @EnableTaskLauncher public class TaskSinkApplication { public static void main(String[] args) { SpringApplication.run(TaskSinkApplication.class, args); } }
A sample Sink and Processor have been made available to you in the samples module
of the Spring Cloud Task project. To install these samples into your local maven
repository execute a maven build from the spring-cloud-task-samples
directory with the
property skipInstall
set to false. For example:
mvn clean install
.
The maven.remoteRepositories.springRepo.url property will need to be set to the location of the remote repository from which the über-jar is located. If not set, then there will be no remote repository, so it will rely upon the local repository only.
To create a stream in Spring Cloud Data Flow first we would want to register the Task Sink Application we created. In the example below we are registering the Processor and Sink sample applications using the Spring Cloud Data Flow shell:
app register --name taskSink --type sink --uri maven://io.spring.cloud:tasksink:<version> app register --name taskProcessor --type processor --uri maven:io.spring.cloud:taskprocessor:<version>
Creating a stream from the Spring Cloud Data Flow shell would look like this:
stream create foo --definition "http --server.port=9000|taskProcessor|taskSink" --deploy