CentOS7 搭建Pulsar 消息队列环境,CentOS(Linux)部署Pulsar,亲测成功,以及Python操作Pulsar实例驱动
在 最佳开源数据库与数据分析平台奖 中,之前曾连续两年入选的 Kafka 意外滑铁卢落选,取而代之的是新兴项目 Pulsar,Bossie Awards中对 Pulsar 点评如下:“Pulsar 旨在取代 Apache Kafka 多年的主宰地位。Pulsar在很多情况下提供了比 Kafka 更快的吞吐量和更低的延迟,并为开发人员提供了一组兼容的 API,让他们可以很轻松地从 Kafka 切换到 Pulsar。Pulsar 的最大优点在于它提供了比 Apache Kafka 更简单明了、更健壮的一系列操作功能,特别在解决可观察性、地域复制和多租户方面的问题。在运行大型 Kafka 集群方面感觉有困难的企业可以考虑转向使用 Pulsar。”
Pulsar中文文档:https://pulsar.apache.org/docs/zh-CN/standalone/
1,系统环境
a,操作系统 CentOS Linux release 7.6.1810 (Core) 64位,必须确保你的内存是4G以上,双核CPU!否则将无法新建默认命名空间。
b,确保jdk环境已经安装,具体教程请看 CentOS7 shell脚本安装jdk
c,确保Python3和对应的pip已经安装,具体教程请看 CentOS7 源码编译安装Python3.5
2,执行以下命令,启动Pulsar
wget https://archive.apache.org/dist/pulsar/pulsar-2.3.0/apache-pulsar-2.3.0-bin.tar.gz # 下载pulsar安装包 tar xvfz apache-pulsar-2.3.0-bin.tar.gz # 解压安装包 cd apache-pulsar-2.3.0 # 打开pulsar目录 bin/pulsar standalone # 启动单机pulsar bin/pulsar-client produce my-topic --messages "hello-pulsar" # 发送一条消息如图,消息已经成功发送
3,执行命令 pip3 install pulsar-client==2.3.1
4,创建Pulsar消费者监听python3程序 consumer.py
import pulsar client = pulsar.Client('pulsar://localhost:6650') consumer = client.subscribe('my-topic2', 'my-subscription') while True:msg = consumer.receive()try:print("Received message '{}' id='{}'".format(msg.data(), msg.message_id()))consumer.acknowledge(msg)except:consumer.negative_acknowledge(msg) client.close()运行 python3 consumer.py
5, 创建Pulsar生产者python3程序 producer.py
import pulsar client = pulsar.Client('pulsar://localhost:6650') producer = client.create_producer('my-topic2') for i in range(10):producer.send(('Hello-%d' % i).encode('utf-8')) client.close()运行 python3 producer.py
看到 消费者监听界面,出现如下消息
总结
以上是生活随笔为你收集整理的CentOS7 搭建Pulsar 消息队列环境,CentOS(Linux)部署Pulsar,亲测成功,以及Python操作Pulsar实例驱动的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: php新建文件在指定目录下,PHP在获取
- 下一篇: Linux安装后初始优化步骤(仅适用于C