簡體   English   中英

Spring Cloud Task Launcher 不響應發送到 Rabbit 的新事件

[英]Spring Cloud Task Launcher doesn't respond to new events sent to 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都是空的。 我沒有定義任何通道或任何東西,因為我看過的示例應用程序也沒有任何特定的設置。

我還需要做些什么來完成這項工作嗎?

設法從大量博客文章和 GitHub 示例中解決了這個問題。

看起來TaskLauncher正在偵聽input而我顯然是通過output發送消息。

一個解決方案是在您的配置中定義兩個通道

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

而在另一邊

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

注意輸出和輸入之間的區別。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM