首页 > 解决方案 > Spring Cloud Task Launcher 不响应发送给 Rabbit 的新事件

问题描述

我正在尝试设置一个非常基本的 Spring Cloud Task 示例,但我遇到了 Task Launcher 没有接收到事件的问题(我认为)。

使用最基本的示例发送事件:

@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);
  }
}

我可以确认这确实TaskLunchRequest按预期发送给 Rabbit。

但是,在另一端使用同样简单的示例不会产生任何结果

@EnableTaskLauncher
@SpringBootApplication
public class Application {

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

和依赖项:

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'

我期待@EnableTaskLauncher继续并根据传入的 maven url 启动一个新 jar。

请注意application.properties,两个项目的 都是空的。我没有定义任何通道或任何东西,因为我看过的示例应用程序也没有任何特定设置。

我还需要做些什么来完成这项工作吗?

标签: javaspring-cloudspring-cloud-stream

解决方案


设法从大量博客文章和 GitHub 示例中解决了这个问题。

看起来像是开箱即用TaskLauncherinput我显然是通过output.

一个解决方案是在您的配置中定义这两个通道

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

而在另一边

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

注意输出和输入之间的区别。


推荐阅读