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-...

#下载pulsarwget 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  会主动启动一个zookeeperbin/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-pulsarbin/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,记住生成的tokenbin/pulsar tokens create --secret-key file:///Users/liang/software/apache-pulsar-2.8.0/my-secret.key --subject admineyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhZG1pbiJ9.UCsEs8p8E_7OiTvCuf0rRvGP26ZPFunnSEbjGsynVqM#批改配置,开启token认证vim conf/standalone.conf#启用认证authenticationEnabled=trueauthenticationProviders=org.apache.pulsar.broker.authentication.AuthenticationProviderTokentokenSecretKey=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.AuthenticationTokenbrokerClientAuthenticationParameters=token:eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhZG1pbiJ9.UCsEs8p8E_7OiTvCuf0rRvGP26ZPFunnSEbjGsynVqM#重启standalonebin/pulsar standalone#在次执行订阅报错: Unable to authenticate 没有权限bin/pulsar-client consume my-topic -s "first-subscription"#执行:获取租户列表: HTTP 401 Unauthorizedbin/pulsar-admin tenants list#批改客户端配置vim conf/client.confauthPlugin=org.apache.pulsar.client.impl.auth.AuthenticationTokenauthParams=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...