Kit is a .NET Core toolkit for microservices that is heavily inspired by go-kit. The goal of Kit is to provide a common set of abstractions for platform components of a microservice framework.
The Service Discovery packages provide a set of abstractions for pluggable service discovery into the toolkit.
This project is still in development and subject to change. Please create an issue with any feedback.
- Abstractions - Common abstractions for service discovery
- Cache - A caching discovery provider that can be chained with other discovery providers
- LoadBalancer - Add load balancing algorithms to service discovery providers
- Multi - Add multiple providers and returns the first provider with endpoints
- Throttle - A throttling discovery provider that can be chained with other discovery providers
A full working example can be found in the samples directory.
All requests for endpoints will request directly against the Consul api.
var consulClient = new ConsulClient();
var subscriber = new ConsulServiceSubscriber(client, "FooService", new List<string>(), true, false);
var endpoints = subscriber.Endpoints();
Since the Consul api supports long polling, we can cache the results and provide a background process to poll for changes.
var consulClient = new ConsulClient();
var subscriber = new ConsulServiceSubscriber(client, "FooService", new List<string>(), true, true);
var cache = new MemoryCache(new MemoryCacheOptions());
var loggerFactory = new LoggerFactory();
var pollingSubscriber = new CacheServiceSubscriber(loggerFactory, subscriber, cache);
var endpoints = pollingSubscriber.Endpoints();
The caching implementation in combination with the throttle implementation can be used for any service discovery platform that does not support long polling. The throttler is useful also to prevent overloading your service discovery platform with requests.
var consulClient = new ConsulClient();
var subscriber = new ConsulServiceSubscriber(client, "FooService", new List<string>(), true, true);
// Limit to 5 requests per 10 seconds
var throttleSubscriber = new ThrottleServiceSubscriber(subscriber, 5, TimeSpan.FromSeconds(10))
var loggerFactory = new LoggerFactory();
var cache = new MemoryCache(new MemoryCacheOptions());
var pollingSubscriber = new CacheServiceSubscriber(throttleSubscriber, loggerFactory, cache);
var endpoints = pollingSubscriber.Endpoints();