View Source mqtt_sessions (mqtt_sessions v2.5.1)

Session management for a MQTT server.

Link to this section Summary

Functions

Stream the connect message - connect a MQTT session or return an error
Stream the connect message - connect a MQTT session or return an error
Handle incoming data for session. Call this after a successful connect. The session will disconnect on an illegal packet.
Return the runtime module for AUTH and other callbacks.
Set the runtime module
Limit the number of sidejobs for message dispatching.

Link to this section Types

-type callback() :: pid() | {module(), atom(), list()}.
-type mqtt_msg() :: mqtt_sessions_router:mqtt_msg().
-type msg_options() ::
    #{transport => transport(),
      peer_ip => tuple() | undefined,
      context_prefs => map(),
      connection_pid => pid()}.
-type session_options() ::
    #{routing_id => binary(), peer_ip => tuple() | undefined, context_prefs => map()}.
-type session_ref() :: pid() | binary().
-type subscriber() :: mqtt_sessions_router:subscriber().
-type subscriber_options() :: mqtt_sessions_router:subscriber_options().
-type topic() :: mqtt_packet_map:mqtt_topic().
-type transport() :: function() | callback().

Link to this section Functions

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

await_response(Topic, Timeout)

View Source
-spec await_response(topic(), pos_integer()) -> {ok, mqtt_packet_map:mqtt_packet()} | {error, timeout};
              (atom(), topic()) -> {ok, mqtt_packet_map:mqtt_packet()} | {error, timeout}.
Link to this function

await_response(Pool, Topic, Timeout)

View Source
-spec find_session(session_ref()) -> {ok, pid()} | {error, notfound}.
Link to this function

find_session(Pool, ClientId)

View Source
-spec find_session(atom(), session_ref()) -> {ok, pid()} | {error, notfound}.
Link to this function

get_transport(SessionPid)

View Source
-spec get_transport(pid()) -> {ok, transport()} | {error, notransport | noproc}.
Link to this function

get_user_context(ClientId)

View Source
-spec get_user_context(session_ref()) -> {ok, term()} | {error, notfound | noproc}.
Link to this function

get_user_context(Pool, ClientId)

View Source
-spec get_user_context(atom(), session_ref()) -> {ok, term()} | {error, notfound | noproc}.
Link to this function

incoming_connect(MsgBin, Options)

View Source
-spec incoming_connect(binary(), msg_options()) ->
                    {ok, {session_ref(), binary()}} | {error, incomplete_packet} | {error, term()}.
Stream the connect message - connect a MQTT session or return an error
Link to this function

incoming_connect(Pool, MsgBin, Options)

View Source
-spec incoming_connect(atom(), binary(), msg_options()) ->
                    {ok, {session_ref(), binary()}} | {error, incomplete_packet} | {error, term()}.
Stream the connect message - connect a MQTT session or return an error
Link to this function

incoming_data(SessionRef, MsgBin)

View Source
-spec incoming_data(session_ref(), binary()) ->
                 ok | {error, wrong_connection | mqtt_packet_map:decode_error()}.
Handle incoming data for session. Call this after a successful connect. The session will disconnect on an illegal packet.
Link to this function

publish(Msg, UserContext)

View Source
-spec publish(mqtt_packet_map:mqtt_packet(), term()) -> ok | {error, eacces | invalid_topic}.
Link to this function

publish(Pool, Msg, UserContext)

View Source
-spec publish(topic(), term(), term()) -> ok | {error, eacces | invalid_topic};
       (atom(), mqtt_packet_map:mqtt_packet(), term()) -> ok | {error, eacces | invalid_topic}.
Link to this function

publish(Pool, Topic, Payload, UserContext)

View Source
-spec publish(atom(), topic(), term(), term()) -> ok | {error, eacces | invalid_topic}.
Link to this function

publish(Pool, Topic, Payload, Options, UserContext)

View Source
-spec publish(atom(), topic(), term(), map(), term()) -> ok | {error, eacces | invalid_topic}.
-spec router_info(atom()) -> list().
-spec runtime() -> atom().
Return the runtime module for AUTH and other callbacks.
-spec session_count(atom()) -> integer().
-spec set_runtime(atom()) -> ok.
Set the runtime module
Link to this function

set_user_context(ClientId, UserContext)

View Source
-spec set_user_context(session_ref(), term()) -> {ok, term()} | {error, notfound | noproc}.
Link to this function

set_user_context(Pool, ClientId, UserContext)

View Source
-spec set_user_context(atom(), session_ref(), term()) -> {ok, term()} | {error, notfound | noproc}.
-spec sidejobs_limit() -> pos_integer().
Limit the number of sidejobs for message dispatching.
-spec sidejobs_per_session() -> pos_integer().
-spec start() -> {ok, pid()} | {error, term()}.
Link to this function

start(StartType, StartArgs)

View Source
-spec start(application:start_type(), term()) -> {ok, pid()} | {error, term()}.
-spec stop(term()) -> ok.
Link to this function

subscribe(TopicFilter, UserContext)

View Source
-spec subscribe(topic(), term()) -> ok | {error, eacces | invalid_topic}.
Link to this function

subscribe(Pool, TopicFilter, UserContext)

View Source
-spec subscribe(atom(), topic(), term()) -> ok | {error, eacces | invalid_topic}.
Link to this function

subscribe(Pool, TopicFilter, MFA, UserContext)

View Source
-spec subscribe(atom(), topic(), callback(), term()) -> ok | {error, eacces | invalid_topic}.
Link to this function

subscribe(Pool, TopicFilter, Receiver, OwnerPid, Options, UserContext)

View Source
-spec subscribe(atom(), topic(), callback(), pid(), map(), term()) ->
             ok | {error, eacces | invalid_topic}.
Link to this function

temp_response_topic(UserContext)

View Source
-spec temp_response_topic(term()) -> {ok, topic()} | {error, eacces}.
Link to this function

temp_response_topic(Pool, UserContext)

View Source
-spec temp_response_topic(atom(), term()) -> {ok, topic()} | {error, eacces}.
Link to this function

unsubscribe(TopicFilter)

View Source
-spec unsubscribe(topic()) -> ok | {error, notfound | invalid_topic}.
Link to this function

unsubscribe(Pool, TopicFilter)

View Source
-spec unsubscribe(atom(), topic()) -> ok | {error, notfound | invalid_topic}.
Link to this function

unsubscribe(Pool, TopicFilter, OwnerPid)

View Source
-spec unsubscribe(atom(), topic(), pid()) -> ok | {error, notfound | invalid_topic}.
Link to this function

update_user_context(ClientId, Fun)

View Source
-spec update_user_context(session_ref(), fun((term()) -> term())) ->
                       {ok, term()} | {error, notfound | noproc}.
Link to this function

update_user_context(Pool, ClientId, Fun)

View Source
-spec update_user_context(atom(), session_ref(), fun((term()) -> term())) ->
                       {ok, term()} | {error, notfound | noproc}.