Example #1
0
        private void Start(IConsulClient consulClient, ILoggerFactory logerFactory)
        {
            if (ServiceInfo != null)
            {
                var configFilePath = Path.Combine(ServiceInfo.Location, "config.json");
                ConfigurationManager.Setup(configFilePath, logerFactory);
                ServiceResourceManager.Load();
                CacheProviderFactory.Init();

                var lifetime = GetMicroserviceLifetime();
                lifetime?.Start();

                ServiceInfo.StartedAt = DateTime.Now;
            }

            consulClient.RegisterMicroServiceAsync(ServiceInfo);
        }
Example #2
0
        private static async Task RegisterService(HttpContext context)
        {
            var serviceEntrypoint = Environment.GetEnvironmentVariable("SERVICE_ENTRYPOINT");

            if (string.IsNullOrEmpty(serviceEntrypoint))
            {
                Environment.SetEnvironmentVariable("SERVICE_ENTRYPOINT", $"{context.Request.Scheme}://{context.Request.Host}");
            }

            var assembly = Assembly.GetEntryAssembly();
            await consulClient.RegisterMicroServiceAsync(new ServiceInfo
            {
                Id      = assembly.ManifestModule.ModuleVersionId.ToString(),
                Name    = Path.GetFileNameWithoutExtension(assembly.ManifestModule.Name),
                Version = assembly.ImageRuntimeVersion
            }, false);

            await WriteResultAsync(context, new { success = true });
        }