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

What is the difference between a topic and a message?

asked 2013-05-26 03:23:50 -0600

cbgrey gravatar image

A very newbie question for sure, but I'm having a little trouble distinguishing between topics and messages. I understand that topics are the named "channels" published and subscribed by nodes and messages are the details of the data carried on the topics so they seem like pretty much the same thing. Can you ever have multiple message types sent across one topic? If not then why the distinction between the two?

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted

answered 2013-05-26 04:32:33 -0600

updated 2018-07-23 08:29:20 -0600

As you said, the topic is the channel where nodes are subscribed for to read messages or where the nodes publish those messages. The topic can be seen as a tag of certain type of data, and the message is the data itself, previously defined. Also, another reason for the difference between topic and message is that you can use two topics that share the same type of messages.

For Example:

Topics: Front_Laser_data, Rear_Laser_data

Message: int readings[]

edit flag offensive delete link more



Ah, it's the fact that different topics can share the same message type I was missing. Thanks.

cbgrey gravatar image cbgrey  ( 2013-05-26 06:17:52 -0600 )edit

answered 2013-05-26 04:18:29 -0600

Topic is a channel - you are correct, but additionally to a name topic can transmit only the messages of a particular type. Thus, a message to be sent across this channel should have the same type.

Imagine that you have a square pipe (this will be a channel-topic) and a set of cubes (these are messages). All the cubes have same dimensions, but different colours, and even some of them have letters engraved. So the 'square' will be the type of a message and colours and letters will be the contents of that message. That means you cannot send (publish) or receive (subscribe to) 'circle' and 'triangle' messages on that topic.

edit flag offensive delete link more


Very intuitive, thank you

aaditya_saraiya gravatar image aaditya_saraiya  ( 2017-08-26 09:49:08 -0600 )edit

Great answer.

tuan gravatar image tuan  ( 2019-09-18 04:27:28 -0600 )edit

answered 2013-05-26 04:54:04 -0600

amine23 gravatar image

updated 2013-05-26 04:55:02 -0600

We have messages, and every message has a message type.

Now, every defined topic should have one of those types, so publishers/subscribers to the topic can send/receive messages, of different values but of the that same type, through the topic.

edit flag offensive delete link more

Question Tools


Asked: 2013-05-26 03:23:50 -0600

Seen: 10,876 times

Last updated: Jul 23 '18