欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

CentOS7 搭建Pulsar 消息队列环境,CentOS(Linux)部署Pulsar,亲测成功,以及Python操作Pulsar实例驱动

发布时间:2025/3/11 37 豆豆
生活随笔 收集整理的这篇文章主要介绍了 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实例驱动的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。