Natsex
Elixir client for NATS
Installation
The package can be installed by adding natsex
to your list of dependencies in mix.exs
:
def deps do
[
{:natsex, "~> 0.7.2"}
]
end
Usage
# connects with default params, host - "localhost", port - 4222
iex(1)> {:ok, pid} = Natsex.start_link()
{:ok, #PID<0.178.0>}
# or connects on custom port with credentials
iex(1)> {:ok, pid} = Natsex.start_link(config: %{host: "localhost", port: 4567, user: "admin", pass: "12345"})
{:ok, #PID<0.195.0>}
iex(2)> Natsex.subscribe(pid, "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
# sent a message and waits a response, aka "Request-Reply"
iex(4)> Natsex.request(pid, "questions", "sup?")
{:ok, "response"}
iex(5)> Natsex.stop(pid)
:ok
Documentation
Docs can be found at hexdocs.