Ejemplo n.º 1
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("Starting...");
            var serverAddress     = "https://localhost:5001";
            var httpClientHandler = new HttpClientHandler
            {
                ServerCertificateCustomValidationCallback =
                    HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
            };
            var httpClient = new HttpClient(httpClientHandler);
            var channel    = GrpcChannel.ForAddress(serverAddress, new GrpcChannelOptions {
                HttpClient = httpClient
            });
            var _client = new MessageService.MessageServiceClient(channel);

            // example 1
            var request = new GetMessageRequest {
                Id = "6523"
            };
            var response = _client.GetMessage(request);

            Console.WriteLine($"Server response: {response.Message} {response.Value1} {response.Value2}");

            // example 2
            var stream = _client.GetMessagesStream(request);

            while (await stream.ResponseStream.MoveNext(CancellationToken.None))
            {
                Console.WriteLine($"{stream.ResponseStream.Current.Message} {stream.ResponseStream.Current.Value1}");
            }

            Console.WriteLine(stream.GetStatus());
        }
Ejemplo n.º 2
0
        public void InitalSevice()
        {
            Thread thr = new Thread(() =>
            {
                while (true)
                {
                    try
                    {
                        InstanceContext context = new InstanceContext(this);
                        mService = new MessageService.MessageServiceClient(context);
                        // mService.Register("000002");
                        Program.WriteLog(Program.g_serialNum + "注册");
                        mService.Register(Program.g_serialNum);  //车编号
                        _ReConnectEvent.WaitOne();
                        _ReConnectEvent.Reset();
                    }
                    catch (Exception ex)
                    {
                        Program.WriteLog(Program.g_serialNum + " 说:" + ex.Message);
                        Thread.Sleep(3000);
                        // throw;
                    }
                }
            });

            thr.Start();
        }
Ejemplo n.º 3
0
 public RepositoryGrpc(
     MessageService.MessageServiceClient messageClient,
     RankingService.RankingServiceClient rankingClient,
     VoteService.VoteServiceClient voteClient)
 {
     _messageClient = messageClient;
     _rankingClient = rankingClient;
     _voteClient    = voteClient;
 }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            var channel = GrpcChannel.ForAddress("https://localhost:5001");
            var client  = new MessageService.MessageServiceClient(channel);

            Console.WriteLine("Digite a mensagem");
            var mensagem = Console.ReadLine();

            var request = new SampleRequest
            {
                Conteudo = mensagem,
                Id       = 1
            };

            var response = client.Ping(request);

            Console.WriteLine(JsonConvert.SerializeObject(response));
            Console.ReadLine();
            Console.WriteLine("Hello World!");
        }
Ejemplo n.º 5
0
 public FanoutConsumerClient(string address, Action <string> consumeHook, CancellationToken cancellationToken)
 {
     _cancellationToken    = cancellationToken;
     _address              = address;
     _consumeHook          = consumeHook;
     _grpcChannel          = GrpcChannel.ForAddress(_address);
     _messageServiceClient = new MessageService.MessageServiceClient(_grpcChannel);
     _messageTask          = Task.Run(async() =>
     {
         while (true)
         {
             try
             {
                 await WaitMessageAsync();
             }
             catch
             {
                 // any cases retry
                 Healthy = false;
             }
         }
     }, _cancellationToken);
 }