romanchechyotkin / nats.ocaml

OCaml client for NATS, the cloud native messaging system.
Apache License 2.0
8 stars 1 forks source link

Basic subscription mechanism #9

Closed dx3mod closed 3 weeks ago

dx3mod commented 3 weeks ago

After this discussion #8 it was decided to use Lwt_stream to handle the stream of incoming messages. Users subscribe to a subject and get a stream of messages (Message.Incoming.msg Lwt_stream.t) for that subject.

It allows users to use streams in many cases.

Callback-like example

let%lwt foo_subj = client#sub ~subject:"FOO" () in

Nats_client.Subscription.handle foo_subj (fun _ -> 
  Lwt_io.printl "GOT MESSAGE FROM FOO SUBJECT");

(* ... *)

References