Rosanswers logo

Hi everyone. Recently I met a question when I read something about "latch" in Publisher. On the Publisher wiki page, "latch" is described as:(http://wiki.ros.org/rospy/Overview/Publishers%20and%20Subscribers)

    "Enable 'latching' on the connection. When a connection is latched, the last message published is saved and sent to any future subscribers that connect. This is useful for slow-changing or static data like a map."

Now I am so confused that [when a node subscribes a message from a topic, will this message disappears? If not, than what is "latch" for? Anyhow the last message will NOT disappear.]

PS. I have done some experiments. When several nodes subscribe a same topic, they always get the same messages content from that topic. And this can also explain how qrt_plot works.(It always subscribe messages from some topics but it never affects other nodes working)

Originally posted by pcler on ROS Answers with karma: 35 on 2014-10-20

Post score: 3


1 Answer 1


Rosanswers logo

I don't know what you mean with "disappear". The documentation doesn't use this word and it doesn't make any sense to have messages disappear on purpose.

The feature of latching makes sure that a new subscriber always gets the last message that was published even if the message was published before the subscriber was connected. Text in bold is the difference to an unlatched connection.

Originally posted by dornhege with karma: 31395 on 2014-10-20

This answer was ACCEPTED on the original site

Post score: 7

Original comments

Comment by pcler on 2014-10-22:
Thanks!!! Your answer helps a lot! Actually, I am thinking about the data structure of "topic". At first I think it is a STACK. "Subscribe" is like POP and "publish" is like PUSH. That's why I said "disappear". But now I think it is more complicated. Would you mind telling me how "topic" works?

Comment by dornhege on 2014-10-23:
This explains the misunderstanding. Topic is not a data structure at all. A topic doesn't exist anywhere on its own. As a concept it is a common name for two nodes to connect to each other. The data is only in the nodes. Therefore if a node isn't running yet it cannot send or receive data.

Comment by pcler on 2014-10-26:
Thanks again! It helps! Best Wishes!

Comment by sam26 on 2017-02-08:
so , if we set latching to particular period of time , say 10 seconds , does it mean that if a new subscriber connects to this node within 10 seconds , it receives the last message from the last connection of the publisher ?

Comment by dornhege on 2017-02-15:
There is no time limit.

Comment by buckley.toby on 2018-09-11:
I have an additional question: if you start a node and publish to a latched topic but then kill the node which did the original publishing, will the data still be available for future subscribers? Thanks!


Your Answer

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