fszmq


Request-Reply Broker

Simple broker for connecting client requests to server replies.

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
26: 
27: 
28: 
29: 
30: 
31: 
32: 
33: 
34: 
35: 
36: 
37: 
#r "fszmq.dll"
open fszmq
open fszmq.Polling

// helper for managing resources
let dispose (o : System.IDisposable) = if o <> null then o.Dispose()

let main () =
  // prepare our context and sockets
  use context   = new Context ()
  use frontend  = Context.router context
  use backend   = Context.dealer context
  Socket.bind frontend  "tcp://*:5559"
  Socket.bind backend   "tcp://*:5560"

  let transfer inbound outbound =
    use message = new Message ()
    let rec loop () =
      // process all parts of the message
      Message.recv message inbound
      if Message.hasMore message
        then  Message.sendMore message outbound
              loop ()
        else  // last message part
              Message.send message outbound
      dispose message
    loop ()

  // initialize poll set
  let items =
    [ frontend |> pollIn (fun _ -> transfer frontend backend )
      backend  |> pollIn (fun _ -> transfer backend  frontend) ]

  // switch messages between sockets
  while items |> pollForever do ((* nothing *))

  0 // return code
module docs
module PATH

from docs
val hijack : unit -> unit

Full name: docs.PATH.hijack
namespace fszmq
module Polling

from fszmq
val dispose : o:System.IDisposable -> unit

Full name: Rrbroker.dispose
val o : System.IDisposable
namespace System
type IDisposable =
  member Dispose : unit -> unit

Full name: System.IDisposable
System.IDisposable.Dispose() : unit
val main : unit -> int

Full name: Rrbroker.main
val context : 'a
val frontend : fszmq.Socket
val backend : fszmq.Socket
val transfer : ('a -> 'b -> unit)
val inbound : 'a
val outbound : 'a
val message : 'a (requires 'a :> System.IDisposable)
val loop : (unit -> unit)
val items : fszmq.Poll list
val pollIn : fn:(fszmq.Socket -> unit) -> socket:fszmq.Socket -> fszmq.Poll

Full name: fszmq.Polling.pollIn
val pollForever : items:seq<fszmq.Poll> -> bool

Full name: fszmq.Polling.pollForever
val release : unit -> unit

Full name: docs.PATH.release
Fork me on GitHub