kafka 发布订阅分组
Posted 72 months ago kafka linux java python 發佈 訂閱 发布 订阅
惹不起的kafka
启动zookeeper
./zookeeper-server-start.sh ../config/zookeeper.pperties
启动kafka
./kafka-server-start.sh ../config/server.propertis
记得给配置文件配置分区数
代码
发布
from kafka import KafkaProducer
producer = KafkaProducer(bootstrap_servers='localhost:9092')
if __name__ == '__main__':
for a in range(1,2):
producer.send('chat',partition=1,value=b'some_message_bytes')
producer.flush()
订阅分区
from kafka import KafkaConsumer
if __name__ == '__main__':
consumer = KafkaConsumer("chat",bootstrap_servers=['localhost:9092'])
consumer.subscribe(pattern="1")
for msg in consumer:
print(msg)
惹不起 惹不起 rabbitMQ 的2500个 队列才3g内存
kafka 一个topic (概念上的队列) 分区(打的tag) 2000个 竟然 需要40g 储存。。。
口区。。。。
我要去试试 nsq !!!