ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

Does a node receive messages sent by itself on a topic that it is both publishing and subscribing to?

asked 2016-04-30 04:21:31 -0600

luketheduke gravatar image

updated 2022-02-22 11:26:51 -0600

lucasw gravatar image

I am working on writing some code for a project, but I have a node that will be continuously publishing(30 Hz) to a topic while also subscribing to the same topic to listen for a different pub from a different node. Basically, node A is listening to topic X and publishing to topic X. Meanwhile another node, node B, will at some time, publish a message to topic X. Will the subscriber callback in node A be triggered every time it publishes sometime? Also, will it be able to pick up the message if node B only publishes once? Thanks, luketheduke

edit retag flag offensive close merge delete


May I suggest a title change? Your question seems to be really about whether a node receives its own messages if it publishes on a topic it also subscribes to. You can't actually 'receive callbacks', just messages.

gvdhoorn gravatar image gvdhoorn  ( 2016-05-01 01:29:16 -0600 )edit

Thanks for the suggestion! It's changed.

luketheduke gravatar image luketheduke  ( 2016-05-01 13:30:07 -0600 )edit

1 Answer

Sort by » oldest newest most voted

answered 2016-04-30 04:33:39 -0600

If a node publishes on a topic and also has a subscriber for it, it will receive "it's own" message. This is a feature, as components in the publish/subscribe system should not need to care about where a message originates from.

Even though this probably is best avoided, you can check for the origin of a message using the MessageEvent mechanism (e.g. if it originates from the same node) as in this example.

edit flag offensive delete link more


Thanks for the quick reply!

luketheduke gravatar image luketheduke  ( 2016-04-30 04:42:51 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2016-04-30 04:21:31 -0600

Seen: 1,614 times

Last updated: May 01 '16