【问题标题】:Spring Integration Message Channel Skipping messgesSpring Integration Message Channel 跳过消息
【发布时间】:2016-01-13 21:12:31
【问题描述】:

我有以下使用 Redis 作为消息存储的配置。我没有这个模块的java代码,只有这个配置文件。该配置具有以下功能: 当该模块接收到来自输入通道的消息时,它将检查 Redis 存储,如果消息不存在(表达式将被评估为 TRUE),则消息将被发送到输出通道将被放入 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, '')"/>

【问题讨论】:

    标签: spring-integration


    【解决方案1】:

    从高处看,您似乎需要Idempotent Receiver,它执行完全相同的逻辑,但以原子方式。见MetadataStoreSelector源码:

        return this.metadataStore.putIfAbsent(key, value) == null;
    

    因此,您可以使用RedisMetadataStore 配置&lt;idempotent-receiver&gt;,并将payload 用作key-expression 选项。

    您的帖子不清楚您是如何获取日志的,因为&lt;int:outbound-channel-adapter&gt;单向 组件。

    也许你在春天 XD 那里?您将output 频道用于您自己的目的,但这确实应该是您模块的输出。

    这可能是您只看到 even 消息的原因,因为 odd 被发送到您的 &lt;int:outbound-channel-adapter&gt; 并且 DirectChannel 使用 round-robin 平衡策略默认。

    使用&lt;idempotent-receiver&gt;,您的RedisMdule 中应该只有&lt;bridge input-channel="input" output-channel="output"/&gt;

    【讨论】:

    • 非常感谢您的回复。这很有帮助
    猜你喜欢
    • 2017-04-28
    • 1970-01-01
    • 2017-07-03
    • 2015-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-29
    • 1970-01-01
    相关资源
    最近更新 更多