Пример #1
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("Publisher");

            AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
            var channel = GrpcChannel.ForAddress(EndpointsConstants.BrokerAddress);
            var client  = new Publisher.PublisherClient(channel);

            while (true)
            {
                Console.Write("Enter the topic: ");
                var topic = Console.ReadLine().ToLower();

                Console.Write("Enter content: ");
                var content = Console.ReadLine();

                var request = new PublishRequest()
                {
                    Topic = topic, Content = content
                };

                try
                {
                    var reply = await client.PublishMessageAsync(request);

                    Console.WriteLine($"Publish Reply: {reply.IsSuccess}");
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Error publishin the message: {e.Message}");
                }
            }
        }
Пример #2
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("Running sensor...");

            var channel         = CreateSecureChannel();
            var publisherClient = new Publisher.PublisherClient(channel);

            var rnd = new Random();

            Console.WriteLine("Sensor type: ");
            var sensor = Console.ReadLine().Trim().ToLower();

            while (true)
            {
                var data    = rnd.Next(low, high + 1);
                var command = new PublishCommand {
                    Sensor = sensor, Data = data
                };
                try
                {
                    await publisherClient.PublishMessageAsync(command);

                    Console.WriteLine($"Send: {sensor} -> {data}");
                    await Task.Delay(data);
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Could not send data. {e.Message}");
                }
            }
        }
Пример #3
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("Sender");

            var httpHandler = new HttpClientHandler
            {
                ServerCertificateCustomValidationCallback =
                    HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
            };

            var channel = GrpcChannel.ForAddress(Settings.BROKER_ADDRESS, new GrpcChannelOptions {
                HttpHandler = httpHandler
            });
            var client = new Publisher.PublisherClient(channel);

            Console.Write("Enter the bank name: ");
            var bankName = Console.ReadLine().ToLower();
            var rates    = new Dictionary <Currency, double>();

            while (true)
            {
                rates.Clear();
                Console.WriteLine("Enter the rates for each currency (0 - not present)");

                foreach (var suit in (Currency[])Enum.GetValues(typeof(Currency)))
                {
                    Console.Write($" # {suit}: ");
                    var rate = Convert.ToDouble(Console.ReadLine());
                    if (rate > 0)
                    {
                        rates.Add(suit, rate);
                    }
                }

                var ratesString = JsonConvert.SerializeObject(rates);

                var request = new PublishRequest
                {
                    Bank    = bankName,
                    Content = ratesString
                };

                try
                {
                    var reply = await client.PublishMessageAsync(request);

                    Console.WriteLine($"Publish reply: {reply.IsSuccess}");
                }
                catch (RpcException e)
                {
                    Console.WriteLine($"Details: {e.Status.Detail}");
                    Console.WriteLine($"Status code: {e.Status.StatusCode}");
                }

                Console.ReadLine();
            }
        }