When a Pulsar cluster is deployed in the production environment, it may require to expose multiple advertised addresses for the broker. For example, when you deploy a Pulsar cluster in Kubernetes and want other clients, which are not in the same Kubernetes cluster, to connect to the Pulsar cluster, you need to assign a broker URL to external clients. But clients in the same Kubernetes cluster can still connect to the Pulsar cluster through the internal network of Kubernetes.
To ensure clients in both internal and external networks can connect to a Pulsar cluster, Pulsar introduces
internalListenerName configuration options into the broker configuration file to ensure that the broker supports exposing multiple advertised listeners and support the separation of internal and external network traffic.
advertisedListenersis used to specify multiple advertised listeners. The broker uses the listener as the broker identifier in the load manager and the bundle owner data. The
advertisedListenersis formatted as
<listener_name>:pulsar://<host>:<port>, <listener_name>:pulsar+ssl://<host>:<port>. You can set up the
internalListenerNameis used to specify the internal service URL that the broker uses. You can specify the
internalListenerNameby choosing one of the
advertisedListeners. The broker uses the listener name of the first advertised listener as the
After setting up the
advertisedListeners, clients can choose one of the listeners as the service URL to create a connection to the broker as long as the network is accessible. However, if the client creates producers or consumers on a topic, the client must send a lookup request to the broker for getting the owner broker, then connect to the owner broker to publish messages or consume messages. Therefore, You must allow the client to get the corresponding service URL with the same advertised listener name as the one used by the client. This helps keep the client side simple and secure.
Use multiple advertised listeners
This example shows how a Pulsar client uses multiple advertised listeners.
- Configure multiple advertised listeners in the broker configuration file.
- Specify the listener name for the client.
PulsarClient client = PulsarClient.builder()