简体   繁体   中英

Spring Cloud Task Launcher doesn't respond to new events sent to Rabbit

I'm trying to setup a very basic Spring Cloud Task example but I'm having a problem with the Task Launcher not receiving the events (I think).

Using the most basic sample to send events:

@RestController
@EnableBinding(Source.class)
@SpringBootApplication
@RequiredArgsConstructor
public class Application {

  private final Source source;

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

  @RequestMapping(path = "/task", method = RequestMethod.GET)
  public void sendRequest() {

    final TaskLaunchRequest request =
        new TaskLaunchRequest(
            "maven://org.springframework.cloud.task.app:timestamp-task:jar:1.0.1.RELEASE",
            null,
            null,
            null,
            null);

    final GenericMessage<TaskLaunchRequest> genericMessage = new GenericMessage<>(request);

    this.source.output().send(genericMessage);
  }
}

I can confirm this does send the TaskLunchRequest to Rabbit as expected.

However using an equally simple example on the other end yields no results

@EnableTaskLauncher
@SpringBootApplication
public class Application {

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

And the dependencies:

implementation 'org.springframework.cloud:spring-cloud-starter-task'
implementation 'org.springframework.cloud:spring-cloud-starter-stream-rabbit'
implementation 'org.springframework.cloud:spring-cloud-deployer-local:1.3.7.RELEASE'

I was expecting the @EnableTaskLauncher to go ahead and start a new jar based on the maven url passed in.

Note the application.properties for both projects are empty. I've not defined any channels or anything as none of the sample applications I've looked at have anything specific set either.

Is there anything further I need to do to make this work?

Managed to work this out from a large number of blog posts and GitHub samples.

Looks like out the box the TaskLauncher is listening on input and I was obviously sending messages out via output .

A solution is to define both channels in your configuration as such

spring:
  cloud:
    stream:
      bindings:
        output:
          destination: task-launcher

And on the other side

spring:
  cloud:
    stream:
      bindings:
        input:
          destination: task-launcher

Note the difference between output and input.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM