A ZMQ subscriber socket keeps only the last message in queue when the CONFLATE option is set to true. (zmq_docs) However, it does not seem to be working for me. Typically in python i would do something like the following and it would work:
context = zmq.Context()
subscriber = context.socket(zmq.SUB)
subscriber.setsockopt(zmq.CONFLATE, 1)
subscriber.connect("tcp://localhost:5555")
The subscriber in pub/sub pattern below simply ignores the CONFLATE option set to 1. You can observe by the minute and second being displayed on the subscriber that the program is tied up as it is processing old messages (fib 42). If fib is set to a trivial value, you can see that the subscriber is indeed receiving messages from the publisher.
Here is the publisher:
open System
open fszmq
open fszmq.Context
open fszmq.Socket
let funcPublish () =
use context = new Context()
use publisher = pub context
"tcp://*:5563" |> bind publisher
while true do
let tm = System.DateTime.Now
let t = String.Concat([tm.Minute.ToString(); " "; tm.Second.ToString()])
t |> s_send publisher
sleep 1
EXIT_SUCCESS
[<EntryPoint>]
let main argv =
funcPublish ()
0
And here is the subscriber:
open fszmq
open fszmq.Context
open fszmq.Socket
let rec fib n =
match n with
| 1 | 2 -> 1
| n -> fib(n-1) + fib(n-2)
let funcSubscribe () =
use context = new Context()
use subscriber = sub context
"tcp://localhost:5563" |> connect subscriber
Socket.setOption subscriber (ZMQ.CONFLATE, 1)
[ ""B ] |> subscribe subscriber
while true do
let contents = s_recv subscriber
fib 42
contents |> printfn "%A"
EXIT_SUCCESS
[<EntryPoint>]
let main argv =
funcSubscribe ()
0
Thanks.
Socket.setOptionline to before yourconnect subscriberline in your F# code? Does that solve your problem? - rmunn