Creating a base interface
As we mentioned previously, an interface is a contract, plain and simple. The interface for our base microservice is going to be relatively simple. The following is what our interface looks like:
public interface IBaseMicroService { void Start(HostControl hc); void Stop(); void Pause(); void Continue(); void Shutdown(); void Resume(); void TryRequest(Action action, int maxFailures, int startTimeoutMS = 100, int resetTimeout = 10000, Action<Exception> OnError = null); Task TryRequestAsync([NotNull] Func<Task> action, int maxFailures, int startTimeoutMS = 100, int resetTimeout = 10000, [CanBeNull] Action<Exception> OnError = null);void PublishMessage(object message, string connStr = "host=localhost", string topic = ""); Task PublishMessageAsync(object message, string connStr = "host=localhost", string topic = ""); }
You will notice that our interface, aside from the TryRequest
functions, really only controls the motion of our microservice. This means...