Hi All,
currently we do some research in how we can do implement the classical Publisher/Subscriber pattern using ASIO. We had one thread that produces some kind of a message and like to send it out to 1 to n subscribers via TCP, where n is < 5. Message rate will be up to 800 Hz. My first idea is that the producer thread puts the message in a blocking queue. On the other end a consumer thread waits, takes the message and send it to the subscribers via synchronous or asynchronous send. One requirement is, when one connection blocks (because their client is buggy/hangs) it’s ok to drop messages for that connection, but we should deliver to the other subscribers. It’s also a one way communication from publisher to subscriber.
Can someone provide some hints for best practices / design patterns / comments please?
If I show up with some other lib like ZeroMQ my colleagues will fry me, so it’s the easiest to use boost also for that task….
Best,
Ingo
>> Can someone provide some hints for best practices / design patterns / comments please?
You are just scratching the surface. I wrote a small pub / sub library designed for (mostly) static configs / connections, with “mesh” connections, with static (startup) topic discovery (currently no “dynamic” topic discovery), which is working well. But it’s a limited library, and has drawbacks for general use.
I just mentioned “topics” – most pub / sub messaging has the concept of topics, which provide the “glue” between the publishers and subscribers.
Check out the OMG DDS specs (http://en.wikipedia.org/wiki/Data_distribution_service), and you might want to also check out a proposed Boost library named Channel (http://channel.sourceforge.net/).
There’s also many other possibilities in the pub / sub space.
Cliff