Interface ServiceUrlProvider
- All Superinterfaces:
AutoCloseable
This allows applications to retrieve the service URL from an external configuration provider and, more importantly, to force the Pulsar client to reconnect if the service URL has been changed.
Each provider instance is tied to the lifecycle of one PulsarClient instance. The client
initializes the provider when the client is created and closes the provider when the owning client is
closed. Applications that create multiple Pulsar clients should create a separate provider instance
for each client instead of sharing one provider.
It can be passed with ClientBuilder.serviceUrlProvider(ServiceUrlProvider)
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidclose()Close the resource that the provider allocated.Get the current service URL the Pulsar client should connect to.voidinitialize(PulsarClient client) Initialize the service url provider with Pulsar client instance.
-
Method Details
-
initialize
Initialize the service url provider with Pulsar client instance.This can be used by the provider to force the Pulsar client to reconnect whenever the service url might have changed. See
PulsarClient.updateServiceUrl(String).This method is invoked by the Pulsar client and is expected to be called once for a provider instance. Implementations may reject repeated initialization.
- Parameters:
client- created pulsar client.
-
getServiceUrl
String getServiceUrl()Get the current service URL the Pulsar client should connect to.- Returns:
- the pulsar service url.
-
close
Close the resource that the provider allocated. The owning Pulsar client invokes this method when it is closed.- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-