Spring Cloud Task provides the ability to emit events via Spring Cloud Stream channel
when the task is executed via a Spring Cloud Stream channel. A task listener is used to
publish the TaskExecution on a message channel named task-events. This feature is
autowired into any task that has spring-cloud-stream on its classpath in addition to the
spring-cloud-stream and a task defined.
![]() | Note |
|---|---|
To disable the event emitting listener, set the property
|
With the appropriate classpath defined, a simple task like this:
@SpringBootApplication
@EnableTask
public class TaskEventsApplication {
public static void main(String[] args) {
SpringApplication.run(TaskEventsApplication.class, args);
}
@Configuration
public static class TaskConfiguration {
@Bean
public CommandLineRunner commandLineRunner() {
return new CommandLineRunner() {
@Override
public void run(String... args) throws Exception {
System.out.println("The CommandLineRunner was executed");
}
};
}
}
}will emit the TaskExecution as an event on the task-events channel (both at the start
and end of the task).
![]() | Note |
|---|---|
Configuration of the content type may be required via
|
![]() | Note |
|---|---|
A binder implementation is also required to be on the classpath. |
![]() | Note |
|---|---|
A sample task event application can be found in the samples module of the Spring Cloud Task Project here. |