How to communicate two own Docker container by rabbitmq

i am building a very simple project. Two python scripts; producer.py and consumer.py. Producer sends random numbers, consumer prints it. It’s working without docker.

I build two docker images for consumer and producer, and want to “communicate” it by docker-compose, by when i run the docker-compose file i see this:

emit_log_1  | Traceback (most recent call last):
emit_log_1  |   File "emit_log.py", line 7, in <module>
emit_log_1  |     connection = pika.BlockingConnection(
emit_log_1  |   File "/usr/local/lib/python3.8/site-packages/pika/adapters/blocking_connection.py", line 359, in __init__
emit_log_1  |     self._impl = self._create_connection(parameters, _impl_class)
emit_log_1  |   File "/usr/local/lib/python3.8/site-packages/pika/adapters/blocking_connection.py", line 450, in _create_connection
emit_log_1  |     raise self._reap_last_connection_workflow_error(error)
emit_log_1  | pika.exceptions.AMQPConnectionError
1_emit_log_1 exited with code 1

And exactly the same for receive:

Docker-compose.yml:

version: '3'

services:
 rabbitmq:
  image: rabbitmq:3-management
  ports:
   - "5672:5672"
   - "15672:15672"


 emit_log:
  build:
   context: .
   dockerfile: Dockerfile.emit_log
  ports:
   - "8081:8081"
   - "8001:8001"
  links:
   - rabbitmq


 receive:
  build:
   context: .
   dockerfile: Dockerfile.receive
  ports:
   - "8082:8082"
   - "8002:8002"
  links:
   - rabbitmq

Source: StackOverflow