View Source Elsa.Util (Elsa.fi v3.1.0)

Provides functions for simplifying first-class interactions (consuming and producing) such as connecting to a cluster and establishing a persistent client process for interacting with a cluster.

Link to this section Summary

Functions

Process messages into chunks of size up to the size specified by the calling function in bytes, and determined by the function argument. If no chunk size is specified the default maximum size a chunk will be is approximately 1 megabyte. If no sizing function is provided to construct the appropriately sized chunks, the internal function based on Kernel.byte_size/1 is used.

Determines if client pid is alive

Retrieve the api version of the desired operation supported by the connected cluster.

Return the number of partitions for a given topic. Bypasses the need for a persistent client for lighter weight interactions from one-off calls.

Convert supplied cluster endpoints from common keyword list format to brod-compatible tuple.

Create a named client connection process for managing interactions with the connected cluster.

Retrieves the pid of a brod client process if it exists and executes the given function against the client.

Wrap establishing a connection to a cluster for performing an operation.

Retrieves the appropriate registry for the given value and validates it exists. Executes the function with the registry name if it successfully locates one.

Link to this section Functions

Link to this function

chunk_by_byte_size(collection, chunk_byte_size \\ 900_000, byte_size_function \\ &get_byte_size/1)

View Source
@spec chunk_by_byte_size(term(), integer(), (... -> any())) :: [term()]

Process messages into chunks of size up to the size specified by the calling function in bytes, and determined by the function argument. If no chunk size is specified the default maximum size a chunk will be is approximately 1 megabyte. If no sizing function is provided to construct the appropriately sized chunks, the internal function based on Kernel.byte_size/1 is used.

@spec client?(pid() | atom()) :: boolean()

Determines if client pid is alive

Link to this function

get_api_version(connection, api)

View Source
@spec get_api_version(pid(), atom()) :: non_neg_integer()

Retrieve the api version of the desired operation supported by the connected cluster.

Link to this function

get_endpoints(connection)

View Source
@spec get_endpoints(Elsa.connection()) :: {:ok, list()} | {:error, any()}
Link to this function

partition_count(connection_or_endpoints, topic, retry_config \\ RetryConfig.no_retry())

View Source
@spec partition_count(
  list() | Elsa.connection() | pid(),
  String.t(),
  Elsa.RetryConfig.t()
) ::
  {:ok, integer()} | {:error, any()}

Return the number of partitions for a given topic. Bypasses the need for a persistent client for lighter weight interactions from one-off calls.

Note that when passing in a connection/pid for the first argument, the underlying brod calls will cache the results, including the non-existence of a topic! So if this function is being used to wait for a recently created topic to be fully online, pass in a list of endpoints rather than a connection. For convenience, the get_endpoints/1 is provided to extract the endpoints from a connection.

Link to this function

partition_count!(connection_or_endpoints, topic, retry_config \\ RetryConfig.no_retry())

View Source
@spec partition_count!(
  list() | Elsa.connection() | pid(),
  String.t(),
  Elsa.RetryConfig.t()
) ::
  integer()

Like partition_count/3 but returns only the partition count, and raises on failure

Link to this function

reformat_endpoints(endpoints)

View Source
@spec reformat_endpoints(keyword()) :: [{charlist(), integer()}]

Convert supplied cluster endpoints from common keyword list format to brod-compatible tuple.

Link to this function

start_client(endpoints, name, config \\ [])

View Source

Create a named client connection process for managing interactions with the connected cluster.

Link to this function

with_client(registry, function)

View Source
@spec with_client(atom(), (pid() -> term())) :: term() | {:error, String.t()}

Retrieves the pid of a brod client process if it exists and executes the given function against the client.

Link to this function

with_connection(endpoints, type \\ :any, fun)

View Source
@spec with_connection(Elsa.endpoints(), atom(), (... -> any())) :: term()

Wrap establishing a connection to a cluster for performing an operation.

Link to this function

with_registry(connection, function)

View Source
@spec with_registry(atom() | String.t(), (atom() -> term())) ::
  term() | {:error, String.t()}

Retrieves the appropriate registry for the given value and validates it exists. Executes the function with the registry name if it successfully locates one.