Work with clients
After setting up your client library and creating a client object, you can explore more to start working with your client.
Create a client with multiple advertised listeners
To ensure clients in both internal and external networks can connect to a Pulsar cluster, Pulsar introduces advertisedListeners.
The following example creates a Python client using multiple advertised listeners:
- Java
- C++
- Python
PulsarClient client = PulsarClient.builder()
.serviceUrl("pulsar://xxxx:6650")
.listenerName("external")
.build();
ClientConfiguration clientConfiguration;
clientConfiguration.setListenerName("external");
Client client("pulsar://xxxx:6650", clientConfiguration);
import pulsar
client = pulsar.Client('pulsar://localhost:6650', listener_name='external')
Set memory limits
You can use memory limits parameters to control the total client memory usage, the producers and consumers under this client will compete for the memory assigned. For implementation details, see PIP 74: Pulsar client memory limits.
- Java
- Go
PulsarClient client = PulsarClient.builder()
.serviceUrl("pulsar://xxxx:6650")
.memoryLimit(64, SizeUnit.MEGA_BYTES)
.build();
client, err := pulsar.NewClient(pulsar.ClientOptions{
URL: "pulsar://xxxx:6650",
MemoryLimitBytes: 64 * 1024 * 1024, // Unit: byte
})