Eventstore:如何正确设置持久订阅客户端?

问题描述

我正在使用 EventStoreDB V20 并且我正在尝试在我的本地开发机器上设置一个持久订阅。在仪表板上,我可以看到列出的持久订阅,但处理程序永远不会被调用

我正在使用这些 nuget: https://www.nuget.org/packages/EventStore.Client.Grpc/ https://www.nuget.org/packages/EventStore.Client.Grpc.PersistentSubscriptions/20.10.0

我在 docker 中运行 EventStore:

docker run --name esdb-node -it -p 2113:2113 -p 1113:1113 -e EVENTSTORE_DEV=true eventstore/eventstore:latest --insecure --run-projections=All --enable-atom-pub-over-http

为了附加事件,我这样做:

await eventStoreClient.AppendToStreamAsync(
    aggregate.Id.ToString(),aggregate.Version == 0 ? StreamRevision.None : StreamRevision.FromInt64(aggregate.Version),events);

创建和订阅持久订阅

var client = new EventStorePersistentSubscriptionsClient(new EventStoreClientSettings {

    CreateHttpMessageHandler = () =>
        new httpclienthandler
        {
            ServerCertificateCustomValidationCallback =
                (message,certificate2,x509Chain,sslPolicyErrors) => true // ignore https
        },ConnectivitySettings = new EventStoreClientConnectivitySettings
        {
            Address = new Uri("http://127.0.0.1:2113?Tls=false&TlsverifyCert=false")
        }});

        await client.CreateAsync("all","TestGroup",new PersistentSubscriptionSettings(startFrom: StreamPosition.End));

        await SubscribeAsync(client);

        Console.ReadLine();
    }

    private static Task<PersistentSubscription> SubscribeAsync(EventStorePersistentSubscriptionsClient client)
    {
        return client.SubscribeAsync("all",(subscription,evt,retryCount,cancelToken) =>
            {
                Console.WriteLine("Received: " + Encoding.UTF8.GetString(evt.Event.Data.Span));

                return Task.CompletedTask;
            });
    }

Console.WriteLine 永远不会被调用。我需要改变什么?

解决方法

一切似乎都设置正确,但我怀疑您是否拥有名称为 all 的流。如果您尝试为 $all 流创建持久订阅,这是不可能的。您只能对 $all 流进行追赶订阅。