public Task InitializeAsync()
 {
     using (var span = initializeSpanBuilder.StartScopedSpan())
     {
         return(cartStore.InitializeAsync());
     }
 }
Esempio n. 2
0
        static object StartServer(string host, int port, ICartStore cartStore)
        {
            // Run the server in a separate thread and make the main thread busy waiting.
            // The busy wait is because when we run in a container, we can't use techniques such as waiting on user input (Console.Readline())
            Task serverTask = Task.Run(async() =>
            {
                try
                {
                    await cartStore.InitializeAsync();

                    var redisCartStore = cartStore as RedisCartStore;

                    if (redisCartStore != null)
                    {
                        tracerProvider = OpenTelemetry.Sdk.CreateTracerProviderBuilder()
                                         .AddRedisInstrumentation(redisCartStore.ConnectionMultiplexer)
                                         .AddSource(CartServiceImpl.ActivitySourceName)
                                         .SetResource(Resources.CreateServiceResource("CartService"))
                                         .AddNewRelicExporter(options =>
                        {
                            options.ApiKey      = Environment.GetEnvironmentVariable("NEW_RELIC_API_KEY");
                            options.EndpointUrl = new Uri(Environment.GetEnvironmentVariable("NEW_RELIC_TRACE_URL"));
                        })
                                         .Build();
                    }


                    Console.WriteLine($"Trying to start a grpc server at  {host}:{port}");
                    Server server = new Server
                    {
                        Services =
                        {
                            // Cart Service Endpoint
                            Hipstershop.CartService.BindService(new CartServiceImpl(cartStore)),

                            // Health Endpoint
                            Grpc.Health.V1.Health.BindService(new HealthImpl(cartStore))
                        },
                        Ports = { new ServerPort(host, port, ServerCredentials.Insecure) }
                    };

                    Console.WriteLine($"Cart server is listening at {host}:{port}");
                    server.Start();

                    Console.WriteLine("Initialization completed");

                    // Keep the server up and running
                    while (true)
                    {
                        Thread.Sleep(TimeSpan.FromMinutes(10));
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
            });

            return(Task.WaitAny(new[] { serverTask }));
        }
Esempio n. 3
0
        static object StartServer(string host, int port, ICartStore cartStore)
        {
            // Run the server in a separate thread and make the main thread busy waiting.
            // The busy wait is because when we run in a container, we can't use techniques such as waiting on user input (Console.Readline())
            Task serverTask = Task.Run(async() =>
            {
                try
                {
                    await cartStore.InitializeAsync();

                    Console.WriteLine($"Trying to start a grpc server at  {host}:{port}");
                    Server server = new Server
                    {
                        Services =
                        {
                            // Cart Service Endpoint
                            Hipstershop.CartService.BindService(new CartServiceImpl(cartStore)),

                            // Health Endpoint
                            Grpc.Health.V1.Health.BindService(new HealthImpl(cartStore))
                        },
                        Ports = { new ServerPort(host, port, ServerCredentials.Insecure) }
                    };

                    Console.WriteLine($"Cart server is listening at {host}:{port}");
                    server.Start();

                    Console.WriteLine("Initialization completed");

                    // zipkinuri = Environment.GetEnvironmentVariable(ZIPKIN_ADDRESS);
                    // if (!string.IsNullOrEmpty(zipkinuri))
                    // {
                    //     Console.WriteLine(zipkinuri);
                    //     Zipkin.Run(zipkinuri);
                    // }

                    // Keep the server up and running
                    while (true)
                    {
                        Thread.Sleep(TimeSpan.FromMinutes(10));
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
            });

            return(Task.WaitAny(new[] { serverTask }));
        }
Esempio n. 4
0
        static object StartServer(string host, int port, ICartStore cartStore)
        {
            // Run the server in a separate thread and make the main thread busy waiting.
            // The busy wait is because when we run in a container, we can't use techniques such as waiting on user input (Console.Readline())
            Task serverTask = Task.Run(async() =>
            {
                try
                {
                    await cartStore.InitializeAsync();

                    // setup grpc interceptor
                    var tracingInterceptor = new ServerTracingInterceptor(GlobalTracer.Instance);

                    Console.WriteLine($"Trying to start a grpc server at  {host}:{port}");
                    Server server = new Server
                    {
                        Services =
                        {
                            // Cart Service Endpoint
                            Hipstershop.CartService.BindService(new CartServiceImpl(cartStore)).Intercept(tracingInterceptor),

                            // Health Endpoint
                            Grpc.Health.V1.Health.BindService(new HealthImpl(cartStore)).Intercept(tracingInterceptor),
                        },
                        Ports = { new ServerPort(host, port, ServerCredentials.Insecure) }
                    };

                    Console.WriteLine($"Cart server is listening at {host}:{port}");
                    server.Start();

                    Console.WriteLine("Initialization completed");

                    // Keep the server up and running
                    while (true)
                    {
                        Thread.Sleep(TimeSpan.FromMinutes(10));
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
            });

            return(Task.WaitAny(new[] { serverTask }));
        }
 public async void Start()
 {
     Console.WriteLine("Starting cart service...");
     await _cartStore.InitializeAsync();
 }