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