rogeralsing/Microphone

Last release and custom Consul host+port

Closed this issue · 3 comments

Just downloaded the latest version from Nuget (testing for WebApi) and couldn't connect to my Consul server which is not on the same server using Microphone lib.
The config includes the following:

  <appSettings>
    <add key="Consul:Host" value="172.18.1.164" />
    <add key="Consul:Port" value="8300" />
  </appSettings>

The error message clearly says thats it can't connect to 127.0.0.1:8500 which is not picking up the config file.

But I have checked the code for the last release and Consul provider only accepts useEbayFabio parameter. The current code in the repository has different parameters (string consulHost = "localhost", int consulPort = 8500)

Can someone explains!

ConsulProvider have default value:
_consulHost -> localhost
_consulPort -> 8500

Constructor looks like this :

        public ConsulProvider(string consulHost = "localhost", int consulPort = 8500, bool useEbayFabio = false)
        {
            _consulHost = consulHost;
            _consulPort = consulPort;
            _useEbayFabio = useEbayFabio;
        }

But probably in NuGet version its not implement yet.

The latest release contains a ConsulOptions class:

    public class ConsulOptions
    {
        public string Host { get; set; } = "localhost";
        public int Port { get; set; } = 8500;
        public ConsulNameResolution NameResolution { get; set; } = ConsulNameResolution.HttpApi;
        public int Heartbeat { get; set; } = 1;
        public string HealthCheckPath { get; set; } = "/status";
    }

You can use this to set where to look for consul.

private static void RegisterWithConsul(Uri uri)
{
    var options = new OptionsWrapper<ConsulOptions>(new ConsulOptions
    {
        Host = "...",
        Port = 123,
    });
    var logging = new LoggerFactory();
    var consulProvider = new ConsulProvider(logging, options);
    var serviceName = Assembly.GetEntryAssembly().GetName().Name;
    Cluster.RegisterService(uri, consulProvider, serviceName, "v1", logging.CreateLogger("Microphone.Consul"));
}

Much of this has changed to align with .NET Core and the ecosystem of libs there.

Using the Microphone.AspNet provider for AspNet Core, allows you to configure it like this:

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
            services
                .AddMicrophone<ConsulProvider>()

                //set up your options here 
                services.Configure<ConsulOptions>(o => {
                    o.Host = Configuration["ConsulHost"];
                });
        }