python3调用rocket mq

发布时间:2023-06-24 14:30

install

https://github.com/apache/roc...

    wget https://github.com/apache/rocketmq-client-cpp/releases/download/2.0.0/rocketmq-client-cpp-2.0.0-centos7.x86_64.rpm
    sudo rpm -ivh rocketmq-client-cpp-2.0.0-centos7.x86_64.rpm

python3调用rocket mq_第1张图片

Installation

pip install rocketmq-client-python

Producer

from rocketmq.client import Producer, Message

producer = Producer('test-litx')
producer.set_name_server_address('rxxrocketmq-namesrv.sit.dexxxxm:9876')
producer.start()

msg = Message('itworkspace')
msg.set_keys('status')
msg.set_tags('json')
msg.set_body('{"alertname": "test666666666","building": "t11111tttt"}')
ret = producer.send_sync(msg)
print(ret.status, ret.msg_id, ret.offset)
producer.shutdown()

image.png

PushConsumer

import time
from rocketmq.client import PushConsumer, ConsumeStatus

def callback(msg):
    print(msg.id, msg.body)
    return ConsumeStatus.CONSUME_SUCCESS

consumer = PushConsumer('itworkxxxce-consumer')
consumer.set_name_server_address('red-rocketmq-namesrv.sit.devops.xixxxu.com:9876')
consumer.subscribe('itwxxce', callback)
consumer.start()

time.sleep(3)

consumer.shutdown()

image.png

ItVuer - 免责声明 - 关于我们 - 联系我们

本网站信息来源于互联网,如有侵权请联系:561261067@qq.com

桂ICP备16001015号