Example #1
0
        private async Task seedData(ConsulUsingApp registry)
        {
            var gateway = new ConsulGateway(new ConsulSettings());
            await gateway.SetProperty("one", "tcp://localhost:2345/queue1");

            await gateway.SetProperty("two", "tcp://localhost:2345/queue2");
        }
Example #2
0
        private static async Task spinUp()
        {
// First, ping to see if consul is running.

            var isRunning = false;

            try
            {
                using (var gateway = new ConsulGateway(new ConsulSettings()))
                {
                    await gateway.SetProperty("ping", "value");

                    isRunning = true;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("No Consul agent found, proceeding to start one up");
            }

            if (isRunning)
            {
                return;
            }


            var basePath = AppContext.BaseDirectory;

            while (!File.Exists(basePath.AppendPath("ConsulServer.cs")))
            {
                basePath = basePath.ParentDirectory();
            }

            string executable = null;

            if (Platform.IsWindows)
            {
                executable = basePath.AppendPath("windows", "consul.exe");
            }
            else if (Platform.IsDarwin)
            {
                executable = basePath.AppendPath("osx", "consul");
            }
            else
            {
                throw new InvalidOperationException(
                          "Sorry, we only support Windows or OSX unless you spin up Consul externally");
            }


            _process = Process.Start(executable, "agent -dev");

            for (int i = 0; i < 5; i++)
            {
                try
                {
                    using (var gateway = new ConsulGateway(new ConsulSettings()))
                    {
                        await gateway.SetProperty("ping", "value");

                        break;
                    }
                }
                catch (Exception)
                {
                    Thread.Sleep(100);
                }
            }
        }