Apache RocketMQ python client

Clone this repo:
  1. 9990413 doc(notice): update copyright year to 2019. by dinglei · 2 weeks ago master
  2. 0919781 doc(readme): add apache license v2 link. by dinglei · 2 weeks ago
  3. 439dff5 feat(platforms): switch branch ctypes to master to support both python2.x and python 3.x by ShannonDing · 2 weeks ago
  4. 08bc79c doc(readme): use cpp 1.2.4 for quick install by dinglei · 2 weeks ago boostpython
  5. bf88e10 style(client) polish code style by dinglei · 4 weeks ago ctypes

rocketmq-client-python

License Build Status codecov PyPI

RocketMQ Python client, based on rocketmq-client-cpp, supports Linux and macOS

Installation

pip install rocketmq-client-python

Usage

Producer

from rocketmq.client import Producer, Message

producer = Producer('PID-XXX')
producer.set_name_server_address('127.0.0.1:9876')
producer.start()

msg = Message('YOUR-TOPIC')
msg.set_keys('XXX')
msg.set_tags('XXX')
msg.set_body('XXXX')
ret = producer.send_sync(msg)
print(ret.status, ret.msg_id, ret.offset)
producer.shutdown()

PushConsumer

import time

from rocketmq.client import PushConsumer


def callback(msg):
    print(msg.id, msg.body)


consumer = PushConsumer('CID_XXX')
consumer.set_name_server_address('127.0.0.1:9876')
consumer.subscribe('YOUR-TOPIC', callback)
consumer.start()

while True:
    time.sleep(3600)

consumer.shutdown()

License

Apache License, Version 2.0 Copyright (C) Apache Software Foundation