Conduit v0.4.0 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 user_id, correlation_id, message_id, content_type, content_encoding, created_by, created_at, headers, and status may have special meaning based on the adapter you use. See your adapters documention to understand how to use them correctly.

  • source - For incoming messages, this will be set to the queue the message was consumed from.
  • destination - For outgoing messages, this will be set to the destination queue (or routing key) it is published to.
  • user_id - An ID representing which user the message pertains to.
  • correlation_id - An ID for a chain of messages, where the current message is one in that chain.
  • message_id - A unique ID for this message.
  • content_type - The media type of the message body.
  • content_encoding - The encoding of the message body.
  • created_by - The name of the app that created the message.
  • created_at - A timestamp or epoch representing when the message was created.
  • 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

Deletes a header from the message specified by key

Returns a header from the message specified by key

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 a content_encoding to the message

Assigns a content_type to the message

Assigns a correlation_id to the message

Assigns a created_at to the message

Assigns a created_by to the message

Assigns the destination of the message

Assigns a header for the message specified by key

Assigns a message_id to the message

Assigns a correlation_id to the message when one isn’t set already

Assigns a message_id to the message when one isn’t set already

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

Assigns the source of the message

Assigns a user_id to the message

Types

assigns()
assigns :: %{optional(atom) => any}
body()
body :: any
content_encoding()
content_type()
correlation_id()
correlation_id :: binary | integer | nil
created_at()
created_at :: String.t | integer | nil
created_by()
created_by :: binary | nil
destination()
destination :: binary | nil
headers()
headers :: %{optional(String.t) => any}
message_id()
message_id :: binary | integer | nil
private()
private :: %{optional(atom) => any}
source()
source :: binary | nil
status()
status :: :ack | :nack
t()
t :: %Conduit.Message{assigns: assigns, body: body, content_encoding: content_encoding, content_type: content_type, correlation_id: correlation_id, created_at: created_at, created_by: created_by, destination: destination, headers: headers, message_id: message_id, private: private, source: source, status: status, user_id: user_id}
user_id()
user_id :: binary | integer | nil

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> import Conduit.Message
iex> message = ack(%Conduit.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
delete_header(message, key)

Deletes a header from the message specified by key.

Examples

iex> import Conduit.Message
iex> message = put_header(%Conduit.Message{}, "retries", 1)
iex> message = delete_header(message, "retries")
iex> get_header(message, "retries")
nil
get_header(message, key)
get_header(Conduit.Message.t, String.t) :: any

Returns a header from the message specified by key.

Examples

iex> import Conduit.Message
iex> message = put_header(%Conduit.Message{}, "retries", 1)
iex> get_header(message, "retries")
1
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 = 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> import Conduit.Message
iex> message = nack(%Conduit.Message{})
iex> message.status
:nack
put_body(message, body)

Assigns the content of the message.

Examples

iex> import Conduit.Message
iex> message = put_body(%Conduit.Message{}, "hi")
iex> message.body
"hi"
put_content_encoding(message, content_encoding)

Assigns a content_encoding to the message.

Examples

iex> import Conduit.Message
iex> message = put_content_encoding(%Conduit.Message{}, 1)
iex> message.content_encoding
1
put_content_type(message, content_type)

Assigns a content_type to the message.

Examples

iex> import Conduit.Message
iex> message = put_content_type(%Conduit.Message{}, 1)
iex> message.content_type
1
put_correlation_id(message, correlation_id)

Assigns a correlation_id to the message.

Examples

iex> import Conduit.Message
iex> message = put_correlation_id(%Conduit.Message{}, 1)
iex> message.correlation_id
1
put_created_at(message, created_at)

Assigns a created_at to the message.

Examples

iex> import Conduit.Message
iex> message = put_created_at(%Conduit.Message{}, 1)
iex> message.created_at
1
put_created_by(message, created_by)

Assigns a created_by to the message.

Examples

iex> import Conduit.Message
iex> message = put_created_by(%Conduit.Message{}, 1)
iex> message.created_by
1
put_destination(message, destination)

Assigns the destination of the message.

Examples

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

Assigns a header for the message specified by key.

Examples

iex> import Conduit.Message
iex> message = put_header(%Conduit.Message{}, "retries", 1)
iex> get_header(message, "retries")
1
put_message_id(message, message_id)

Assigns a message_id to the message.

Examples

iex> import Conduit.Message
iex> message = put_message_id(%Conduit.Message{}, 1)
iex> message.message_id
1
put_new_correlation_id(message, correlation_id)
put_new_correlation_id(Conduit.Message.t, correlation_id) :: Conduit.Message.t

Assigns a correlation_id to the message when one isn’t set already.

Examples

iex> import Conduit.Message
iex> message = put_new_correlation_id(%Conduit.Message{}, 1)
iex> message = put_new_correlation_id(message, 2)
iex> message.correlation_id
1
put_new_message_id(message, message_id)

Assigns a message_id to the message when one isn’t set already.

Examples

iex> import Conduit.Message
iex> message = put_new_message_id(%Conduit.Message{}, 1)
iex> message = put_new_message_id(message, 2)
iex> message.message_id
1
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 = 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> import Conduit.Message
iex> message = put_source(%Conduit.Message{}, "my.queue")
iex> message.source
"my.queue"
put_user_id(message, user_id)

Assigns a user_id to the message.

Examples

iex> import Conduit.Message
iex> message = put_user_id(%Conduit.Message{}, 1)
iex> message.user_id
1