Search code examples
dockerrabbitmqsymfonyphp-amqplib

"Error reading data" while executing a RabbitMQ consumer in Symfony


I have a RabbitMQ container and a PHP 7 container with a Symfony 3.1.x project that executes a RabbitMQ consumer using the OldSoundRabbitMqBundle.

When running this command that executes the test consumer:

bin/console rabbitmq:consumer -w test

I get the following error:

[PhpAmqpLib\Exception\AMQPIOException]

Error reading data. Received 0 instead of expected 7 bytes

My setup is very simple and I checked the following things:

  • RabbitMQ is at its latest version (3.6.5)
  • The configured host, vhost, user, password parameters are correct
  • mbstring extension is enabled

It's really easy to set up a project to reproduce the issue.

The sample project is available on GitHub and instructions are provided in the README file to reproduce the issue with just a few steps.

Here are some highlights:

docker-compose.yml

version: '2'
services:
  php:
    build: ./docker/php/
    links:
      - rabbitmq
    volumes:
      - ./src:/var/www/rabbitmq-test
    working_dir: /var/www/rabbitmq-test

  rabbitmq:
    image: rabbitmq:3.6-management

config.yml

old_sound_rabbit_mq:
    connections:
        default:
            host:     'rabbitmq'
            port:     5672
            user:     'guest'
            password: 'guest'
            vhost:    '/'
            lazy:     false
            # ...
    producers:
        # ...
    consumers:
        test:
            connection:       default
            exchange_options: {name: 'test', type: direct}
            queue_options:    {name: 'test'}
            callback:         test_consumer

The test_consumer service is a very simple class implementing the ConsumerInterface interface.

Would someone have any idea concerning my problem?


Solution

  • The answer was really straightforward. I had to change this in my config.yml:

    old_sound_rabbit_mq:
        connections:
            default:
                # ...
    
                use_socket: true
    

    to:

    old_sound_rabbit_mq:
        connections:
            default:
                # ...
    
                use_socket: false
    

    Note that false is the default value.