java - 如何在 Spring Integration 中使用临时 Channel?
问题描述
我是 Spring Integration 的新手,我正在尝试从临时频道获取消息。
阅读文档,spring 有一个临时通道使用。我猜它的名字NullChannel
我需要gateway
从临时通道返回值。
http controller -> gateway -> direct channel -> activator 1 -> queue channel -> activator 2
所以我activator 2
会将新值放入临时通道,因此gateway
将从临时通道中检索值
@MessageEndpoint
public class Activator2 {
@Autowired
private NullChannel nullChannel;
@ServiceActivator(inputChannel = "asyncChannel")
public void plus(Integer message){
try {
message++;
Thread.sleep(2000);
nullChannel.send(MessageBuilder.withPayload(message).build());
log.info("Activator 2: " +message );
} catch (InterruptedException e) {
log.error("I don't want to sleep");
}
}
}
它不工作。我不确定一切是否连接良好
解决方案
NullChannel
就像/dev/null
在 Unix 中一样;它只是丢弃了该值。
@ServiceActivator(inputChannel = "asyncChannel")
public Integer plus(Integer message){
return message;
}
会自动做你想做的。
如果没有outputChannel
,框架将结果发送到replyChannel
标头。
推荐阅读
- reactjs - 用axios拉取后解释Geojson
- python - 如果日期间隔大于 N 秒,则使用最后一个值填充列表
- algorithm - 用整数项计算矩阵幂
- node.js - 基于允许和不能导入哪些模块的 TypeScript lint 文件和文件夹
- c# - 如何从同一 Azure AD 中的另一个 Web 应用程序访问 Web api?
- python - 使用切片和列表索引数据框
- c - 在 Ubuntu 18.04.1 上与 gcc-6 的覆盖兼容性?
- r - r 使用随机换行符格式化 csv 并导出
- node.js - 不从身份验证代码返回刷新令牌
- jquery - 通过 jQuery 重新加载脚本