m_mqtt_ticket (zotonic_mod_base v1.0.0-rc.17)

A ticketing system for out of band MQTT posts via HTTP.

The controller controller_mqtt_transport can accept HTTP posts. These posts MUST include a ticket and a topic for the payload to be sent.

The ticket is obtained via model/mqtt_ticket/post/new. This can only be accessed via MQTT, as the routines will check for a valid client_id.

If a ticket is created then the current request context is saved for max 30 seconds. If a request comes in then the ticket is used to fetch the stored context and the following information is copied over from the stored context to the HTTP request context:

  • MQTT client-id
  • MQTT client-topic
  • MQTT routing-id
  • ACL user id
  • ACL auth_options
  • ACL read-only flag
  • Timezone
  • Language

A ticket can only be used once.

Available Model API Paths

MethodPath patternDescription
post/newCreate a one-time MQTT transport ticket for the current MQTT client context and return the generated ticket id (binary). No further lookups.
delete/+ticketInvalidate/delete ticket +ticket and its stored context so it can no longer be exchanged. No further lookups.

/+name marks a variable path segment. A trailing /... means extra path segments are accepted for further lookups.

Summary

Functions

exchange_ticket(Ticket, Context)

-spec exchange_ticket(binary(), z:context()) -> {ok, z:context()} | {error, term()}.

m_delete/3

-spec m_delete([binary()], zotonic_model:opt_msg(), z:context()) -> {ok, term()} | ok | {error, term()}.

m_get(Path, Msg, Context)

m_post/3

-spec m_post([binary()], zotonic_model:opt_msg(), z:context()) -> {ok, term()} | ok | {error, term()}.

new_ticket(Context)

-spec new_ticket(z:context()) -> {ok, binary()} | {error, term()}.