【问题标题】:Eventstore: How do I setup an persistent subscriptions client correctly?Eventstore:如何正确设置持久订阅客户端?
【发布时间】:2021-01-15 19:50:02
【问题描述】:

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

我正在使用这些 nugets: 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", "TestGroup",
            (subscription, evt, retryCount, cancelToken) =>
            {
                Console.WriteLine("Received: " + Encoding.UTF8.GetString(evt.Event.Data.Span));

                return Task.CompletedTask;
            });
    }

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

【问题讨论】:

  • 你有名为all的流吗?
  • 不,我真的想要$all

标签: c# event-sourcing eventstoredb


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-03
    • 2015-04-04
    • 1970-01-01
    • 2011-03-18
    • 2015-08-24
    • 2012-10-19
    • 2015-08-11
    相关资源
    最近更新 更多