nats_msg (enats_msg v1.0.2)

View Source

Summary

Functions

Encodes a CONNECT message sent by the client to provide connection details and security information. The argument is the JSON connect options payload.

Decodes a binary or iolist containing NATS protocol messages. Stops after the first complete message is decoded. Returns the decoded message term and any remaining binary data.

Decodes a binary or iolist containing NATS protocol messages using a callback function to handle decoded events. The callback function is called with (Event, State) and should return {continue, NewState} or {stop, FinalState}. Returns the final state returned by the callback and any remaining binary data.

Decodes all complete NATS protocol messages found in the input binary. Returns a list of decoded messages and any remaining binary data.

Encodes an Erlang term representing a NATS protocol message into an iolist suitable for sending over the wire.

Encodes an -ERR message indicating a protocol error.

Encodes an HMSG message with no reply-to, empty header, and empty payload.

Encodes an HMSG message with no reply-to.

Encodes an HPUB message to publish data with headers to a subject with empty header and payload.

Encodes an HPUB message to publish data with headers to a subject.

Encodes an HPUB message to publish data with headers to a subject, optionally including a reply subject.

Encodes an INFO message sent by the server to provide connection information. The argument is the JSON info payload.

Initializes the nats_msg module.

Encodes a MSG message with no reply-to and empty payload.

Encodes a MSG message.

Encodes a +OK acknowledgement message.

Encodes a PING keep-alive message.

Encodes a PONG keep-alive response.

Encodes a PUB message to publish data to a subject with an empty payload.

Encodes a PUB message to publish data to a subject, optionally including a reply subject.

Encodes a SUB message to subscribe to a subject.

Encodes a SUB message to subscribe to a subject, optionally joining a queue group.

Encodes an UNSUB message to unsubscribe from a subject.

Encodes an UNSUB message to unsubscribe from a subject after a certain number of messages.

Types

encode_param()

-type encode_param() ::
          ping | pong | ok | error |
          {info, iodata()} |
          {connect, iodata()} |
          error_param() |
          pub_param() |
          hpub_param() |
          sub_param() |
          unsub_param() |
          msg_param() |
          hmsg_param().

error_atom()

-type error_atom() ::
          unknown_operation | auth_violation | auth_timeout | parser_error | stale_connection |
          slow_consumer | max_payload | invalid_subject.

error_param()

-type error_param() :: {error, error_atom()}.

hmsg_param()

-type hmsg_param() ::
          {hmsg,
           {Subject :: iodata(),
            Sid :: iodata(),
            ReplyTo :: iodata() | undefined,
            Header :: iodata(),
            Payload :: iodata()}}.

hpub_param()

-type hpub_param() ::
          {hpub,
           {Subject :: iodata(),
            ReplyTo :: iodata() | undefined,
            Header :: iodata(),
            Payload :: iodata()}}.

msg_param()

-type msg_param() ::
          {msg,
           {Subject :: iodata(), Sid :: iodata(), ReplyTo :: iodata() | undefined, Payload :: iodata()}}.

pub_param()

-type pub_param() :: {pub, {Subject :: iodata(), ReplyTo :: iodata() | undefined, Payload :: iodata()}}.

sub_param()

-type sub_param() :: {sub, {Subject :: iodata(), QueueGrp :: iodata() | undefined, Sid :: iodata()}}.

unsub_param()

-type unsub_param() :: {unsub, {Sid :: iodata(), MaxMsg :: integer() | undefined}}.

Functions

connect(Info)

-spec connect(Info :: iodata()) -> iolist().

Encodes a CONNECT message sent by the client to provide connection details and security information. The argument is the JSON connect options payload.

decode(Param)

-spec decode(Param :: iodata()) -> {term(), binary()}.

Decodes a binary or iolist containing NATS protocol messages. Stops after the first complete message is decoded. Returns the decoded message term and any remaining binary data.

decode(Bin, CbFunState)

-spec decode(Bin :: iodata(), CbFunState :: {function(), term()}) -> {term(), binary()}.

