View Source Mammoth (mammoth v0.4.6)

Mammoth: A STOMP client.

Use Mammoth as the primary API and Mammoth.Message for working with received messages.

My recommendation is to start mammoth from within your own implementation of the callback handler, and to put the callback handler itself into a supervisor.

You shouldn't try to reconnect a disconnected mammoth process, at the moment the internal state may be inconsistent. Instead, start a new instance. Again, this is easily handled with OTP.

example

Example

{:ok, callback_pid} = Mammoth.DefaultCallbackHandler.start_link
{:ok, pid} = Mammoth.start_link(callback_pid)
:ok = Mammoth.DefaultCallbackHandler.set_mammoth_pid(callback_pid, pid)
Mammoth.connect(pid, {127,0,0,1}, 61613, "/", "admin", "admin")
Mammoth.subscribe(pid, "foo.bar", :client)
Mammoth.disconnect(pid)

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.

Disconnect from server.

Requests disconnection from the remote server

Callback implementation for GenServer.init/1.

Receive messages from the TCP socket.

Send an ACK message to the remote server for the specified frame if the 'ack' header is present

Send an ACK message to the remote server for the specified frame ID (referenced in the MESSAGE ack header)

Send a frame to the remote server

Send an NACK message to the remote server for the specified frame

Send an NACK message to the remote server for the specified frame ID (referenced in the MESSAGE ack header)

Send a SEND message to the remote server

Unsubscribe from a queue.

Link to this section Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

connect(pid, host, port, virtual_host, login, password, additional_headers \\ [])

View Source

Connect to server.

host must be inet:socket_address() | inet:hostname(), for example {127,0,0,1} or 'example.com'. virtual_host (host header) is mandatory in STOMP 1.2, behaviour is server defined. Default on RabbitMQ would be "/".

https://stomp.github.io/stomp-specification-1.2.html#CONNECT_or_STOMP_Frame

Disconnect from server.

Link to this function

handle_call(msg, from, state)

View Source

Requests disconnection from the remote server

Callback implementation for GenServer.init/1.

Receive messages from the TCP socket.

Is called automatically when necessary. Should not be called manually.

Link to this function

send_ack_frame(pid, message, additional_headers \\ [])

View Source

Send an ACK message to the remote server for the specified frame if the 'ack' header is present

Link to this function

send_ack_id(pid, id, additional_headers)

View Source

Send an ACK message to the remote server for the specified frame ID (referenced in the MESSAGE ack header)

Link to this function

send_frame(pid, message)

View Source

Send a frame to the remote server

Link to this function

send_nack_frame(pid, message, additional_headers \\ [])

View Source

Send an NACK message to the remote server for the specified frame

Link to this function

send_nack_id(pid, id, additional_headers)

View Source

Send an NACK message to the remote server for the specified frame ID (referenced in the MESSAGE ack header)

Link to this function

send_send(pid, destination, body, additional_headers \\ [])

View Source

Send a SEND message to the remote server

content-length header will be automatically added.

Link to this function

start_link(callback_handler, state \\ %{}, opts \\ [])

View Source
Link to this function

subscribe(pid, destination, ack_mode \\ :auto, additional_headers \\ [])

View Source

Subscribe to a queue.

Note that if you set ack_mode to :client_individual or :client, you must send ACK frames when you receive MESSAGE frames (not required with :auto) https://stomp.github.io/stomp-specification-1.2.html#SUBSCRIBE_ack_Header

Link to this function

unsubscribe(pid, destination)

View Source

Unsubscribe from a queue.