0

I have created a spring cloud task that will perform some specific task based on the requirement. I wanted to call this task from another spring boot application. Please let me know is there any way of calling the below task from an external application.

@SpringBootApplication
@EnableTask
public class FileGenerationTaskApplication {
    @Autowired
    private DataSource dataSource;

    public class FileGeneratorTaskConfigurer extends DefaultTaskConfigurer {
        public FileGeneratorTaskConfigurer(DataSource dataSource){
            super(dataSource);
        }
    }

    @Bean()
    public FileGeneratorTaskConfigurer getTaskConfigurer() {
        return new FileGeneratorTaskConfigurer(dataSource);
    }

    public static void main(String[] args) {
        SpringApplication.run(FileGenerationTaskApplication.class, args);
    }


    @Component
    public static class FileGeneratorTaskRunner implements  ApplicationRunner {

        @Autowired
        private FulfillmentFileGenerationService service;


        public void run(ApplicationArguments args) throws Exception {
            System.out.println("FileGeneratorTaskRunner from Spring Cloud Task!");
            service.fulFillmentFileGenerationTask();
        }
    }

}

Can we create a REST api to call the spring cloud task?

Ravikiran
  • 45
  • 1
  • 7
  • You can create a stream with task-launcher sink to launch a Task in PCF, and then make a custom trigger to invoke the stream. https://docs.spring.io/spring-cloud-dataflow-server-mesos/docs/1.0.0.RELEASE/reference/html/spring-cloud-dataflow-launch-tasks-from-stream.html – Gayatri Mar 20 '19 at 17:16

1 Answers1

0

It would be nice to have the Task registered on Spring Cloud Dataflow. After you have your Task registered, you can make REST calls to trigger the Task. Check this example out.

You can also use Spring Cloud Dataflow Rest Client

DataFlowOperations dataFlowOperations = new DataFlowTemplate(URI.create(springDataFlowUri));
TaskOperations operations = dataFlowOperations.taskOperations();

Then you can start launching the Tasks previously got using the API Rest.

In case you do not want to use Spring Cloud DataFlow, remember when you create a Task, this is a Spring Boot Application by itself, so you can expose end points to trigger the Task.

dbustosp
  • 4,208
  • 25
  • 46