Astarte.Flow.Blocks.MqttSource (astarte_flow v0.1.0)

An Astarte Flow source that produces data from an MQTT connection.

When a message is received on a subscribed topic, MqttSource generates an %Astarte.Flow.Message{} containing these fields:

  • key contains the topic on which the message was received.
  • data contains the payload of the message.
  • type is always :binary.
  • subtype defaults to application/octet-stream but can be configured with the subtype option in start_link/1.
  • metadata contains the Astarte.Flow.Blocks.MqttSource.broker_url key with the broker url as value.
  • timestamp contains the timestamp (in microseconds) the message was received on.

Since MQTT is a push-driven protocol, this block implements a queue to buffer incoming messages while waiting for consumer demand.

Link to this section Summary

Functions

Starts the MqttSource.

Link to this section Functions

Link to this function

start_link(opts)

@spec start_link(opts) :: GenServer.on_start()
when opts: [opt],
     opt:
       {:broker_url, String.t()}
       | {:subscriptions, [String.t(), ...]}
       | {:client_id, String.t()}
       | {:username, String.t()}
       | {:password, String.t()}
       | {:ignore_ssl_errors, boolean()}

Starts the MqttSource.

options

Options

  • broker_url (required): the URL of the broker the source will connect to. The transport will be deduced by the URL: if mqtts:// is used, SSL transport will be used, if mqtt:// is used, TCP transport will be used.
  • subscriptions (required): a non-empty list of topic filters to subscribe to.
  • client_id: the client id used to connect. Defaults to a random string.
  • username: username used to authenticate to the broker.
  • password: password used to authenticate to the broker.
  • ca_cert_pem: a PEM encoded CA certificate. If not provided, the default CA trust store provided by :certifi will be used.
  • client_cert_pem: a PEM encoded client certificate, used for mutual SSL authentication. If this is provided, also private_key_pem must be provided.
  • private_key_pem: a PEM encoded private key, used for mutual SSL authentication. If this is provided, also client_cert_pem must be provided.
  • ignore_ssl_errors: if true, accept invalid certificates (e.g. self-signed) when using SSL.
  • subtype: a MIME type that will be put as subtype in the generated Messages. Defaults to application/octet-stream