How to do it...

Let's implement a simple event using Spring Cloud Task:

  1. Create a Spring Boot 2.0 project, ch11-batch-task, that contains the core starter POM such as webflux, actuator, and the Tomcat server for Spring Boot 2.0, with the addition of the needed Spring Cloud dependent management configuration, which is Spring Cloud Finchley.
  2. Add the following Spring Cloud Task dependency into the pom.xml file:
<dependency> 
  <groupId>org.springframework.cloud</groupId> 
  <artifactId>spring-cloud-task-core</artifactId> 
</dependency> 
  1. Create a core package org.packt.process.core and create a bootstrap class that enables Spring Cloud Task through the @EnableTask annotation:
@SpringBootApplication 
@EnableTask 
public class TaskBootApplication extends   
            SpringBootServletInitializer  { 
      // refer to sources 
} 
  1. Inside its srcmain esources folder, create application.properties similar to the previous recipes. Just create a blank database named springcloudtask that is mapped solely to this application.
  2. Copy the logback.xml file from the previous chapters and place this file in srcmain esources with some updates.
  1. Inside a new package, org.packt.process.core.config, create a configuration for the task to be executed by implementing the Spring Cloud Task core interface, org.springframework.boot.CommandLineRunner. This class simply logs a dummy message:
@Configuration 
public class MonitorTask implements CommandLineRunner { 
 
   private final Logger log =  
  LoggerFactory.getLogger(MonitorTask.class); 
 
   @Override 
   public void run(String... args) throws Exception { 
      log.info("running task"); 
   } 
} 
  1. Save all files. Deploy the project. Check the log file and open a MySQL Workbench to check the springcloudtask schema:
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.249.210