proxy的作用

The Pulsar proxy is an optional gateway that you can run in front of the brokers in a Pulsar cluster. We recommend running a Pulsar proxy in cases when direction connections between clients and Pulsar brokers are either infeasible, undesirable, or both, for example when running Pulsar in a cloud environment or on Kubernetes or an analogous platform.

根据官方的描述, proxy可以更好的解耦client和broker.

proxy impl

  1. 主要的类:
  • ProxyConnection: 处理proxy server的请求,
  • ProxyConnectionPool: 后端broker client的连接池, LookupProxyHandler频繁使用
  • LookupProxyHandler: 负责 namespace topic的查找工作
  • DirectProxyHandler: broker client的处理器, 内部类 ProxyBackendHandler 负责协议相关
  • BrokerDiscoveryProvider: 负责从 zk上获取 topic metadata
  1. 消息收发流程

总结如下图:

Netty Server <-> ProxyConnection <-> DirectProxyHandler <-> Broker Server

总结

不足

  1. ProxyConnection 和 ProxyConnectionPool 容易混淆, 其实, ProxyConnectionPool 并不是 ProxyConnection 的 pool.