richardmillen / zguide-examples

Implementations of the 0MQ examples in the guide.
http://zguide.zeromq.org/page:all
4 stars 0 forks source link

Last Value Caching in C++ #25

Closed richardmillen closed 7 years ago

richardmillen commented 7 years ago

Implement the Last Value Caching example.

If you've used commercial pub-sub systems, you may be used to some features that are missing in the fast and cheerful ZeroMQ pub-sub model. One of these is last value caching (LVC). This solves the problem of how a new subscriber catches up when it joins the network. The theory is that publishers get notified when a new subscriber joins and subscribes to some specific topics. The publisher can then rebroadcast the last message for those topics.

richardmillen commented 7 years ago

I ran this with 10 subscribers, left it for 20 minutes and came back to find 1 subscriber had shut itself down with the following output:

$ ./pathosub localhost:5558
pathosub (72516): connecting to 'tcp://localhost:5558'...
pathosub (72516): subscribing to topic '15'...
pathosub (72516): Save Roger!
pathosub: bug: '159' is not equal to '15'.

I'll re-test but without the lvcache running.

richardmillen commented 7 years ago

No need to wait this time. I got this within 10 seconds of running the first subscriber:

$ ./pathosub localhost:5556
pathosub (68084): connecting to 'tcp://localhost:5556'...
pathosub (68084): subscribing to topic '11'...
pathosub: bug: '115' is not equal to '11'.

This was subscribing directly to the publisher i.e. without the lvcache in the middle.

richardmillen commented 7 years ago

It's interesting to see that in both instances the incorrect value received starts with the correct value...

i.e.

159 instead of 15 & 115 instead of 11.

richardmillen commented 7 years ago

I believe this is simply a design flaw in the example itself.

It would be simple to fix - just make sure the pub/sub topic is limited to 3 digits i.e. 100-999.