共计 2524 个字符,预计需要花费 7 分钟才能阅读完成。
Pulsar 简略介绍
Pulsar 是一个用于服务器到服务器的音讯零碎,具备多租户、高性能等劣势。Pulsar 最后由 Yahoo 开发,目前由 Apache 软件基金会治理。
Pulsar 的要害个性如下:
- Pulsar 的单个实例原生反对多个集群,可跨机房在集群间无缝地实现音讯复制。
- 极低的公布提早和端到端提早。
- 可无缝扩大到超过一百万个 topic。
- 简略的客户端 API,反对 Java、Go、Python 和 C++。
- 反对多种 topic 订阅模式(独占订阅、共享订阅、故障转移订阅)。
- 通过 Apache BookKeeper 提供的长久化音讯存储机制保障消息传递。
- 由轻量级的 serverless 计算框架 Pulsar Functions 实现流原生的数据处理。
- 基于 Pulsar Functions 的 serverless connector 框架 Pulsar IO 使得数据更易移入、移出 Apache Pulsar。
- 分层式存储可在数据古老时,将数据从热存储卸载到冷 / 长期存储(如 S3、GCS)中。
官网文档地址:https://pulsar.apache.org/doc…
Pulsar 在 Linux 或 MacBook 上装置
Pulsar 是 java 开发的, 只须要装置 jdk 环境
MacBook 装置 jdk8
Linux 卸载 openjdk 并装置 Oracle jdk
官网下载地址:https://pulsar.apache.org/zh-…
# 下载 pulsar | |
wget https://archive.apache.org/dist/pulsar/pulsar-2.8.0/apache-pulsar-2.8.0-bin.tar.gz | |
#解压 | |
tar xvfz apache-pulsar-2.8.0-bin.tar.gz | |
#进入目录 | |
cd apache-pulsar-2.8.0 | |
#启动单机模式 Pulsar 会主动启动一个 zookeeper | |
bin/pulsar standalone |
发送和订阅数据
应用 Pulsar-client 工具
# 进入目录 | |
cd apache-pulsar-2.8.0 | |
#消费者订阅: 在 first-subscription 订阅中 consume 一条音讯到 topic:my-topic 的命令 | |
bin/pulsar-client consume my-topic -s "first-subscription" | |
#开启另一个终端发送数据, 留神察看订阅者收到数据:content:hello-pulsar | |
#生产者发送: 向名称为 my-topic 的 topic 发送一条简略的音讯 hello-pulsar | |
bin/pulsar-client produce my-topic --messages "hello-pulsar" |
开启认证性能
# 生成秘钥 | |
bin/pulsar tokens create-secret-key --output /Users/liang/software/apache-pulsar-2.8.0/my-secret.key --base64 | |
#创立 Token, 记住生成的 token | |
bin/pulsar tokens create --secret-key file:///Users/liang/software/apache-pulsar-2.8.0/my-secret.key --subject admin | |
eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhZG1pbiJ9.UCsEs8p8E_7OiTvCuf0rRvGP26ZPFunnSEbjGsynVqM | |
#批改配置, 开启 token 认证 | |
vim conf/standalone.conf | |
#启用认证 | |
authenticationEnabled=true | |
authenticationProviders=org.apache.pulsar.broker.authentication.AuthenticationProviderToken | |
tokenSecretKey=file:///Users/liang/software/apache-pulsar-2.8.0/my-secret.key | |
#broker 与 broker 之间的互相通信 (如果不配置报错:HTTP 401 Unauthorized BookKeeper client is closed) | |
brokerClientAuthenticationPlugin=org.apache.pulsar.client.impl.auth.AuthenticationToken | |
brokerClientAuthenticationParameters=token:eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhZG1pbiJ9.UCsEs8p8E_7OiTvCuf0rRvGP26ZPFunnSEbjGsynVqM | |
#重启 standalone | |
bin/pulsar standalone | |
#在次执行订阅报错: Unable to authenticate 没有权限 | |
bin/pulsar-client consume my-topic -s "first-subscription" | |
#执行: 获取租户列表: HTTP 401 Unauthorized | |
bin/pulsar-admin tenants list | |
#批改客户端配置 | |
vim conf/client.conf | |
authPlugin=org.apache.pulsar.client.impl.auth.AuthenticationToken | |
authParams=token:eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhZG1pbiJ9.UCsEs8p8E_7OiTvCuf0rRvGP26ZPFunnSEbjGsynVqM | |
#在次执行订阅胜利 | |
bin/pulsar-client consume my-topic -s "first-subscription" | |
#执行: 获取租户列表胜利 | |
bin/pulsar-admin tenants list | |
#胜利显示 | |
"public" | |
"sample" |
参考链接:
https://www.jianshu.com/p/dd3…
https://blog.csdn.net/wt33450…
正文完