コード例 #1
0
    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)
コード例 #2
0
ファイル: msg_consumer_direct.py プロジェクト: AQFOFP/DEMO
    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)
コード例 #3
0
ファイル: msg_product_fanout.py プロジェクト: AQFOFP/DEMO
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()
コード例 #4
0
    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)
コード例 #5
0
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()
コード例 #6
0
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()
コード例 #7
0
    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)