spring-integration之Spring Integration 消息 channel 跳过消息
我有以下使用 Redis 作为消息存储的配置。我没有这个模块的java代码,只有这个配置文件。此配置具有以下功能:当此模块从输入 channel 接收到消息时,它将检查 Redis 存储,如果消息不存在(表达式将被评估为 TRUE),则将消息发送到输出 channel 将被放入Redis;如果消息已经存在(表达式被评估为 False),消息将被丢弃。
假设这个模块叫做 RedisModule,所以我有一个流:
RedisMdule | log
问题是:当我向这个模块发送消息时,在日志文件中,它显示消息 #2、#4、#6 等,第一条消息丢失,奇数消息也是如此。我在这个配置文件中遗漏了什么吗?非常感谢。
<int:channel id="input"/>
<int:channel id="output"/>
<int:filter input-channel="input"
output-channel="output"
discard-channel="nullChannel"
expression="@metadataStore.get(payload) == null"/>
<int:outbound-channel-adapter channel="output"
expression="@metadataStore.put(payload, '')"/>
请您参考如下方法:
从高处看你需要 Idempotent Receiver
,它执行完全相似的逻辑,但以 atomic 方式。参见 MetadataStoreSelector
源代码:
return this.metadataStore.putIfAbsent(key, value) == null;
因此,您可以配置一个 <idempotent-receiver>
用你的RedisMetadataStore
并使用 payload
作为 key-expression
选项。
你的帖子并不清楚你是如何获取日志的,因为<int:outbound-channel-adapter>
是单向组件。
也许你在 Spring XD?你在哪里使用 output
用于您自己目的的 channel ,但这实际上应该是您模块的输出。
这可能就是您只看到偶数 消息的原因,因为奇数 发送到您的<int:outbound-channel-adapter>
和 DirectChannel
使用 round-robin
默认平衡策略。
随着 <idempotent-receiver>
你应该只有 <bridge input-channel="input" output-channel="output"/>
在你的RedisMdule
.
1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。