z_mqtt (zotonic_core v1.0.0-rc.11)

Interface to MQTT pubsub functionality

Link to this section Summary

Link to this section Types

-type callback() :: pid() | {module(), atom(), list()}.
Link to this type

publish_options/0

-type publish_options() :: #{retain => boolean(), qos => 0 | 1 | 2}.
-type topic() :: mqtt_sessions:topic().
-type topic_any() :: mqtt_sessions:topic() | m_rsc:resource_id() | {object, list()} | {subject, list()}.

Link to this section Functions

Link to this function

await_response(Topic, Context)

-spec await_response(mqtt_sessions:topic(), z:context()) ->
                  {ok, mqtt_packet_map:mqtt_packet()} | {error, timeout}.
Link to this function

await_response(Topic, Timeout, Context)

-spec await_response(mqtt_sessions:topic(), pos_integer(), z:context()) ->
                  {ok, mqtt_packet_map:mqtt_packet()} | {error, timeout}.
Link to this function

call(Msg, Context)

-spec call(mqtt_packet_map:mqtt_packet(), z:context()) -> {ok, term()} | {error, term()}.
Link to this function

call(Topic, Payload, Context)

-spec call(topic(), term(), z:context()) -> {ok, term()} | {error, term()}.
Link to this function

flatten_topic(T)

Link to this function

is_client_alive(Context)

-spec is_client_alive(z:context()) -> boolean().
Check if the MQTT client for this request context is alive.
Link to this function

map_topic(Topic, Context)

-spec map_topic(mqtt_sessions:topic(), z:context()) ->
             {ok, mqtt_sessions:topic()} | {error, no_client | term()}.
Link to this function

map_topic_filter(Topic, Context)

-spec map_topic_filter(topic_any(), z:context()) -> {ok, topic()} | {error, no_topic | term()}.
Map subscription topic to a topic filter.
Link to this function

origin_topic(Topic)

-spec origin_topic(Topic) -> OriginTopic
                when Topic :: mqtt_sessions:topic(), OriginTopic :: mqtt_sessions:topic().
Ensure that the topic is prefixed with "bridge/origin/".
Link to this function

publish(Msg, Context)

-spec publish(mqtt_packet_map:mqtt_packet(), z:context()) -> ok | {error, term()}.
Link to this function

publish(Topic, Payload, Context)

-spec publish(topic(), term(), z:context()) -> ok | {error, term()}.
Link to this function

publish(Topic, Payload, Options, Context)

-spec publish(topic(), term(), publish_options(), z:context()) -> ok | {error, term()}.
Link to this function

subscribe(TopicFilter, Context)

-spec subscribe(topic(), z:context()) -> ok | {error, term()}.
Link to this function

subscribe(TopicFilter, Pid, Context)

-spec subscribe(topic(), pid(), z:context()) -> ok | {error, term()}.
Link to this function

subscribe(TopicFilter, Callback, OwnerPid, Context)

-spec subscribe(topic(), callback(), pid(), z:context()) -> ok | {error, term()}.
Link to this function

subscribe(TopicFilter, Callback, OwnerPid, Options, Context)

-spec subscribe(topic(), callback(), pid(), mqtt_sessions:subscriber_options(), z:context()) ->
             ok | {error, term()}.
Link to this function

temp_response_topic(Context)

-spec temp_response_topic(z:context()) -> {ok, mqtt_sessions:topic()} | {error, term()}.
Link to this function

unsubscribe(TopicFilter, Context)

-spec unsubscribe(topic(), z:context()) -> ok | {error, term()}.
Link to this function

unsubscribe(TopicFilter, OwnerPid, Context)

-spec unsubscribe(topic(), pid(), z:context()) -> ok | {error, term()}.
Link to this function

whereis_client(Context)

-spec whereis_client(z:context()) -> {ok, pid()} | {error, term()}.
Find the Pid of the MQTT client process for this request context.