예제 #1
0
    private static RegistryClient BuildRegistryClient(string prefixName)
    {
        var configuration = new ConsulRegistryHostConfiguration()
        {
            HostName = "localhost"
        };

        var consul = new ConsulRegistryHost(configuration);

        var registryClient = new RegistryClient(prefixName, new RoundRobinAddressRouter());

        registryClient.AddRegistryHost(consul);

        return(registryClient);
    }
예제 #2
0
        private static async Task MainAsync()
        {
            var log = LogManager.GetCurrentClassLogger();

            log.Debug($"Starting {typeof(Program).Namespace}");

            var consulRegistryHost = new ConsulRegistryHost();
            var serviceRegistry    = new ServiceRegistry(consulRegistryHost);

            Console.WriteLine("Press ESC to stop");
            do
            {
                while (!Console.KeyAvailable)
                {
                    try
                    {
                        var instances = await serviceRegistry.FindServiceInstancesAsync();

                        var groupedByName = instances
                                            .GroupBy(x => x.Name, x => x)
                                            .ToList();

                        if (!groupedByName.Any())
                        {
                            Console.WriteLine("No service instances found");
                            Console.WriteLine();
                            continue;
                        }

                        foreach (var group in groupedByName)
                        {
                            string name  = group.Key;
                            int    count = group.Count();
                            Console.WriteLine($"    Name: {name}, instances found: {count}");
                        }
                        Console.WriteLine();

                        await Task.Delay(TimeSpan.FromSeconds(1));
                    }
                    catch (AggregateException ex)
                    {
                        Console.WriteLine($"Could not connect to service registry: {ex.Message}");
                    }
                }
            } while (Console.ReadKey(true).Key != ConsoleKey.Escape);
        }
예제 #3
0
        private async Task <IRegistryHost> GetConsulRegistryHostAsync()
        {
            var configuration = new ConsulRegistryHostConfiguration()
            {
                HostName = "localhost"
            };

            var registryHost = new ConsulRegistryHost(configuration);
            await registryHost.KeyValuePutAsync("key1", "value1");

            await registryHost.KeyValuePutAsync("key2", "value2");

            await registryHost.KeyValuePutAsync("folder/key3", "value3");

            await registryHost.KeyValuePutAsync("folder/key4", "value4");

            return(registryHost);
        }
예제 #4
0
        private static async Task MainAsync()
        {
            const int PORT = 8899;

            var uri = new Uri($"http://localhost:{PORT}/");

            using (var nancyHost = new NancyHost(uri))
            {
                nancyHost.Start();

                var consulRegistryHost = new ConsulRegistryHost();
                var serviceRegistry    = new ServiceRegistry(consulRegistryHost);

                await serviceRegistry.RegisterServiceAsync("price", "1.3.2", uri);

                Console.WriteLine($"Now listening on {uri}/price. Press enter to stop");
                Console.ReadKey();
            }
        }
        public void Start()
        {
            var baseUrl   = new Uri("http://localhost:7777");
            var healthUrl = new Uri("http://localhost:7777/api/health/ping");

            WireAppDomainHandlers();
            InitializeMapper();
            SetupQueues();
            ListenOnQueues();

            var registryHost = new ConsulRegistryHost();

            _serviceRegistry = new ServiceRegistry(registryHost);

            Task.Run(async() =>
            {
                _registryInformation = await _serviceRegistry.AddTenantAsync(new CustomWebApiRegistryTenant(baseUrl), "orders", "0.0.2", healthUrl);

                _server = WebApp.Start <Startup>(baseUrl.ToString());
                Console.WriteLine("Orders Service running - listening at {0} ...", baseUrl);
            }).GetAwaiter().GetResult();
        }