首页 > 解决方案 > 重新连接到 EventStore 中的持久连接后不重复确认的事件

问题描述

我正在使用 Eventstore20.6.1.0 而这个客户端https://github.com/EventStore/EventStore-Client-NodeJS 当我将事件发布到 eventstore 并像这样在订阅者中确认它们时

      const onEvent = 
        (event: ResolvedEvent, report: PersistentReport) => {
          if (event.event) {
            report.ack(event.event.id);
          }
        }

如果我从事件存储断开并重新连接,我会再次收到所有确认的事件

为什么我收到确认的事件,但不仅是新的?

标签: node.jseventstoredb

解决方案


创建持久连接时,您必须设置最大检查点计数。就我而言,我发送的事件少于maxCheckpointCount断开连接之前未确认的事件。这就是为什么重新连接后我再次收到它们。

    await createPersistentSubscription(streamName, groupName)
      .fromStart()
      .enableLinkResolution()
      .consumerStrategy(ROUND_ROBIN)
      .maxCheckpointCount(1)
      .minCheckpointCount(1)
      .execute(connection)

推荐阅读