use

namespace CORE.WEBERP
{
    public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .UseIdHelper()//.ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); }); }}Copy the code

Zookeeper version 1: Install and configure the JAVA environment (Zookeeper requires JAVA) tutorial: Connect

2: Install and start Zookeeper, tutorial: link

3: Nuget installation package: idHelper. Zookeeper

/// <summary>
///Using IdHelper
/// </summary>
/// <param name="hostBuilder">The builders</param>
/// <returns></returns>
public static IHostBuilder UseIdHelper(this IHostBuilder hostBuilder)
{
    hostBuilder.ConfigureServices((buidler, services) =>
    {
        new IdHelperBootstrapper()
            / / set WorkerId
            .SetWorkderId(buidler.Configuration["WorkerId"].ToLong())
            / / use the Zookeeper
            / / UseZookeeper (127.0.0.1:2181, 200, GlobalSwitch. ProjectName)
            .Boot();
        Console.WriteLine($"WorkerId:{IdHelper.WorkerId},Id:{IdHelper.GetId()}");
    });

    return hostBuilder;
}
Copy the code

Note: other functions please move to the class library to view, I have blog.