Decodes a binary or iolist containing NATS protocol messages using a callback function to handle decoded events. The callback function is called with (Event, State) and should return {continue, NewState} or {stop, FinalState}. Returns the final state returned by the callback and any remaining binary data.

decode_all(Bin)

-spec decode_all(Bin :: iodata()) -> {list(), binary()}.

Decodes all complete NATS protocol messages found in the input binary. Returns a list of decoded messages and any remaining binary data.

encode(Param)

-spec encode(Param :: encode_param()) -> iolist().

Encodes an Erlang term representing a NATS protocol message into an iolist suitable for sending over the wire.

err(Msg)

-spec err(Msg :: error_atom()) -> iolist().

Encodes an -ERR message indicating a protocol error.

hmsg(Subject, Sid)

-spec hmsg(Subject :: iodata(), Sid :: iodata()) -> iolist().

Encodes an HMSG message with no reply-to, empty header, and empty payload.

hmsg(Subject, Sid, Header, Payload)

-spec hmsg(Subject :: iodata(), Sid :: iodata(), Header :: iodata(), Payload :: iodata()) -> iolist().

Encodes an HMSG message with no reply-to.

hmsg(Subject, Sid, ReplyTo, Header, Payload)

-spec hmsg(Subject :: iodata(),
           Sid :: iodata(),
           ReplyTo :: iodata() | undefined,
           Header :: iodata(),
           Payload :: iodata()) ->
              iolist().

Encodes an HMSG message.

hpub(Subject)

-spec hpub(Subject :: iodata()) -> iolist().

Encodes an HPUB message to publish data with headers to a subject with empty header and payload.

hpub(Subject, Header, Payload)

-spec hpub(Subject :: iodata(), Header :: iodata(), Payload :: iodata()) -> iolist().

Encodes an HPUB message to publish data with headers to a subject.

hpub(Subject, ReplyTo, Header, Payload)

-spec hpub(Subject :: iodata(),
           ReplyTo :: iodata() | undefined,
           Header :: iodata(),
           Payload :: iodata()) ->
              iolist().

Encodes an HPUB message to publish data with headers to a subject, optionally including a reply subject.

info(Info)

-spec info(Info :: iodata()) -> iolist().

Encodes an INFO message sent by the server to provide connection information. The argument is the JSON info payload.

init()

-spec init() -> ok.

Initializes the nats_msg module.

msg(Subject, Sid)

-spec msg(Subject :: iodata(), Sid :: iodata()) -> iolist().

Encodes a MSG message with no reply-to and empty payload.

msg(Subject, Sid, ReplyTo, Payload)

-spec msg(Subject :: iodata(), Sid :: iodata(), ReplyTo :: iodata() | undefined, Payload :: iodata()) ->
             iolist().

Encodes a MSG message.

ok()

-spec ok() -> iolist().

Encodes a +OK acknowledgement message.

ping()

-spec ping() -> iolist().

Encodes a PING keep-alive message.

pong()

-spec pong() -> iolist().

Encodes a PONG keep-alive response.

pub(Subject)

-spec pub(Subject :: iodata()) -> iolist().

Encodes a PUB message to publish data to a subject with an empty payload.

pub(Subject, ReplyTo, Payload)

-spec pub(Subject :: iodata(), ReplyTo :: iodata() | undefined, Payload :: iodata()) -> iolist().

Encodes a PUB message to publish data to a subject, optionally including a reply subject.

sub(Subject, Sid)

-spec sub(Subject :: iodata(), Sid :: iodata()) -> iolist().

Encodes a SUB message to subscribe to a subject.

sub(Subject, QueueGrp, Sid)

-spec sub(Subject :: iodata(), QueueGrp :: iodata() | undefined, Sid :: iodata()) -> iolist().

Encodes a SUB message to subscribe to a subject, optionally joining a queue group.

unsub(Sid)

-spec unsub(Sid :: iodata()) -> iolist().

Encodes an UNSUB message to unsubscribe from a subject.

unsub(Sid, MaxMsg)

-spec unsub(Sid :: iodata(), MaxMsg :: integer() | undefined) -> iolist().

Encodes an UNSUB message to unsubscribe from a subject after a certain number of messages.