zeromq / netmq

A 100% native C# implementation of ZeroMQ for .NET
Other
2.97k stars 743 forks source link

Request-Response pattern not working when client and sever are hosted on different machines #1038

Closed BhusanBibhuti closed 2 years ago

BhusanBibhuti commented 2 years ago

Environment

NetMQ Version:    4.0.1.10
Operating System:  Windows Server 2016
.NET Version:     NET 5

Expected behaviour

  1. Client sends message without any issue

  2. Server sends back acknowledhment

Actual behaviour

  1. Client is able to send
  2. Server is not sending any response

Steps to reproduce the behaviour

Create Client Worker Service , host it on a machine

        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            /*string endpointLocal = @"127.0.0.1:5678";*/
            string endpointRemote = @"10.83.219.120:5678"; /*IP of the server machine*/
            string sampleMessage = "Hello World";
            while (!stoppingToken.IsCancellationRequested)
            {
                using (var client = new RequestSocket($">tcp://{endpointRemote}"))
                {
                    _logger.LogInformation("Attempting to send NetMQ Message ");
                    client.SendFrame(JsonConvert.SerializeObject(sampleMessage));
                    _logger.LogInformation("Attempting to send NetMQ Message - Sent ");
                    _logger.LogInformation("Awaiting response from NetMQ Message server - Started ");
                    string response = client.ReceiveFrameString();
                    _logger.LogInformation("Awaiting response from NetMQ Message server - Finished ");
                    if (!string.IsNullOrEmpty(response))
                    {
                        _logger.LogInformation("Saving client configuration");
                    }
                }

Create Server Worker Service , host it on server machine

        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            /*string endpointLocal = @"127.0.0.1:5678";*/
            string endpointRemote = @"10.83.219.120:5678"; /*IP of the server machine*/
            while (!stoppingToken.IsCancellationRequested)
            {
                _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
                using (var server = new ResponseSocket($"@tcp://{endpointRemote}")) 
                {
                    while (true)
                    {
                        try
                        {
                            _logger.LogInformation($"Receiving Message");
                            string jsonMessage = server.ReceiveFrameString();
                            var message = JsonConvert.DeserializeObject<string>(jsonMessage);                            
                            server.SendFrame(JsonConvert.SerializeObject("Sending ACK.."));
                        }
                        catch (Exception exception)
                        {
                            _logger.LogError(exception, "Unable to process");
                        }
                    }
                }
            }
        }

It works fine when both the services are hosted on the same machine , doesn't work when hosted under different machines.

ClientWorkerService.zip

BhusanBibhuti commented 2 years ago

HI Team , any further updates on this ?

BhusanBibhuti commented 2 years ago

Closing the issue , since it was identified an issue with the firewall. This has been fixed.