-
Notifications
You must be signed in to change notification settings - Fork 323
helloworld.zh_CN
Ady Liu edited this page May 31, 2012
·
2 revisions
#Hello world 文档>>Hello World
启动服务端(Broker)参考安装指南.
###发送消息
import jafka
producer = jafka.Producer('127.0.0.1',9092)
producer.send(topic='demo',messages='Hello jafka')
producer.send('demo',('Try it','Jafka is simple'))
producer.send('demo',('Try it','Jafka is simple'),2)
producer.close()
###消费消息
import jafka
import time
consumer = jafka.Consumer('127.0.0.1',9092)
offset = 0
while True:
messages = consumer.fetch('demo',0,offset)
if not messages:
time.sleep(1)
continue
for offsetmessage in messages:
offset,message = offsetmessage
print(offset,' => ',message.decode())
Language: English | Simple Chinese