Esempio n. 1
0
        private async Task RunAsync(CancellationToken stoppingToken)
        {
            using var subscriber = new SubscriberSocket($">tcp://127.0.0.1:4444");
            subscriber.Subscribe("ping");
            using var publisher = new PublisherSocket($">tcp://127.0.0.1:5555");
            _logger.LogInformation("Pong service ready");
            while (!stoppingToken.IsCancellationRequested)
            {
                try
                {
                    var msg = await subscriber.ReceiveMultipartMessageAsync(cancellationToken : stoppingToken);

                    if (stoppingToken.IsCancellationRequested)
                    {
                        break;
                    }
                    _logger.LogInformation("Ping received");
                    await Task.Delay(100);

                    publisher.SendMoreFrame("pong");
                    publisher.SendMoreFrameEmpty();
                    publisher.SendFrame(msg[2].Buffer);
                }
                catch (Exception e)
                {
                    _logger.LogError(e, "ERROR in PingService");
                    break;
                }
            }
        }
Esempio n. 2
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            using var publisher = new PublisherSocket($">tcp://127.0.0.1:5555");
            await Task.Delay(1000);

            _logger.LogInformation("Introducing the ball");
            publisher.SendMoreFrame("ping");
            publisher.SendMoreFrameEmpty();
            publisher.SendFrame(Encoding.ASCII.GetBytes("The ball"));
        }