java - 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
,两个项目的 都是空的。我没有定义任何通道或任何东西,因为我看过的示例应用程序也没有任何特定设置。
我还需要做些什么来完成这项工作吗?
解决方案
设法从大量博客文章和 GitHub 示例中解决了这个问题。
看起来像是开箱即用TaskLauncher
,input
我显然是通过output
.
一个解决方案是在您的配置中定义这两个通道
spring:
cloud:
stream:
bindings:
output:
destination: task-launcher
而在另一边
spring:
cloud:
stream:
bindings:
input:
destination: task-launcher
注意输出和输入之间的区别。
推荐阅读
- c++ - 我的程序太慢了
- docker - 为 gcloud 构建提交指定 Dockerfile
- amazon-web-services - 限制对 Redshift 表的访问,仅授予对视图的访问权限
- reactjs - 在 Gatsby 中使用 react-web-vector-icons 时出现“无法从...解码字体”错误
- python - Teradata Python 包:如何在 Teradata 中访问非默认数据库中的表
- text - 将数据帧转换为语料库时如何避免单词标记?
- r - 使用 updateSelectInput 时防止双重加载输出
- sql - PostgreSQL:从函数内创建外部服务器和外部表
- javascript - 我的算法正确吗?(范围内的值与否)
- ios - Siri 建议的网站图标