Question

I recently discovered the wonderful world of zeromq and all of its work that it's doing for the developer - awesome! Digging deeper and deeper into the guides and handbooks leaves me with a question: How can I set the reconnect interval in C# by myself?

I know that there is something like

using (ZmqSocket subscriber= context.CreateSocket(SocketType.SUB))
{
    subscriber.ReconnectInterval = new TimeSpan(hours: 0, minutes: 0, seconds: 30);
    subscriber.ReconnectIntervalMax = new TimeSpan(hours: 0, minutes: 1, seconds: 0);
}

and that zeromq is performing reconnects every 100ms by default, but what if I want to change the interval to a bit more, like, 30 seconds? I actually tried the snippet from above - but it dont work for me anyways. There are still attempts to reconnect 10 times a seconds.

Also: how can I set the reconnect interval to "-1"? ZeroMQ guides says (for language C)

The value -1 means no reconnection.

But how can I set a Timespan in C# to "-1" (or the zeromq-needed equivalent)?

Was it helpful?

Solution

Ok, I think I got this by myself this way:

public static void DisableReconnect(this ZmqSocket socket)
{
   socket.ReconnectInterval = TimeSpan.FromMilliseconds(-1);
}

Built an extension for the socket class and did exactly what the C-interface expects: -1 milliseconds. MSDN library says that -1 milliseconds is not possible (and results in an exception) but it worked for me so far!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top