ProgramSpree
ProgramSpree

Reputation: 402

Unable to receive messages in RabbitMQ and UI shows empty queue

I'm following the tutorial on https://www.rabbitmq.com/tutorials/tutorial-one-python.html

I've set up RabbitMQ using docker. Have defined the exchange, etc, in there.

The management UI shows the exchange created. And when the sender script is executed the first time, the queue is showing up in the UI too.

I run the consumer first & then the publisher. But while the message gets published (assuming it is, since the send script doesn't throw any errors), the consumer doesn't receive any messages. I can see the AMQP connections getting established and closed (in the case of the publisher) correctly. But the queue is empty.

The management UI also shows an empty queue. I tried publishing persistent & non-persistent messages using the UI itself, but even there, while the message gets published, I receive "Queue is empty" while doing Get Messages.

Please help me out!

docker-compose.yml:

...

  my_rabbit:
    hostname: my_rabbit # persistence
    build:
      context: .
      dockerfile: Dockerfile_rabbit
    restart: unless-stopped
    container_name: my_rabbit
    volumes:
      - "./rabbitmq:/var/lib/rabbitmq"
      - "./rabbitmq_logs:/var/log/rabbitmq"
    command: ["./rabbit_init.sh"]
    ports:
      - 5670:5672
      - 20888:15672 # rabbitmq management plugin
    logging:
      driver: "json-file"
      options:
        max-size: "100M"
        max-file: "10"
...

Dockerfile:

FROM rabbitmq

RUN apt-get update && apt-get install -y wget python3
# Define environment variables.
ENV RABBITMQ_USER user
ENV RABBITMQ_PASSWORD password
ENV RABBITMQ_VHOST myvhost
ENV RABBITMQ_PID_FILE /var/lib/rabbitmq/mnesia/rabbitmq

ADD rabbit_init.sh /rabbit_init.sh
EXPOSE 15672
# Define default command
RUN chmod +x /rabbit_init.sh

CMD ["/rabbit_init.sh"]

rabbit_init.sh:

#!/bin/sh

# Create Rabbitmq user
( sleep 10 ; \
    rabbitmqctl wait --timeout 60 $RABBITMQ_PID_FILE ; \
    rabbitmqctl add_user $RABBITMQ_USER $RABBITMQ_PASSWORD 2>/dev/null ; \
    rabbitmqctl set_user_tags $RABBITMQ_USER administrator ; \
    rabbitmqctl add_vhost $RABBITMQ_VHOST ; \
    rabbitmqctl set_permissions -p  $RABBITMQ_VHOST $RABBITMQ_USER  ".*" ".*" ".*" ; \
    rabbitmq-plugins enable rabbitmq_management ; \
    wget 'https://raw.githubusercontent.com/rabbitmq/rabbitmq-management/v3.7.15/bin/rabbitmqadmin' ; \
    chmod +x rabbitmqadmin ; \
    sed -i 's|#!/usr/bin/env python|#!/usr/bin/env python3|' rabbitmqadmin ; \
    mv rabbitmqadmin /bin/ ; \
    sleep 2; \
    rabbitmqadmin declare queue --username=$RABBITMQ_USER --password=$RABBITMQ_PASSWORD --vhost=$RABBITMQ_VHOST name=xxx durable=true arguments='{"x-overflow":"reject-publish", "x-max-length-bytes":5000000000}' ; \
    rabbitmqadmin declare exchange --username=$RABBITMQ_USER --password=$RABBITMQ_PASSWORD --vhost=$RABBITMQ_VHOST name=xxx type=direct durable=true ; \
    rabbitmqadmin declare binding --username=$RABBITMQ_USER --password=$RABBITMQ_PASSWORD --vhost=$RABBITMQ_VHOST source=xxx destination=xxx routing_key=xxx; \
    ) &

rabbitmq-server $@

Upvotes: 2

Views: 1938

Answers (1)

SwampratNZ
SwampratNZ

Reputation: 36

Have you tried publishing the message without the consumer enabled? Then the message will just be stored in the queue and you can view it. If the consumer is on it will consume the message straight away. If you are publishing and receiving no errors it is most likely the consumer that is the problem.

Upvotes: 2

Related Questions