off_broadway_mqtt v0.2.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 to5000.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 to1883.transport- The protocol the MQTT client uses by default. Defaults to:tcp.- See
Tortoise.Connection.start_link/1for 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 toOffBroadway.MQTT.QueueSupervisor.queue_registry- The registry that is used to register the queue processes started by the producer. Defaults toOffBroadway.MQTT.QueueRegistry.acknowledger- TheBroadway.Acknowledgerimplementation 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
}
Keep in mind that any option with nil or the empty string will be removed from the server options to prevent issues when configuring the application from environment variables.
Link to this section Summary
Link to this section Types
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()}
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()}
options()
View Source
options() :: [option()]
options() :: [option()]
raw_server_opt() View Source
raw_server_opts()
View Source
raw_server_opts() :: [raw_server_opt(), ...]
raw_server_opts() :: [raw_server_opt(), ...]
server()
View Source
server() :: {transport(), server_opts()}
server() :: {transport(), server_opts()}
server_opt()
View Source
server_opt() ::
{:host, String.t()}
| {:port, non_neg_integer()}
| {:transport, transport()}
| {atom(), any()}
server_opt() ::
{:host, String.t()}
| {:port, non_neg_integer()}
| {:transport, transport()}
| {atom(), any()}
server_opts()
View Source
server_opts() :: [server_opt(), ...]
server_opts() :: [server_opt(), ...]
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()
}
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()
}
transport()
View Source
transport() :: :tcp | :ssl
transport() :: :tcp | :ssl
Link to this section Functions
new(opts \\ []) View Source
Builds a t/0 from the given keyword list.
Use this function if you want to build a config only from the passed options. Any application config is ignored if using this function.
new_from_app_config(overrides \\ []) View Source
Returns a t/0 with values from the applicatoin config.
Use this function if you want to build a config based on the configured defaults for the application.