Пример #1
0
        static void Main(string[] args)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json")
                          .AddEnvironmentVariables();

            Configuration = builder.Build();

            var loggerFactory = new LoggerFactory()
                                .AddConsole()
                                .AddDebug();

            ILogger logger = loggerFactory.CreateLogger <Program>();

            var port = int.Parse(Configuration["service:port"]);

            var brokerList = Configuration["kafkaclient:brokerlist"];
            var config     = new Dictionary <string, object>
            {
                { "group.id", "order-command" },
                { "enable.auto.commit", "false" },
                { "bootstrap.servers", brokerList }
            };

            IEventEmitter kafkaEmitter = new KafkaEventEmitter(config, loggerFactory.CreateLogger <KafkaEventEmitter>());
            // TODO: this channel needs to use a service-discovery hostname
            var orderChannel = new Channel($"{Configuration["orderclient:hostname"]}:{Configuration["orderclient:port"]}",
                                           ChannelCredentials.Insecure);
            var inventoryChannel = new Channel($"{Configuration["inventoryclient:hostname"]}:{Configuration["inventoryclient:port"]}",
                                               ChannelCredentials.Insecure);

            logger.LogInformation($"Configured gRPC channel for Order Management client: {orderChannel.ResolvedTarget}");
            logger.LogInformation($"Configured gRPC channel for Inventory Management client: {inventoryChannel.ResolvedTarget}");

            var orderClient     = new OrderManagement.OrderManagementClient(orderChannel);
            var inventoryClient = new InventoryManagement.InventoryManagementClient(inventoryChannel);

            var refImpl = new ReflectionServiceImpl(
                ServerReflection.Descriptor, OrderCommand.Descriptor);

            var rpcLogger = loggerFactory.CreateLogger <OrderCommandImpl>();
            var server    = new Server
            {
                Services = { OrderCommand.BindService(new OrderCommandImpl(rpcLogger, kafkaEmitter, orderClient, inventoryClient)),
                             ServerReflection.BindService(refImpl) },
                Ports = { new ServerPort("localhost", port, ServerCredentials.Insecure) }
            };

            server.Start();

            logger.LogInformation("Orders Command gRPC Service Listening on Port " + port);

            // Keep the process alive without consuming CPU cycles
            mre.WaitOne();
        }
Пример #2
0
        static void Main(string[] args)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json")
                          .AddEnvironmentVariables();

            Configuration = builder.Build();

            ILoggerFactory loggerFactory = new LoggerFactory()
                                           .AddConsole()
                                           .AddDebug();

            ILogger logger = loggerFactory.CreateLogger <Program>();

            var port = int.Parse(Configuration["service:port"]);

            IEventEmitter kafkaEmitter = new KafkaEventEmitter();
            // TODO: this channel needs to use a service-discovery hostname
            Channel orderChannel = new Channel($"{Configuration["orderclient:hostname"]}:{Configuration["orderclient:port"]}",
                                               ChannelCredentials.Insecure);

            logger.LogInformation($"Configured gRPC channel for Order Management client: {orderChannel.ResolvedTarget}");
            var orderClient = new OrderManagement.OrderManagementClient(orderChannel);

            Server server = new Server
            {
                Services = { OrderCommand.BindService(new OrderCommandImpl(kafkaEmitter, orderClient)) },
                Ports    = { new ServerPort("localhost", port, ServerCredentials.Insecure) }
            };

            server.Start();

            logger.LogInformation("Orders Command RPC Service Listening on Port " + port);

            // Keep the process alive without consuming CPU cycles
            mre.WaitOne();
        }
Пример #3
0
        static void Main(string[] args)
        {
            const int Port = 3000;

            IEventEmitter kafkaEmitter = new KafkaEventEmitter();
            Channel       orderChannel = new Channel("127.0.0.1:3001", ChannelCredentials.Insecure);
            var           orderClient  = new OrderManagement.OrderManagementClient(orderChannel);

            Server server = new Server
            {
                Services = { OrderCommand.BindService(new OrderCommandImpl(kafkaEmitter, orderClient)) },
                Ports    = { new ServerPort("localhost", Port, ServerCredentials.Insecure) }
            };

            server.Start();

            Console.WriteLine("Orders Command RPC Service Listening on Port " + Port);
            Console.WriteLine("Press any key to stop");

            Console.ReadKey();

            server.ShutdownAsync().Wait();
        }