View Source Elsa.Producer (Elsa.fi v2.2.0)

Defines functions to write messages to topics based on either a list of endpoints or a named client. All produce functions support the following options:

  • An existing named client process to handle the request can be specified by the keyword option connection:.
  • If no partition is supplied, the first (zero) partition is chosen.
  • Value may be a single message or a list of messages.
  • If a list of messages is supplied as the value, the key is defaulted to an empty string binary.
  • Partition can be specified by the keyword option partition: and an integer corresponding to a specific partition, or the keyword option partitioner: and the atoms :md5 or :random. The atoms correspond to partitioner functions that will uniformely select a random partition from the total available topic partitions or assign an integer based on an md5 hash of the messages.

Link to this section Summary

Types

Elsa messages can take a number of different forms, including a single binary, a key/value tuple, a map including :key and :value keys, or a list of iolists. Because Elsa supports both single messages and lists of messages and because an iolist is indistinguishable from a list of other message types from the perspective of the compiler, even single-message iolists must be wrapped in an additional list in order to be produced. Internally, all messages are converted to a map before being encoded and produced.

Functions

Write the supplied message(s) to the desired topic/partition via an endpoint list and optional named client. If no client is supplied, the default named client is chosen.

Link to this section Types

@type message() :: {iodata(), iodata()} | binary() | %{key: iodata(), value: iodata()}

Elsa messages can take a number of different forms, including a single binary, a key/value tuple, a map including :key and :value keys, or a list of iolists. Because Elsa supports both single messages and lists of messages and because an iolist is indistinguishable from a list of other message types from the perspective of the compiler, even single-message iolists must be wrapped in an additional list in order to be produced. Internally, all messages are converted to a map before being encoded and produced.

Link to this section Functions

Link to this function

produce(endpoints_or_connection, topic, messages, opts \\ [])

View Source
@spec produce(
  Elsa.endpoints() | Elsa.connection(),
  Elsa.topic(),
  message() | [message()] | [iolist()],
  keyword()
) ::
  :ok | {:error, term()} | {:error, String.t(), [Elsa.Message.elsa_message()]}

Write the supplied message(s) to the desired topic/partition via an endpoint list and optional named client. If no client is supplied, the default named client is chosen.