diff options
author | Vincent Ambo <tazjin@google.com> | 2019-12-21T01·21+0000 |
---|---|---|
committer | Vincent Ambo <tazjin@google.com> | 2019-12-21T01·21+0000 |
commit | 1a281d3bb93fa46e74fb5e5b79a5da38ba48d628 (patch) | |
tree | 60127697dcd12debaedd876e53bfba511bc69949 /net/stomp_erl/README.md | |
parent | 5f4924cfa769fc2be2ddbd8fe6f82cb0b3663409 (diff) | |
parent | 32d16e2b02bd9ef112107ae5408a1f8fb7fc92c1 (diff) |
merge(stomp.erl): Integrate at //net/stomp_erl r/268
This currently has no build configuration.
Diffstat (limited to 'net/stomp_erl/README.md')
-rw-r--r-- | net/stomp_erl/README.md | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/net/stomp_erl/README.md b/net/stomp_erl/README.md new file mode 100644 index 000000000000..21c95a11a2e9 --- /dev/null +++ b/net/stomp_erl/README.md @@ -0,0 +1,78 @@ +STOMP on Erlang +=============== + +`stomp.erl` is a simple Erlang client for the [STOMP protocol][] in version 1.2. + +Currently only subscribing to queues is supported. + +It provides an application called `stomp` which takes configuration of the form: + +```erlang +[{stomp, #{host => "stomp-server.somedomain.sexy", % required + port => 61613, % optional + login => <<"someuser">>, % optional + passcode => <<"hunter2>>, % optional + }}]. +``` + +## Types + +The following types are used in `stomp.erl`, you can include them from +`stomp.hrl`: + +```erlang +%% Client ack modes, refer to the STOMP protocol documentation +-type ack_mode() :: client | client_individual | auto. + +%% Subscriptions are enumerated from 0 +-type sub_id() :: integer(). + +%% Message IDs (for acknowledgements) are simple strings. They are +%% extracted from the 'ack' field of the header in client or client-individual +%% mode, and from the 'message-id' field in auto mode. +-type message_id() :: binary(). + +%% A STOMP message as received from a queue subscription +-record(stomp_msg, { headers :: #{ binary() => binary() }, + body :: binary() }. +-type stomp_msg() :: #stomp_msg{}. +``` + +Once the application starts it will register a process under the name +`stomp_worker` and expose the following API: + +## Subscribing to a queue + +```erlang +%% Subscribe to a destination, receive the subscription ID +-spec subscribe(binary(), % Destination (e.g. <<"/queue/lizards">>) + ack_mode(), % Client-acknowledgement mode + -> {ok, sub_id()}. +``` + +This synchronous call subscribes to a message queue. The `stomp_worker` will +link itself to the caller and forward received messages as +`{msg, sub_id(), stomp_msg()}`. + +Depending on the acknowledgement mode specified on connecting, the subscriber +may have to acknowledge receival of messages. + +## Acknowledging messages + +```erlang +%% Acknowledge a message ID. +%% This is not required in auto mode. In client mode it will acknowledge the +%% received messages up to the ID specified. In client-individual mode every +%% single message has to be acknowledged. +-spec ack(sub_id(), message_id()) -> ok. + +%% Explicitly "unacknowledge" a message +-spec nack(sub_id(), message_id()) -> ok. +``` + +Both of these calls are asynchronous and will return immediately. Note that in +the case of the `stomp_worker` crashing before a message acknowledgement is +handled, the message *may* be delivered again. Your consumer needs to be able to +handle this. + +[STOMP protocol]: https://stomp.github.io/stomp-specification-1.2.html |