I'm trying to connect rabbitMQ in one machine (Windows 10) to other machine (Raspberry pi 4). The windows machine is the producer, and the pi is the receiver. Both are connected to the same network, and defined with the same localhost. Although the message is sent correctly to the queue, it is not received by the Pi. Is there any steps that I'm missing?
Below is the producer code (python in PC- Windows)
import pika
connection = pika.BlockingConnection(
pika.ConnectionParameters(host='localhost'))
channel = connection.channel()
channel.queue_declare(queue='my-queue')
channel.basic_publish(exchange='', routing_key='my-queue', body='Hello World from windows!!')
print(" [x] Sent 'Hello World from windows!'")
connection.close()
Consumer code (in Pi)
import pika
host = 'localhost'
queue = 'my-queue'
def on_message(ch, method, properties, body):
message = body.decode('UTF-8')
print(message)
def main():
connection_params = pika.ConnectionParameters(host=host)
connection = pika.BlockingConnection(connection_params)
channel = connection.channel()
channel.queue_declare(queue=queue)
channel.basic_consume(queue=queue, on_message_callback=on_message,
auto_ack=True)
print('Subscribed to ' + queue + ', waiting for messages...')
channel.start_consuming()
if __name__ == '__main__':
main()