我正在尝试设置一个非常基本的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网址启动一个新的jar。
注意,两个项目的application.properties
为空。我还没有定义任何通道或任何东西,因为我看过的所有示例应用程序都没有任何特定的设置。
要完成这项工作,我还需要做更多的事情吗?
设法从大量博客文章和GitHub示例中解决了这一问题。
[看上去像TaskLauncher
框在监听input
,我显然是通过output
发送消息的。
解决方案是在您的配置中同时定义两个通道
spring:
cloud:
stream:
bindings:
output:
destination: task-launcher
和另一边
spring:
cloud:
stream:
bindings:
input:
destination: task-launcher
注意输出和输入之间的差异。