DdDataStreams.Carrier behaviour (DD Data Streams v0.3.0)

Copy Markdown View Source

Broker-specific carriers for the pathway header.

A carrier is the part of an inbound or outbound message that holds the pathway header: a flat attribute map or header list for Pub/Sub, Kafka and RabbitMQ, or the _datadog JSON message attribute for SQS. Flat and Sqs implement the behaviour; adapter/1 selects one from the carrier's shape, so DdDataStreams.Checkpoints stays free of broker conditionals.

Summary

Functions

Selects the adapter that understands carrier's shape.

Reads the pathway out of carrier under key, like get/2, but tells a header that is absent from one that is present and cannot be read.

Reads the pathway out of carrier under key, using the adapter selected by its shape.

Writes pathway into carrier under key, using the adapter selected by its shape.

Measures the size in bytes of the carrier entries.

Callbacks

fetch(carrier, key)

@callback fetch(carrier :: term(), key :: String.t()) ::
  {:ok, DdDataStreams.Pathway.t()} | :absent | {:error, :malformed}

get(carrier, key)

@callback get(carrier :: term(), key :: String.t()) :: DdDataStreams.Pathway.t() | nil

put(carrier, pathway, key)

@callback put(carrier :: term(), pathway :: DdDataStreams.Pathway.t(), key :: String.t()) ::
  term()

size(carrier)

@callback size(carrier :: term()) :: non_neg_integer()

Functions

adapter(carrier)

@spec adapter(term()) :: module()

Selects the adapter that understands carrier's shape.

fetch(carrier, key)

@spec fetch(term(), String.t()) ::
  {:ok, DdDataStreams.Pathway.t()} | :absent | {:error, :malformed}

Reads the pathway out of carrier under key, like get/2, but tells a header that is absent from one that is present and cannot be read.

get(carrier, key)

@spec get(term(), String.t()) :: DdDataStreams.Pathway.t() | nil

Reads the pathway out of carrier under key, using the adapter selected by its shape.

put(carrier, pathway)

@spec put(term(), DdDataStreams.Pathway.t()) :: term()

put(carrier, pathway, key)

@spec put(term(), DdDataStreams.Pathway.t(), String.t()) :: term()

Writes pathway into carrier under key, using the adapter selected by its shape.

size(carrier)

@spec size(term()) :: non_neg_integer()

Measures the size in bytes of the carrier entries.