.netcore 操作 Consul

Git:https://github.com/G-Research/consuldotnet

Nuget:Consul

使用方法:

using Consul;
using System;
using System.Text;
using System.Threading.Tasks;

namespace ConsulConsoleApp
{
    class Program
    {
        static async Task Main(string[] args)
        {
            using (var client = new ConsulClient(config =>
            {
                config.Address = new Uri("http://127.0.0.1:8501");
            }))
            {
                var putPair = new KVPair("hello")
                {
                    Value = Encoding.UTF8.GetBytes("Hello Consul")
                };

                var putAttempt = await client.KV.Put(putPair);

                if (putAttempt.Response)
                {
                    var getPair = await client.KV.Get("hello");
                    var value = Encoding.UTF8.GetString(getPair.Response.Value, 0,
                         getPair.Response.Value.Length);
                }
            }
            Console.ReadKey();
        }
    }
}

 

你可能感兴趣的:(Consul)