This is an enhancement issue based on the discussions about this question: http://answers.ros.org/question/11167/how-do-i-publish-exactly-one-message
The problem that my colleague and I experienced is that the first (few) messages published were "lost". In our case, we wanted to publish exactly one message and not more. The problem with ROS is that the publisher starts sending its messages as soon as it exists, without waiting for the subscribers to establish a connection. This is acceptable in some cases, but not in many others.
Here is my suggestion:
Calling NodeHandle::advertise eventually gets to line 403 of topic_manager.cpp: master::execute("registerPublisher", args, result, payload, true); Currently, the variable result is ignored, but it should contain the total number of subscribers for the given topic. I would also add an optional parameter in advertise() that would be a duration. Then, we a publisher would be created, it would wait for the subscribers to connect, up to the given duration. Any call to Publisher::publish before that would queue the message.
This solution is not fail-proof, but at least with a timeout option, it would increase the reliability when required and still allow not to wait (or not to wait too long) for other cases (by giving zero as a timeout duration).