关于消息中间件:号称全新一代消息中间件来看看它有多牛逼

10次阅读

共计 4057 个字符,预计需要花费 11 分钟才能阅读完成。

最近这个 Apache Pulsar 消息中间件十分的火,号称下一代音讯中件,明天,就一起来看看它到底有多牛逼?

概述

Apache Pulsar 是一个应用 Apache Bookkeeper 提供长久化的 pub/sub 音讯平台,是一个用于服务端到服务端的消息中间件,最后由 Yahoo 开发并在 2016 年开源,目前正在 Apache 基金会下孵化。它能够提供如下个性:

  • 跨地区复制
  • 多租户
  • 零数据失落
  • 零 Rebalancing 工夫
  • 对立的队列和流模型
  • 高可扩展性
  • 高吞吐量
  • Pulsar Proxy
  • 函数

架构

Pulsar 应用分层构造,将存储机制与 broker 隔离开来。此体系结构为 Pulsar 提供以下益处:

  • 独立扩大 broker
  • 独立扩大存储(Bookies)
  • 更容易容器化 Zookeeper, Broker and Bookies
  • ZooKeeper 提供集群的配置和状态存储

在 Pulsar 集群中,一个或多个代理解决和负载平衡来自生产者的传入音讯,将音讯分派给消费者,与 Pulsar 配置存储通信以解决各种协调工作,将音讯存储在 BookKeeper 实例(又名 bookies)中,依赖特定于集群的 ZooKeeper 集群工作等等。

  • 由一个或多个 bookie 组成的 BookKeeper 集群解决音讯的长久存储。
  • 特定于该集群的 ZooKeeper 集群解决 Pulsar 集群之间的协调工作。

更多对于 Pulsar 的架构介绍请参阅:https://pulsar.apache.org/doc…

四种订阅模式

Pulsar 中有四种订阅模式:exclusive、shared、failover 和 key\_shared。这些模式如下图所示。

具体介绍参阅:https://pulsar.apache.org/doc…

性能优于 Kafka

Pulsar 体现最出色的就是性能,Pulsar 的速度比 Kafka 快得多,与 Kafka 相比,Pulsar 的速度晋升了 2.5 倍,提早升高了 40%。

数据起源:https://streaml.io/pdf/Gigaom…

注:比照是针对 1 个分区的 1 个主题,其中蕴含 100 字节音讯,Pulsar 每秒可发送 220,000+ 条音讯。

装置

二进制版本装置 Pulsar
# 下载官网二进制包
[root@centos7 ~]# wget https://archive.apache.org/dist/pulsar/pulsar-2.8.0/apache-pulsar-2.8.0-bin.tar.gz
#解压
[root@centos7 ~]# tar zxf apache-pulsar-2.8.0-bin.tar.gz
[root@centos7 ~]# cd apache-pulsar-2.8.0
[root@centos7 apache-pulsar-2.8.0]# ll
total 72
drwxr-xr-x 3 root root   225 Jan 22  2020 bin
drwxr-xr-x 5 root root  4096 Jan 22  2020 conf
drwxr-xr-x 3 root root   132 Jul  6 11:47 examples
drwxr-xr-x 4 root root    66 Jul  6 11:47 instances
drwxr-xr-x 3 root root 16384 Jul  6 11:47 lib
-rw-r--r-- 1 root root 31639 Jan 22  2020 LICENSE
drwxr-xr-x 2 root root  4096 Jan 22  2020 licenses
-rw-r--r-- 1 root root  6612 Jan 22  2020 NOTICE
-rw-r--r-- 1 root root  1269 Jan 22  2020 README
#bin 目录下就有间接启动的命令 
Docker 装置(重点介绍)
[root@centos7 ~]# docker run -it \
 -p 6650:6650 \
 -p 8080:8080 \
 --mount source=pulsardata,target=/pulsar/data \
 --mount source=pulsarconf,target=/pulsar/conf \
 apachepulsar/pulsar:2.8.0 \
 bin/pulsar standalone

http 协定拜访应用 8080 端口,pulsar 协定(Java、Python 等客户端)拜访应用 6650 端口。

官网提供的可视化工具 Pulsar Manager,能够对多个 Pulsar 进行可视化治理。https://pulsar.apache.org/doc…

[root@centos7 ~]# docker pull apachepulsar/pulsar-manager:v0.2.0

[root@centos7 ~]# docker run -it \
   -p 9527:9527 -p 7750:7750 \
   -e SPRING_CONFIGURATION_FILE=/pulsar-manager/pulsar-manager/application.properties \
   apachepulsar/pulsar-manager:v0.2.0

设置管理员用户与明码

[root@centos7 ~]# CSRF_TOKEN=$(curl http://localhost:7750/pulsar-manager/csrf-token)
curl \
  -H 'X-XSRF-TOKEN: $CSRF_TOKEN' \
  -H 'Cookie: XSRF-TOKEN=$CSRF_TOKEN;' \
  -H "Content-Type: application/json" \
  -X PUT http://localhost:7750/pulsar-manager/users/superuser \
  -d '{"name":"admin","password":"admin123","description":"test","email":"mingongge@test.org"}'

{"message":"Add super user success, please login"}

浏览器间接输出 http://server_ip:9527 登录如下

输出刚刚创立的用户与明码,配置管理的服务端

列表

Toptic 列表

Toptic 详细信息

客户端配置

Java 客户端

上面是一个应用共享订阅的 Java 消费者配置示例:

import org.apache.pulsar.client.api.Consumer;
import org.apache.pulsar.client.api.PulsarClient;
import org.apache.pulsar.client.api.SubscriptionType;

String SERVICE_URL = "pulsar://localhost:6650";
String TOPIC = "persistent://public/default/mq-topic-1";
String subscription = "sub-1";

PulsarClient client = PulsarClient.builder()
        .serviceUrl(SERVICE_URL)
        .build();

Consumer consumer = client.newConsumer()
        .topic(TOPIC)
        .subscriptionName(subscription)
        .subscriptionType(SubscriptionType.Shared)
        // If you'd like to restrict the receiver queue size
        .receiverQueueSize(10)
        .subscribe();
Python 客户端

上面是一个应用共享订阅的 Python 消费者配置示例:

from pulsar import Client, ConsumerType

SERVICE_URL = "pulsar://localhost:6650"
TOPIC = "persistent://public/default/mq-topic-1"
SUBSCRIPTION = "sub-1"

client = Client(SERVICE_URL)
consumer = client.subscribe(
    TOPIC,
    SUBSCRIPTION,
    # If you'd like to restrict the receiver queue size
    receiver_queue_size=10,
    consumer_type=ConsumerType.Shared)
C++ 客户端

上面是一个应用共享订阅的 C++ 消费者配置示例:

#include <pulsar/Client.h>

std::string serviceUrl = "pulsar://localhost:6650";
std::string topic = "persistent://public/defaultmq-topic-1";
std::string subscription = "sub-1";

Client client(serviceUrl);

ConsumerConfiguration consumerConfig;
consumerConfig.setConsumerType(ConsumerType.ConsumerShared);
// If you'd like to restrict the receiver queue size
consumerConfig.setReceiverQueueSize(10);

Consumer consumer;

Result result = client.subscribe(topic, subscription, consumerConfig, consumer);

更多配置及操作指南,官网的文档写的都很分明,官网文档:https://pulsar.apache.org/docs/

总结

Plusar 作为下一代分布式音讯队列,领有十分多吸引人的个性,也补救了一些其余竞品的短板,例如地区复制、多租户、扩展性、读写隔离等等。

正文完
 0