Conduit v0.1.1 Conduit.Message

The Conduit message.

This module defines a Conduit.Message struct and the main functions for working with Conduit messages.

Note this struct is used for sending and receiving messages from a message queue.

Public fields

These fields are for you to use in your application. The values in meta, headers, and status may have special meaning based on the adapter you use. See your adapters documention to understand how to use them correctly.

  • meta - Information applicable to every message stored as a map.
  • headers - Information applicable to a specific message stored as a keyword list.
  • body - The contents of the message.
  • status - The operation to perform on the message. This only applies to messages that are being received.

Private fields

These fields are reserved for library/framework usage.

  • private - shared library data as a map

Summary

Functions

Assigs the status of the message as acknowledged. This will be used to signal to the message queue that processing the message was successful and can be discarded

Assigns a named value to the message

Retrieves a named value from the message

Returns a header from the message specified by key

Gets a meta property from the message

Retrieves a named value from the message. This is intended for libraries and framework use

Assigs the status of the message to a negative acknowledged. This will be used to signal to the message queue that processing the message was not successful

Assigns the content of the message

Assigns the destination of the message

Assigns a header for the message specified by key

Assigns a meta property to the message

Assigns a meta property to the message if not already set

Assigns a named value to the message. This is intended for libraries and framework use

Assigns the source of the message

Types

assigns()
assigns :: %{optional(atom) => any}
body()
body :: any
destination()
destination :: binary
headers()
meta()
meta :: %{optional(atom) => any}
private()
private :: %{optional(atom) => any}
source()
source :: binary
status()
status :: :ack | :nack
t()
t :: %Conduit.Message{assigns: assigns, body: body, destination: destination, headers: headers, meta: meta, private: private, source: source, status: status}

Functions

Assigs the status of the message as acknowledged. This will be used to signal to the message queue that processing the message was successful and can be discarded.

Examples

iex> message = %Conduit.Message{}
iex> message = Conduit.Message.ack(message)
iex> message.status
:ack
assign(message, key, value)
assign(Conduit.Message.t, atom, any) :: Conduit.Message.t

Assigns a named value to the message.

Examples

iex> import Conduit.Message
iex> message = assign(%Conduit.Message{}, :user_id, 1)
iex> assigns(message, :user_id)
1
assigns(message, key)

Retrieves a named value from the message.

Examples

iex> import Conduit.Message
iex> message = assign(%Conduit.Message{}, :user_id, 1)
iex> assigns(message, :user_id)
1
get_header(message, key)
get_header(Conduit.Message.t, atom | binary) :: any

Returns a header from the message specified by key.

Examples

iex> import Conduit.Message
iex> message = put_header(%Conduit.Message{}, :retries, 1)
iex> Conduit.Message.get_header(message, :retries)
1
get_meta(message, key)
get_meta(Conduit.Message.t, term) :: any

Gets a meta property from the message.

Examples

iex> import Conduit.Message
iex> message = put_meta(%Conduit.Message{}, :content_type, "application/json")
iex> get_meta(message, :content_type)
"application/json"
get_private(message, key)
get_private(Conduit.Message.t, term) :: Conduit.Message.t

Retrieves a named value from the message. This is intended for libraries and framework use.

Examples

iex> import Conduit.Message
iex> message = Conduit.Message.put_private(%Conduit.Message{}, :message_id, 1)
iex> get_private(message, :message_id)
1
nack(message)

Assigs the status of the message to a negative acknowledged. This will be used to signal to the message queue that processing the message was not successful.

Examples

iex> message = %Conduit.Message{}
iex> message = Conduit.Message.nack(message)
iex> message.status
:nack
put_body(message, body)

Assigns the content of the message.

Examples

iex> message = %Conduit.Message{}
iex> message = Conduit.Message.put_body(message, "hi")
iex> message.body
"hi"
put_destination(message, destination)

Assigns the destination of the message.

Examples

iex> message = %Conduit.Message{}
iex> message = Conduit.Message.put_destination(message, "my.queue")
iex> message.destination
"my.queue"
put_header(message, key, value)
put_header(Conduit.Message.t, atom, any) :: Conduit.Message.t

Assigns a header for the message specified by key.

Examples

iex> import Conduit.Message
iex> message = put_header(%Conduit.Message{}, :retries, 1)
iex> Conduit.Message.get_header(message, :retries)
1
put_meta(message, key, value)
put_meta(Conduit.Message.t, atom, any) :: Conduit.Message.t

Assigns a meta property to the message.

Examples

iex> import Conduit.Message
iex> message = put_meta(%Conduit.Message{}, :content_type, "application/json")
iex> get_meta(message, :content_type)
"application/json"
put_new_meta(message, key, value)
put_new_meta(Conduit.Message.t, atom, any) :: Conduit.Message.t

Assigns a meta property to the message if not already set.

Examples

iex> import Conduit.Message
iex> message =
iex>   %Conduit.Message{}
iex>   |> put_new_meta(:content_type, "application/json")
iex>   |> put_new_meta(:content_type, "application/xml")
iex> get_meta(message, :content_type)
"application/json"
put_private(message, key, value)
put_private(Conduit.Message.t, atom, any) :: Conduit.Message.t

Assigns a named value to the message. This is intended for libraries and framework use.

Examples

iex> import Conduit.Message
iex> message = Conduit.Message.put_private(%Conduit.Message{}, :message_id, 1)
iex> get_private(message, :message_id)
1
put_source(message, source)

Assigns the source of the message.

Examples

iex> message = %Conduit.Message{}
iex> message = Conduit.Message.put_source(message, "my.queue")
iex> message.source
"my.queue"