Routemaster Client v0.3.0 Routemaster.Director View Source
The Director module provides functions to interact with the Routemaster event bus REST API. It’s a client and each function will perform an authenticated HTTP request to the even bus server.
Link to this section Summary
Functions
Retrieves the subscribers currently known to the server and their metadata
Retrieves the current topics from the server and their metadata.
It performs a GET /topics
request
Deletes an owned topic from the bus server
Returns a single topic, by name. It will fetch all topics over the network and filter them locally
Creates a subscription on the bus server. Arguments
Unsubscribes this consumer from the provided topic.
Returns :ok
on success and {:error, 404}
if either the topic
doesn’t exist or we are not subscribed to it
Unsubscribes this consumer from all current topics
Link to this section Types
Link to this section Functions
all_subscribers() :: {:ok, [map()]} | {:error, http_status()}
Retrieves the subscribers currently known to the server and their metadata.
all_topics() :: {:ok, [map()]} | {:error, http_status()}
Retrieves the current topics from the server and their metadata.
It performs a GET /topics
request.
Examples
case Director.all_topics() do
{:ok, topics} ->
"The bus is handling #{length topics} topics"
{:error, status} ->
"Couldn't get topics, HTTP error #{status}"
end
delete_topic(binary()) :: :ok | {:error, http_status()}
Deletes an owned topic from the bus server.
get_topic(binary()) :: {:ok, map()} | {:error, http_status()}
Returns a single topic, by name. It will fetch all topics over the network and filter them locally.
subscribe([binary()], Keyword.t()) :: :ok | {:error, http_status()}
Creates a subscription on the bus server. Arguments:
topics
: a list of valid topic names. This must always be the complete set of topics this subscriber wants to receive, because any missing previously-submitted topics will see their subscriptions deleted.options, an optional keyword list with:
max
: How many events can be batched together on delivery. The server will never deliver batches larger than this number. Default: 100.timeout
: How long the server can wait before delivering the events (ms). Once this timeout is reached, a batch is delivered even if incomplete. This indirectly controls the max latency of event delivery. Default: 500ms.
Examples
Subscribe to two topics, and dispatch events within 2 seconds, in batches no larger than 300 events:
Director.subscribe(~w(users orders), max: 300, timeout: 2_000)
unsubscribe(binary()) :: :ok | {:error, http_status()}
Unsubscribes this consumer from the provided topic.
Returns :ok
on success and {:error, 404}
if either the topic
doesn’t exist or we are not subscribed to it.
unsubscribe_all() :: :ok | {:error, http_status()}
Unsubscribes this consumer from all current topics.