Rosanswers logo

These slides introducing ROS subscribers/publishers on slide 7 are saying that one topic can have multiple subscribers/publishers. If you scroll down a bit in the official tutorials here you can see the actual protocol for establishing connection between single subscriber and publisher. My question is, in case you have multiple publishers to a single topic, how does the communication changes in order to handle these publishers? Does one publisher blocks until the subscriber is ready to process more messages? Are the process messages handled using a queue? How is the second connection established? What if there are many-to-many relationship between the subscribers/publishers? Are the subscriber just removing msg-s from a queue and publishers pushing msgs on the queue? Can this queue overflow (if there is a queue at all)?

More in depth documentation of the subscriber/publisher architecture is acceptable as an answer. Also if you know the answer of some of the questions it will be helpful as well.

Thank you, much appreciated!

Originally posted by Anton Belev on ROS Answers with karma: 15 on 2015-01-27

Post score: 0


1 Answer 1


Rosanswers logo


As far as I know, there is no publication on a topic if no node has subscribed to it. When there is at least one, message are published depending on the rate of publishing node.

If there are two nodes publishing on the same topic, messages will come one after the other in a non-predictable order. The subscriber will get these messages as they come. It may be conflicting (if you have a movement control node and the teleop node publishing speeds to the low-level controller, your robot may move strangely).

About queues :

ros::Subscriber subscribe(const std::string& topic, uint32_t queue_size, <callback>, const ros::TransportHints& transport_hints = ros::TransportHints());

the queue_size argument tells the node how many messages it should keep before erasing the oldest one. A value of 1 will keep the last message received. I guess that all subscribers having a queue_size on 1 means that you have at most "Nb of Callbacks" messages to process when spinningOnce.

So for you two last questions : subscribing nodes handle their own callbackQueue that is being processed when spinning. It can overflow if publishers are faster that subscribers and callback processing.

I let someone more used to the precise mechanisms of ROS give more details.

Originally posted by Erwan R. with karma: 697 on 2015-01-28

This answer was ACCEPTED on the original site

Post score: 2

Original comments

Comment by Anton Belev on 2015-01-28:
Thank you! That's helpful.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.