day = data.get('day') act_type = data.get('act_type') title = data.get('title') act_desc = data.get('act_desc') try: print("success handle data:{}".format(data)) # raise IOError except Exception as ex: print("handle data error, data: {} ex:{}".format(body, ex)) else: channel.basic_ack(delivery_tag=method.delivery_tag) if __name__ == '__main__': rabbit_config = { 'username': '******', 'password': '******', 'host': '127.0.0.1', 'port': 5672, } print("**** start write heart record process ****") # client = RabbitmqBox(**rabbit_config) # client.connect_server() # queue_name = "resource_distribute" # client.consume_from_queue(queue_name=queue_name, callback=handle_write) with RabbitmqBox(**rabbit_config) as client: client.connect_server() queue_name = "resource_distribute" client.consume_from_queue(queue_name=queue_name, callback=handle_write)
uid = data.get('uid') source_id = data.get('source_id') num = data.get('num') diamond = data.get('diamond') day = data.get('day') act_type = data.get('act_type') title = data.get('title') act_desc = data.get('act_desc') try: print("success handle data:{}".format(data)) except Exception as ex: print("handle data error, data: {} ex:{}".format(body, ex)) else: channel.basic_ack(delivery_tag=method.delivery_tag) if __name__ == '__main__': rabbit_config = { 'username': '******', 'password': '******', 'host': '127.0.0.1', 'port': 5672, } print("**** start write heart record process ****") client = RabbitmqBox(**rabbit_config) client.connect_server(exchange='logs_direct', ex_type='direct') # 用户定义消息关键字 serverities = ['info', 'warning', 'error'] client.consume_from_queue(callback=handle_write, routing_keys=serverities)
import json # from rabbit_mq import RabbitmqBox from rabbit_mq_back.rabbit_mq import RabbitmqBox if __name__ == '__main__': rabbit_config = { 'username': '******', 'password': '******', 'host': '127.0.0.1', 'port': 5672, } print("**** start write fanout process ****") client = RabbitmqBox(**rabbit_config) client.connect_server(exchange='logs_fanout', ex_type='fanout') for item in range(1, 10): data = { 'stype': 'mic', 'uid': 'adbbddd', 'source_id': '123' + str(item), } client.publish_to_queue(msg=json.dumps({'dd': 44})) client.connection.close()
print("handle body: {}, data:{}".format(body, data)) stype = data.get('stype') uid = data.get('uid') source_id = data.get('source_id') num = data.get('num') diamond = data.get('diamond') day = data.get('day') act_type = data.get('act_type') title = data.get('title') act_desc = data.get('act_desc') try: print("success handle data:{}".format(data)) except Exception as ex: print("handle data error, data: {} ex:{}".format(body, ex)) else: channel.basic_ack(delivery_tag=method.delivery_tag) if __name__ == '__main__': rabbit_config = { 'username': '******', 'password': '******', 'host': '127.0.0.1', 'port': 5672, } print("**** start write heart record process ****") client = RabbitmqBox(**rabbit_config) client.connect_server() queue_name = "resource_distribute_test" client.consume_from_queue(queue_name=queue_name, callback=handle_write)
import json # from rabbit_mq import RabbitmqBox from rabbit_mq_back.rabbit_mq import RabbitmqBox if __name__ == '__main__': rabbit_config = { 'username': '******', 'password': '******', 'host': '127.0.0.1', 'port': 5672, } print("**** start write fanout process ****") client = RabbitmqBox(**rabbit_config) client.connect_server(exchange='logs_topic', ex_type='topic') for item in range(1, 10): data = { 'stype': 'mic', 'uid': 'adbbddd', 'source_id': '123' + str(item), } client.publish_to_queue(msg=json.dumps(data), routing_key='anonymous.info') client.connection.close()
import json # from rabbit_mq import RabbitmqBox from rabbit_mq_back.rabbit_mq import RabbitmqBox if __name__ == '__main__': rabbit_config = { 'username': '******', 'password': '******', 'host': '127.0.0.1', 'port': 5672, } print("**** start write fanout process ****") client = RabbitmqBox(**rabbit_config) client.connect_server(exchange='logs_direct', ex_type='direct') for item in range(1, 10): data = { 'stype': 'mic', 'uid': 'adbbddd', 'source_id': '123' + str(item), } client.publish_to_queue(msg=json.dumps(data), routing_key='error') client.connection.close()
num = data.get('num') diamond = data.get('diamond') day = data.get('day') act_type = data.get('act_type') title = data.get('title') act_desc = data.get('act_desc') try: print("success handle data:{}".format(data)) except Exception as ex: print("handle data error, data: {} ex:{}".format(body, ex)) else: channel.basic_ack(delivery_tag=method.delivery_tag) if __name__ == '__main__': rabbit_config = { 'username': '******', 'password': '******', 'host': '127.0.0.1', 'port': 5672, } print("**** start write heart record process ****") client = RabbitmqBox(**rabbit_config) client.connect_server(exchange='logs_topic', ex_type='topic') # 用户定义消息关键字 binding_keys = ['*.info', '#.error'] # “#”表示0个或若干个关键字,“*”表示一个关键字。如“log.*”能与“log.warn”匹配, # 无法与“log.warn.timeout”匹配;但是“log.#”能与上述两者匹配。 client.consume_from_queue(callback=handle_write, routing_keys=binding_keys)