A session manages the connection with the server and is used to send commands to the server.
Incoming port for messages from the STOMP server.
port onMessage : Stomp.Client.OnMessage msgA subscription that will listen for new WebSocket messages on the provided port and dispatch them to the STOMP session.
subscriptions : State -> Sub Msg
subscriptions state =
Stomp.Client.listen onMessage state.sessionThe messages to send to your update function when the state of the connection changes.
{ onConnected : msg
, onDisconnected : msg
, onError : String -> msg
, onHeartBeat : msg
}The Session holds the state of the connection.
Create a session that manages the WebSocket connection (through a port) and keeps track of the STOMP state.
Stomp.Client.init socket
{ onConnected = Connected
, onDisconnected = Disconnected
, onError = Error
, onHeartBeat = HeartBeat
}Send a CONNECT frame to the server. This always needs to be the first message sent, to establish the connection and authenticate the user. Trying to send a message before the server has recieved and acknowledged the CONNECT message will result in the server simply closing the socket.
Stomp.Client.connect session "guest" "guest" "/"Send a DISCONNECT frame to the server.
Send a message to a specific topic.
sendStrings : List String -> Cmd Msg
sendStrings strings =
let
topic =
"example.strings"
headers =
[ ( "x-example", "this is a header" ) ]
body =
Json.Encode.list (List.map Json.Encode.string strings)
in
Stomp.Session.send session topic headers bodySend a remote procedure call to a server.
type Msg
= Strings (Result String Stomp.Message.Message)
getStrings : Cmd Msg
getStrings =
Stomp.Proc.init "example.strings"
|> Stomp.Proc.onResponse Strings
|> Stomp.Session.call sessionSubscribe to message from a server on a specific topic.
type Msg
= Strings (Result String Stomp.Message.Message)
strings : Cmd Msg
strings =
Stomp.Subscription.init "example.strings"
|> Stomp.Subscription.onMessage Strings
|> Stomp.Session.subscribe sessionUnsubscribe an existing subscription (uses subscription id to identify which subscription to unsubscribe).
Stomp.Subscription.init "example.strings"
|> Stomp.Subscription.withSubscriptionId "strings-1"
|> Stomp.Session.unsubscribe sessionAcknowledge that a message was consumed by the session when using SessionAck or SessionIndividualAck modes on a subscription.
The opposite of ack.
It is used to tell the server that the session did not consume the message. The server can then either send the message to a different session, discard it, or put it in a dead letter queue. The exact behavior is server specific.
nack applies either to one single message (if the subscription's ack mode is SessionIndividualAck) or to all messages sent before and not yet ack'ed or nack'ed (if the subscription's ack mode is SessionAck).
begin is used to start a transaction. Transactions in this case apply to sending and acknowledging - any messages sent or acknowledged during a transaction will be processed atomically based on the transaction.
commit is used to commit a transaction in progress.
abort is used to roll back a transaction in progress.
Connection to a STOMP server. This is the type of the outgoing port.