z_mqtt (zotonic_core v1.0.0-rc.17)

Interface to MQTT pubsub functionality

Summary

Types

callback/0

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

publish_options/0

-type publish_options() :: #{retain => boolean(), qos => 0 | 1 | 2}.

topic/0

-type topic() :: mqtt_sessions:topic().

topic_any/0

-type topic_any() :: mqtt_sessions:topic() | m_rsc:resource_id() | {object, list()} | {subject, list()}.

Functions

await_response(Topic, Context)

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

await_response(Topic, Timeout, Context)

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

call(Msg, Context)

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

call(Topic, Payload, Context)

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

flatten_topic(T)

is_client_alive(Context)

-spec is_client_alive(z:context()) -> boolean().

Check if the MQTT client for this request context is alive.

map_topic(Topic, Context)

-spec map_topic(Topic, Context) -> {ok, mqtt_sessions:topic()} | {error, no_client | term()}
                   when
                       Topic :: mqtt_sessions:topic() | undefined | atom() | m_rsc:resource_id(),
                       Context :: z:context().

map_topic_filter(TopicAny, Context)

-spec map_topic_filter(TopicAny, Context) -> {ok, topic()} | {error, no_topic | term()}
                          when TopicAny :: topic_any() | undefined, Context :: z:context().

Map subscription topic to a topic filter.

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/".

publish(Msg, Context)

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

publish(Topic, Payload, Context)

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

publish(Topic, Payload, Options, Context)

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

subscribe(TopicFilter, Context)

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

subscribe(TopicFilter, Pid, Context)

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

subscribe(TopicFilter, Callback, OwnerPid, Context)

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

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

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

temp_response_topic(Context)

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

unsubscribe(TopicFilter, Context)

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

unsubscribe(TopicFilter, OwnerPid, Context)

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

whereis_client(Context)

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

Find the Pid of the MQTT client process for this request context.