py-amqp-reciver.py 613 B

1234567891011121314151617181920212223
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. import amqp
  4. from amqp.basic_message import Message
  5. def recv_callback(msg):
  6. headers = msg.headers
  7. print(headers.get("loggerName") + " " + msg.body.decode('utf-8'))
  8. if __name__ == "__main__":
  9. with amqp.Connection(
  10. host="localhost:5672",
  11. userid="admin",
  12. password="123456",
  13. virtual_host="/",
  14. insist=False) as c:
  15. channel = c.channel()
  16. channel.basic_consume(queue='proxylogtopic',
  17. callback=recv_callback, no_ack=True)
  18. while True:
  19. c.drain_events()