Pulsar proxy

Pulsar proxy 是可选网关。 当客户端和 broker 之间不能直连或者不方便直连时,可以使用 Pulsar Proxy。 例如,当 Pulsar 运行在云环境、 Kubernetes 环境以及类似的平台时,可能不方便直连或者不能直连所有 broker,此时你就可以使用 Pulsar Proxy。

配置 Proxy

使用 proxy 之前,需要为 proxy 配置集群内 broker 的地址。 可以配置 proxy 直接连到服务发现(比如ZooKeeper),也可以在配置中指定 broker URL。

使用服务发现

Pulsar uses ZooKeeper for service discovery. To connect the proxy to ZooKeeper, specify the following in conf/proxy.conf.

  1. zookeeperServers=zk-0,zk-1,zk-2
  2. configurationStoreServers=zk-0:2184,zk-remote:2184

要使用服务发现,必须开启网络 ACL,proxy 通过端口 2181(本地 ZooKeeper 集群)或 2184(配置存储集群)连接到 ZooKeeper 节点。

However, it is not secure to use service discovery. Because if the network ACL is open, when someone compromises a proxy, they have full access to ZooKeeper.

使用 broker URL

通过指定 URL 连接到 broker 更安全。

Proxy 拥有访问 ZooKeeper 的权限才可以授权。如果通过 broker URL 连接到 Broker,则必须禁用 proxy 级别的授权。 Brokers still authorize requests after the proxy forwards them.

您可以在 conf/proxy.conf中配置broker URLs,如下所示。

  1. brokerServiceURL=pulsar://brokers.example.com:6650
  2. brokerWebServiceURL=http://brokers.example.com:8080
  3. functionWorkerWebServiceURL=http://function-workers.example.com:8080

若使用 TLS,则可以使用以下方式配置 broker URL:

  1. brokerServiceURLTLS=pulsar+ssl://brokers.example.com:6651
  2. brokerWebServiceURLTLS=https://brokers.example.com:8443
  3. functionWorkerWebServiceURL=https://function-workers.example.com:8443

URL 中的域名可以是映射到多个 broker 的 DNS 域名,也可以是虚拟 IP。由于有多个 broker IP,即使集群中的单个 broker 不可用,proxy 和集群也不会断开连接。

The ports to connect to the brokers (6650 and 8080, or in the case of TLS, 6651 and 8443) should be open in the network ACLs.

注意:如果不使用 Pulsar Functions,则不需要配置 functionWorkerWebServiceURL

启动 Proxy

To start the proxy:

  1. $ cd /path/to/pulsar/directory
  2. $ bin/pulsar proxy

一个集群可以运行多个 Pulsar proxy 实例。

停止 Proxy

Pulsar proxy runs in the foreground by default. To stop the proxy, simply stop the process in which the proxy is running.

Proxy frontends

你可以在 Pulsar proxy 前端部署负载均衡软件,比如 HAProxy 负载均衡器。

Pulsar 客户端连接 Proxy

Once your Pulsar proxy is up and running, preferably behind a load-distributing frontend, clients can connect to the proxy via whichever address that the frontend uses. 例如,地址是 DNS 地址 pulsar.cluster.default,则客户端连接的 URL 是 pulsar://pulsar.cluster.default:6650

了解更多关于 Pulsar proxy 的信息,参阅 Pulsar proxy