0

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()
Ran
  • 57
  • 6
  • please provide the receiver code and the error logs – Robson Sampaio Dec 02 '21 at 16:29
  • Hi @RobsonSampaio , I updated the question and added the consumer code. There is no error message,the problem is that the message is not received by the consumer. – Ran Dec 03 '21 at 09:32
  • 1
    I ran your consumer code in my rasp pi and the producer code in my PC and it worked! No errors at all. Bear in mind, that you have to change the localhost to point to the rabbitMQ address. In my case, my RabbitMQ Server is running in my PC, so the local host in the RaspPi had to be set to the IP address on my PC. – Robson Sampaio Dec 04 '21 at 13:19

0 Answers0