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

image.png

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


锅包肉
89 声望17 粉丝

这个人很懒,没有什么说的。


引用和评论

0 条评论