Pulsar is a distributed pub-sub messaging platform with a very flexible messaging model and an intuitive client API.
pulsar本质上也是一个消息队列,但是在消息队列的基础上增加了一些额外的功能。
Main features
- Horizontally scalable (Millions of independent topics and millions of messages published per second)
- Strong ordering and consistency guarantees
- Low latency durable storage
- Topic and queue semantics
- Load balancer
- Designed for being deployed as a hosted service:
- Multi-tenant
- Authentication
- Authorization
- Quotas
- Support mixing very different workloads
- Optional hardware isolation
- Keeps track of consumer cursor position
- REST API for provisioning, admin and stats
- Geo replication
- Transparent handling of partitioned topics
- Transparent batching of messages
其中比较有亮点的功能我认为有两点
- 消息的时序性保证和一致性保证
- pulsar functions.支持类似flink的实时流式计算模型
下载安装
到官网下载安装包 pulsar 官网
$ wget https://archive.apache.org/dist/pulsar/pulsar-2.4.2/apache-pulsar-2.4.2-bin.tar.gz
$ tar xvfz apache-pulsar-2.4.2-bin.tar.gz
$ cd apache-pulsar-2.4.2
启动standalone
$ bin/pulsar standalone
启动消费者
$ bin/pulsar-client consume my-topic -s "first-subscription"
发送消息
$ bin/pulsar-client produce my-topic --messages "hello-pulsar"
#消费者打印收到消息
----- got message -----
hello-pulsar
坑
由于安装centos7的时候把主机名做了修改,导致启动失败(初步怀疑pulsar启动会根据主机名称去访问),建议主机名别随意修改,保留为localhost即可。