0

Trying to make a containerised windows service using docker to consume messages from rabbitmq queues. I am also using EasyNetQ client to connect with RabbitMQ.

However it is failing with Persistent Channel timed out exception

The operation requested on PersistentChannel timed out

Here is my code for Executing the consumer

protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
    while (!stoppingToken.IsCancellationRequested)
    {
          try
          {
              using (var bus = RabbitHutch.CreateBus("host=localhost;username=guest;password=guest"))
              {
                 bus.Receive("Queue", msg => msg.Add<CustomModel>(m =>
                 {
                   _logger.LogInformation("Received Message: {0}, {1}", m.Prop1, m.Prop2);}));
                 }
                _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);               
              }
           }
           catch (Exception ex)
           {
               _logger.LogError(ex.InnerException?.ToString());
           }
     }
}

I am not really sure what could be causing the timeout? Anybody have similar issue?

KJSR
  • 1,679
  • 6
  • 28
  • 51
  • Is the connection string from your example the same with the one from your Windows service? I am asking this because this exception may appear if you are not using the correct host/username/password in the connection string. – tzrm Feb 12 '20 at 10:50
  • That is just an example but in my actual programme I have username and password also in the connection string. Will update queustions thanks. – KJSR Feb 12 '20 at 10:53
  • Maybe the user doesn't have the permissions to access the wanted virtual host.. – tzrm Feb 12 '20 at 11:17
  • Makes sense, do you suggest i need to grant access to Windows Service? – KJSR Feb 12 '20 at 11:46
  • The user from the connection string needs to have permissions to access the virtual host, you can find more details [here](https://www.rabbitmq.com/access-control.html) about the permissions/authorization. – tzrm Feb 12 '20 at 11:54
  • Its strange as I can post and receive message using a console app. – KJSR Feb 12 '20 at 12:11
  • Maybe [this](https://www.reddit.com/r/csharp/comments/b1719z/how_could_connect_my_application_to_rabbitmq_in/) can help. Telling to the Docker container to forward the default (5672) port. – tzrm Feb 12 '20 at 12:25
  • ok thanks will look at the solution. Just to confirm so rabbitmq is also running as a docker instance. – KJSR Feb 12 '20 at 13:12
  • You need to replace localhost with the IP of the machine where the RabbitMQ is running , since on the windows worker container localhost will be resolved to the worker container itself. – Soumen Mukherjee Feb 12 '20 at 15:16

0 Answers0