A client represents an isolated Pulsar connection context.
Each client maintains:
- Separate broker connections
- Independent consumer/producer registries
- Isolated broker configuration
Usage
Single Client (Implicit)
When using Pulsar.start/1, a default client is automatically created:
# config.exs
config :pulsar,
host: "pulsar://localhost:6650",
consumers: [...]
# Uses implicit :default client
{:ok, consumer} = Pulsar.start_consumer(topic, subscription, MyCallback)Multiple Clients (Explicit)
You can start multiple clients in your supervision tree:
children = [
{Pulsar.Client, name: :analytics_client, host: "pulsar://analytics:6650"},
{Pulsar.Client, name: :events_client, host: "pulsar://events:6650"}
]
# Explicit client usage
{:ok, consumer} = Pulsar.start_consumer(
topic, subscription, MyCallback,
client: :analytics_client
)
Summary
Functions
Returns a specification to start this module under a supervisor.
Looks up an existing broker connection by broker URL.
Returns a random broker process from the specified client's broker supervisor.
Starts a broker connection.
Starts a client with the given options.
Stops a client and all its resources gracefully.
Stops a broker connection by broker URL.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
Looks up an existing broker connection by broker URL.
Returns {:ok, broker_pid} if found, {:error, :not_found} otherwise.
Returns a random broker process from the specified client's broker supervisor.
Defaults to the :default client if no client is specified.
This is useful for operations that need any broker from a client (e.g., service discovery).
Starts a broker connection.
If a broker for the given URL already exists, returns the existing broker. Otherwise, starts a new broker connection with the provided options.
Returns {:ok, broker_pid} if successful, {:error, reason} otherwise.
Starts a client with the given options.
Options
:name- Required. The name of the client (atom):host- Required. Bootstrap broker URL:auth- Optional. Authentication configuration:conn_timeout- Optional. Connection timeout (default: 5000):socket_opts- Optional. Socket options
Stops a client and all its resources gracefully.
This stops all producers, consumers, brokers, and the client supervisor.
Options
:timeout- Maximum time to wait for shutdown (default: 5000ms)
Examples
Pulsar.Client.stop(:my_client)
Stops a broker connection by broker URL.