View Source Mammoth (mammoth v0.0.0)
Mammoth: A STOMP client.
Use Mammoth
as the primary API and Mammoth.Message
for working with received messages.
example
Example
{:ok, pid} = Mammoth.start_link
Mammoth.connect(pid, {127,0,0,1}, 61613, "admin", "admin")
callback = fn m -> IO.puts(inspect(m)) end
Mammoth.subscribe(pid, "foo.bar", callback)
Mammoth.disconnect(pid)
For more control, use pattern matching in the callback:
callback = fn
%Mammoth.Message{command: :message, headers: headers, body: body} ->
Logger.info(["Received MESSAGE", "\nheaders: ", inspect(headers), "\nbody: ", inspect(body)])
%Mammoth.Message{command: :error, headers: headers, body: body} ->
Logger.error(["Received ERROR", "\nheaders: ", inspect(headers), "\nbody: ", inspect(body)])
%Mammoth.Message{command: cmd, headers: headers, body: body} ->
Logger.error([
"Received unknown command: ", cmd,
"\nheaders: ",
inspect(headers),
"\nbody: ",
inspect(body)
])
end
starting-in-a-supervision-tree
Starting in a supervision tree
children = [
worker(Mammoth, [%{}, [name: Mammoth]])
]
Link to this section Summary
Functions
Returns a specification to start this module under a supervisor.
Connect to server.
Disconnect from server.
Disconnects from server.
Callback implementation for GenServer.init/1
.
Receive messages from the TCP socket.
Subscribe to a queue and register a callback for received messages.
Unsubscribe from a queue.
Link to this section Functions
Returns a specification to start this module under a supervisor.
See Supervisor
.
Connect to server.
host
must be inet:socket_address() | inet:hostname()
, for example {127,0,0,1}
.
Disconnect from server.
Disconnects from server.
Returns {:ok, :disconnected}
or {:error, :disconnect_failed, message}
.
Callback implementation for GenServer.init/1
.
Receive messages from the TCP socket.
Is called automatically when necessary. Should not be called manually.
Subscribe to a queue and register a callback for received messages.
Unsubscribe from a queue.