off_broadway_mqtt v0.1.0 OffBroadway.MQTT.Config View Source

Defines a data structure for configuring this library.

Config options

  • dequeue_interval - The interval used by the producer to timout polls to the queue process. Defaults to 5000.
  • client_id_prefix - The value is used to prefix the randomly generated client ids by the MQTT client. Defaults to "obmp". Keep in mind that some brokers limit the size of client_id size to 23 bytes!
  • server_opts - See the "Server options" section for details.
  • telemetry_prefix - Sets the prefix for any telemery events. Defaults to :off_broadway_mqtt.

Server options

All options given with the server_opts option are passed to Tortoise when starting the connection process. The following options can be given:

  • host - The host the MQTT client uses by default. Defaults to 'localhost'.
  • port - The port the MQTT client uses by default. Defaults to 1883.
  • transport - The protocol the MQTT client uses by default. Defaults to :tcp.
  • See Tortoise.Connection.start_link/1 for further options.

Dependency injection

Besides the other config options it is also possible to replace some modules used by providing an alternative implementation:

  • queue_supervisor - The supervisor that supervises the queue processes started by the producer. Defaults to OffBroadway.MQTT.QueueSupervisor.
  • queue_registry - The registry that is used to register the queue processes started by the producer. Defaults to OffBroadway.MQTT.QueueRegistry.
  • acknowledger - The Broadway.Acknowledger implementation used when building the message strucs.
  • client - The MQTT client module.
  • handler- The handler module used by the default client.
  • queue - The queue used in the handler and producer to enqueue / dequeue messages.

Compiletime configuration

The following options must be given at compile time:

  • telemetry_enabled - Enables telemetry events if set to true. This option is disabled by default.

Configuration example

use Mix.Config

config :off_broadway_mqtt,
  client_id_prefix: "sensor_data_processor",
  server_opts: [
    host: "vernemq",
    port: 8883,
    transport: :ssl
  ],
  handler: MyApp.BetterHandler

Building configurations

iex> OffBroadway.MQTT.Config.new()
%OffBroadway.MQTT.Config{
  acknowledger: OffBroadway.MQTT.Acknowledger,
  client: OffBroadway.MQTT.Client,
  client_id_prefix: "obmp",
  dequeue_interval: 5000,
  handler: OffBroadway.MQTT.Handler,
  producer: OffBroadway.MQTT.Producer,
  queue: OffBroadway.MQTT.Queue,
  queue_registry: OffBroadway.MQTT.QueueRegistry,
  queue_supervisor: OffBroadway.MQTT.QueueSupervisor,
  server: {:tcp, [host: 'localhost', port: 1883]},
  telemetry_prefix: :off_broadway_mqtt
}

iex> OffBroadway.MQTT.Config.new(
...>   telemetry_prefix: :test,
...>     server_opts: [host: "vernemq", port: 8883, transport: :ssl]
...>   )
%OffBroadway.MQTT.Config{
  acknowledger: OffBroadway.MQTT.Acknowledger,
  client: OffBroadway.MQTT.Client,
  client_id_prefix: "obmp",
  dequeue_interval: 5000,
  handler: OffBroadway.MQTT.Handler,
  producer: OffBroadway.MQTT.Producer,
  queue: OffBroadway.MQTT.Queue,
  queue_registry: OffBroadway.MQTT.QueueRegistry,
  queue_supervisor: OffBroadway.MQTT.QueueSupervisor,
  server: {:ssl, [host: 'vernemq', port: 8883]},
  telemetry_prefix: :test
}

Link to this section Summary

Functions

Returns a t/0. If no argument or :default is passed the configuration reads values from the Application environment.

Returns a t/0. If no argument or :default is passed the configuration reads values from the Application environment. The second argument is used to override values in the config.

Link to this section Types

Link to this type

option() View Source
option() ::
  {:acknowledger, module()}
  | {:client, module()}
  | {:client_id_prefix, String.t()}
  | {:dequeue_interval, non_neg_integer()}
  | {:handler, module()}
  | {:producer, module()}
  | {:queue, module()}
  | {:queue_registry, GenServer.name()}
  | {:queue_supervisor, GenServer.name()}
  | {:server_opts, raw_server_opts()}
  | {:telemetry_prefix, atom()}
  | {atom(), any()}

Link to this type

options() View Source
options() :: [option()]

Link to this type

raw_server_opt() View Source
raw_server_opt() ::
  {:host, charlist() | String.t()}
  | {:port, non_neg_integer() | String.t()}
  | {:transport, transport(), String.t()}
  | {atom(), any()}

Link to this type

raw_server_opts() View Source
raw_server_opts() :: [raw_server_opt(), ...]

Link to this type

server_opt() View Source
server_opt() ::
  {:host, charlist()}
  | {:port, non_neg_integer()}
  | {:transport, transport()}
  | {atom(), any()}

Link to this type

server_opts() View Source
server_opts() :: [server_opt(), ...]

Link to this type

t() View Source
t() :: %OffBroadway.MQTT.Config{
  acknowledger: module(),
  client: module(),
  client_id_prefix: String.t(),
  dequeue_interval: non_neg_integer(),
  handler: module(),
  producer: module(),
  queue: module(),
  queue_registry: GenServer.name(),
  queue_supervisor: GenServer.name(),
  server: server(),
  telemetry_prefix: atom()
}

Link to this type

transport() View Source
transport() :: :tcp | :ssl

Link to this section Functions

Link to this function

new(options_or_config \\ :default) View Source
new(:default | options()) :: t()

Returns a t/0. If no argument or :default is passed the configuration reads values from the Application environment.

Link to this function

new(opts, overrides) View Source
new(:default | options(), options()) :: t()

Returns a t/0. If no argument or :default is passed the configuration reads values from the Application environment. The second argument is used to override values in the config.