eventstoredb - 事件存储死机时如何正确处理追赶订阅重新连接

标签 eventstoredb

当更新订阅重新连接时,事件存储似乎不一致。基于 google 组中的线程和实验,如果 SubscriptionDropReason 为 ConnectionClosed,似乎 catch 订阅将自动重新连接。

但是,如果您随后尝试停止这些连接并指定超时,那么它们似乎永远不会真正停止并且总是超时。

我使用了 this post 中的代码但我认为这是误导,因为在我的实验中,在这种情况下收到多个事件的原因是因为当事件存储重新联机时,事件存储会自动重新订阅 CatchupSubscriptions,所以只要你在原因是 ConnectionClosed 时不重新订阅,那么你不会多次收到事件。如果我修改此代码以将超时添加到 .Stop(timeout) 方法,那么它就会挂起并抛出。

当我在自动重新连接后收到对实时处理启动事件的调用时,EventStoreCatchUpSubscription 对象具有指示 _isDropped=1 的内部状态,这对我来说也很奇怪,因为它没有被丢弃,它实际上是在处理事件。

所以我的问题是我应该如何处理 eventstore 已经自动重新连接并且我想断开连接并等待超时的情况?

最佳答案

“subscriptionDropped”事件是处理连接问题的好地方。 事件存储项目中仍有 Unresolved 问题。

https://github.com/EventStore/EventStore/issues/929

https://github.com/EventStore/EventStore/issues/1127

eventStoreConnection.SubscribeToAllFrom(lastCheckpoint, catchUpSubscriptionSettings,
                eventAppeared(projection),
                liveProcessingStarted(projection),subscriptionDropped(projection),userCredentials );   



 private Action<EventStoreCatchUpSubscription, SubscriptionDropReason, Exception> subscriptionDropped(Projection projection)
            => async (eventStoreCatchUpSubscription, subscriptionDropReason, exception) =>
            {

                eventStoreCatchUpSubscription.Stop();

                switch (subscriptionDropReason)
                {
                    case SubscriptionDropReason.UserInitiated:
                        Console.WriteLine($"{projection} projection stopped by user.");
                        break;
                    case SubscriptionDropReason.SubscribingError:
                    case SubscriptionDropReason.ServerError:
                    case SubscriptionDropReason.ConnectionClosed:
                    case SubscriptionDropReason.CatchUpError:
                    case SubscriptionDropReason.ProcessingQueueOverflow:
                    case SubscriptionDropReason.EventHandlerException:
                        Console.WriteLine($"{projection} projection stopped because of a transient error ({subscriptionDropReason}). ");
                        Console.WriteLine($"Exception Detail:  {exception}");    
                        Console.WriteLine("Attempting to restart...");
                        // Re-build your subscription in here
                        Task.Run(() => StartProjection(projection));
                        break;
                    default:
                        Console.WriteLine("Your subscription gg");
                        Console.WriteLine($"Exception Detail:  {exception}");    
                        break;
                }
            };

关于eventstoredb - 事件存储死机时如何正确处理追赶订阅重新连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52496556/

相关文章:

event-sourcing - 聚合间通信

java - 如何以编程方式(java 或 http)在 GetEventStore 中创建投影

eventstoredb - 我可以在 EventStore 管理站点的哪个位置查看我的保存事件?

cqrs - 应如何托管事件溯源事件处理程序来构建读取模型?

eventstoredb - 如何从类别进行投影?

cqrs - 如何确保应用事件来读取模型?

eventstoredb - EventStore 持久订阅事件数据

eventstoredb - 如何通过它的 ID 在 EventStore 中查找事件?

Docker Compose/无效,因为

gitlab - 无法在我的免费帐户中连接到 Gitlab CI 中的容器