ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Is it possible for a subscriber to miss a message

asked 2019-01-21 09:17:59 -0500

max11gen gravatar image

Consider having a publisher publishing at a set rate and a subscriber that calls a callback on the published topic that stores all the data in an array. Is it possible that the publisher publishes mutliple messages before the subscriber callback is called? And if that is possible and happens: Is the callback called on each new message or just on the most recent message?

If that's important here: The publishing node is a rosbag, that I didn't create myself. The subscriber node constructs an object of a class that defines all the callbacks and then calls spin().

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2019-01-21 09:35:55 -0500

NEngelhard gravatar image

Your keyword here is the queue: how-do-publishersubscriber-message-queues-work

short version: If you publish faster than the subscriber can process (or queue) the messages, they are discarded.

edit flag offensive delete link more


So if my Publisher and my Subscriber have a queue size of 1000 and I know that the total amount of messages published will never exceed 100, I can be sure, that my subscriber will call its callbacks on every single message, right?!

max11gen gravatar image max11gen  ( 2019-01-21 09:50:28 -0500 )edit

You should get all messages (but there is no guarantee), but only if your publisher's queue also is big enough. If it's so important, then you should also look at the rosbag API, so you have a much better control over what is happening.

NEngelhard gravatar image NEngelhard  ( 2019-01-21 10:35:46 -0500 )edit

Thanks a lot, i‘ll read into the rosbag API but probably „should get“ will be sufficient for me.

max11gen gravatar image max11gen  ( 2019-01-21 10:53:42 -0500 )edit

Question Tools

1 follower


Asked: 2019-01-21 09:17:59 -0500

Seen: 1,914 times

Last updated: Jan 21 '19