Example #1
0
        /// <summary>
        /// Consul注册
        /// </summary>
        /// <param name="servicgrpcOptionses">配置</param>
        /// <param name="whenException">==null => throw</param>
        public static void WithConsul(
            GrpcOptions grpcOptions          = null,
            Action <Exception> whenException = null)
        {
            try
            {
                var serviceElement = ResolveServiceConfiguration(grpcOptions);

                #region 注册服务
                var address = ResolveConsulConfiguration(serviceElement);
                if (string.IsNullOrWhiteSpace(address))
                {
                    return;
                }
                serverRegister = new ConsulRegister(address, grpcOptions.GenServiceId);
                serverRegister.Register(serviceElement, entry => discoveryEntry = entry);
                #endregion
            }
            catch (Exception ex)
            {
                RemoveConsul();
                InvokeException(ex, whenException);
            }
        }
Example #2
0
 public Entry(ConsulRegister serverRegister, string serviceId)
 {
     ServiceId = serviceId;
     _serverRegister = serverRegister;
 }