Eventstore:如何正确设置持久订阅客户端?
Eventstore: How do I setup an persistent subscriptions client correctly?
我正在使用 EventStoreDB V20,我正在尝试在我的本地开发机器上设置持久订阅。在仪表板上,我可以看到列出的持久订阅,但处理程序从未被调用。
我正在使用这些 nugets:
https://www.nuget.org/packages/EventStore.Client.Grpc/
https://www.nuget.org/packages/EventStore.Client.Grpc.PersistentSubscriptions/20.10.0
我 运行 事件存储在 docker:
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
流创建持久订阅,这是不可能的。您只能在 $all
流上进行追赶订阅。
我正在使用 EventStoreDB V20,我正在尝试在我的本地开发机器上设置持久订阅。在仪表板上,我可以看到列出的持久订阅,但处理程序从未被调用。
我正在使用这些 nugets: https://www.nuget.org/packages/EventStore.Client.Grpc/ https://www.nuget.org/packages/EventStore.Client.Grpc.PersistentSubscriptions/20.10.0
我 运行 事件存储在 docker:
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
流创建持久订阅,这是不可能的。您只能在 $all
流上进行追赶订阅。