orus-io/elm-nats/1.0.0

Nats

A nats.io client for Elm

socket

connect : ConnectOptions -> Socket -> (SocketEvent -> msg) -> Sub datatype msg

Open a socket

The socket will be opened as soon as the subscription is active, and until the subscriptions is removed.

The socket may get closed if a network error occurs, in which case a 'SocketError' event will be sent

After the subscription is removed, the handler will receive a SocketClosed event.

pub/sub/request

publish : String -> datatype -> Effect datatype msg

Publish a new message on a given subject

If you wish to send it on a non-default socket, use Nats.Effect.onSocket

publishRequest : String -> String -> datatype -> Effect datatype msg

Publish a new message on a given subject, with a 'replyTo' attribute

subscribe : String -> (Message datatype -> msg) -> Sub datatype msg

Subscribe to a subject

If you wish to subscribe on a non-default socket, use Nats.Sub.onSocket

groupSubscribe : String -> String -> (Message datatype -> msg) -> Sub datatype msg

Subscribe to a subject with a group

If you wish to subscribe on a non-default socket, use Nats.Sub.onSocket

String
-> datatype
-> (Result Timeout datatype -> msg)
-> Effect datatype msg

Create a request

The timeout is 5s by default

Int
-> String
-> datatype
-> (Result Timeout datatype -> msg)
-> Effect datatype msg

Create a request with a custom timeout

{ marker : String
, subject : String
, replyTo : Maybe String
, message : datatype
, onTimeout : Timeout -> msg
, onResponse : Message datatype -> ( Maybe msg, Bool )
, timeout : Maybe Int
}
-> Effect datatype msg

Create a request with custom features

track : String -> Sub datatype msg

Track a request

cancelRequest : String -> Effect datatype msg

Cancel an active request, given its marker

withMarker : String -> Effect datatype msg -> Effect datatype msg

Add a marker on a request

If the effect is not a request, the function is no-op

Types

type alias Config datatype portdatatype msg =
Config datatype portdatatype msg

The NATS configuration

type State datatype msg

The nats internal state

type alias Msg datatype msg =
Msg datatype msg

A nats internal Msg

withInboxPrefix : String -> State datatype msg -> State datatype msg

Set a custom inbox prefix

Effects

type alias Effect datatype msg =
Effect datatype msg

A nats effect

Kind of like Cmd, but will be converted at the last moment to regular Cmd

type alias Sub datatype msg =
Sub datatype msg

A nats subscription

Will be converted at the last moment to regular Sub.

Config datatype portdatatype msg
-> Effect datatype msg
-> Sub datatype msg
-> State datatype msg
-> ( State datatype msg, Cmd msg )

Update the nats state according to all the Nats.Effect and Nats.Sub gathered by the app root component, and emit all the necessary Cmd

...

init : Seed -> Posix -> State datatype msg

Initialise a new nats state

Config datatype portdatatype msg
-> Msg datatype msg
-> State datatype msg
-> ( State datatype msg, Cmd msg )

Handle Nats Msg

subscriptions : Config datatype portdatatype msg -> State datatype msg -> Sub msg

Connect the nats internal state to the ports

State datatype msg
-> List
{ sid : String
, id : String
, marker : Maybe String
, subject : String
, inbox : String
}

List all the active requests