Natsex v0.1.0 Natsex View Source

Elixir client for NATS.

Examples

iex(1)> Natsex.start_link
{:ok, #PID<0.178.0>}
iex(2)> Natsex.subscribe "telegram.user.notifications", self
"13b2d0cd-9dba-43b6-bb5d-288d48346ff4"
iex(3)> flush
{:natsex_message,
 {"telegram.user.notifications", "13b2d0cd-9dba-43b6-bb5d-288d48346ff4", nil},
 "Good news, everyone!"}
:ok
iex(4)>

Link to this section Summary

Functions

Publishes the message to NATS

Starts Natsex client process

Initiates a subscription to a subject. When new message will arrive, caller process will receive message

Unsubcribes the connection from the specified subject, or auto-unsubscribes after the specified number of messages has been received

Link to this section Functions

Link to this function publish(subject, payload \\ "", reply \\ nil) View Source

Publishes the message to NATS

Examples

Natsex.publish("news.urgent", "today is monday")

Starts Natsex client process

Link to this function subscribe(subject, who, sid \\ nil, queue_group \\ nil) View Source

Initiates a subscription to a subject. When new message will arrive, caller process will receive message:

{:natsex_message, {subject, sid, nil}, message}

Examples

sid = Natsex.subscribe("news.urgent", self())
flush
{:natsex_message,
 {"telegram.user.notifications", "sub_id", nil},
 ""Good news, everyone!""}
Link to this function unsubscribe(sid, max_messages \\ nil) View Source

Unsubcribes the connection from the specified subject, or auto-unsubscribes after the specified number of messages has been received.

Examples

Natsex.unsubscribe "13b2d0cd-9dba-43b6-bb5d-288d48346ff4"
:ok