rnr
December 7, 2021, 11:52pm
1
.NET Client version : eventstore.client.grpc 21.2.0
on .NET 5
Trying to listen to event store streams using a Hosted service.
The app is crashing , if the esdb connection is down.
What’s the retry mechanism available; so that the HostedService is not silently failing.
I assume, the GRPC client doesnot have any retry mechanism and its the client responsibility to provide one?
The client seems to be newing up HttpClient and is there some way to inject retry mechanism like Polly there?
using System;
using System.Net;
using Grpc.Core;
#if !GRPC_CORE
using System.Net.Http;
using System.Threading;
using Grpc.Net.Client;
#else
using System.Collections.Generic;
#endif
#nullable enable
namespace EventStore.Client {
internal static class ChannelFactory {
public static ChannelBase CreateChannel(EventStoreClientSettings settings, EndPoint endPoint) =>
CreateChannel(settings, endPoint.ToUri(!settings.ConnectivitySettings.Insecure));
public static ChannelBase CreateChannel(EventStoreClientSettings settings, Uri? address) {
address ??= settings.ConnectivitySettings.Address;
This file has been truncated. show original
The exception you get is
EventStore.Client.DiscoveryException: Failed to discover candidate in 10 attempts.
there are as you can see retries by default .
var settings = EventStoreClientSettings.Create(connection);
// settings.ConnectivitySettings.MaxDiscoverAttempts
// https://github.com/EventStore/EventStore-Client-Dotnet/blob/a853663cb06fcc70db12f0da20956f4afa63f3c7/src/EventStore.Client/GossipBasedEndpointDiscoverer.cs#L39
you can pass your own HttpMessageHandler : settings.CreateHttpMessageHandler
make sure you use the same kind of settings under the hood as
LoggerFactory = settings.LoggerFactory,
Credentials = settings.ChannelCredentials,
DisposeHttpClient = true
});
HttpMessageHandler CreateHandler() {
if (settings.CreateHttpMessageHandler != null) {
return settings.CreateHttpMessageHandler.Invoke();
}
return new SocketsHttpHandler {
KeepAlivePingDelay = settings.ConnectivitySettings.KeepAliveInterval,
KeepAlivePingTimeout = settings.ConnectivitySettings.KeepAliveTimeout,
EnableMultipleHttp2Connections = true
};
}
#else
return new Channel(address.Host, address.Port, settings.ChannelCredentials ?? ChannelCredentials.Insecure,
GetChannelOptions());
IEnumerable<ChannelOption> GetChannelOptions() {
1 Like
When you subscribe, you can provide a function to handle errors, including disconnects.
Overall, making catch-up subscriptions reliable is not a super-easy task, and it never is for any kind of message delivery system like brokers, etc. I claim you’d always need some sort of middleware to handle things like retries, etc.
You can check how it’s done in Eventuous https://github.com/Eventuous/eventuous/tree/dev/src/EventStore/src/Eventuous.EventStore/Subscriptions
1 Like