Similar to keywords
Producers:
# coding:utf8# __author:administrator# Date:2018/3/ the 0015# /usr/bin/env Pythonimport pikaconnection=Pika. Blockingconnection (Pika. Connectionparameters (Host='localhost')) Channel=Connection.channel () channel.exchange_declare (Exchange='Topic_logs', type='Topic') Key='Ha.ga.ef'message='Hello World'channel.basic_publish (Exchange='Topic_logs', Routing_key=Key, Body=message) Print ("Sent Message") Connection.close ()
Consumers:
# coding:utf8# __author:administrator# Date:2018/3/ the 0015# /usr/bin/env pythonimport Pikaimport sysconnection=Pika. Blockingconnection (Pika. Connectionparameters (Host='localhost')) Channel=Connection.channel () channel.exchange_declare (Exchange='Topic_logs', type='Topic') Result= Channel.queue_declare (exclusive=True) queue_name=Result.method.queuebind_key='ha'Channel.queue_bind (Exchange='Topic_logs', Queue=queue_name, Routing_key=bind_key) Print ('Wait for Logs') def callback (ch, method, properties, body): print (body) Channel.basic_consume (callback, queue< /c8>=queue_name, No_ack=True) channel.start_consuming ()
Python---RabbitMQ (4) Fuzzy matching topic in exchange