Confused about publishing msgs in a synchronous way
Hello,
I'm studying the communication of ROS recently. And I saw this article Choose a good queue_size, which tells that the rospy can publish msgs sychronously by setting queue_size=None
or omitted.
pub = rospy.Publisher('topic_name', std_msgs.msg.String, queue_size=None)
pub.publish("hello world")
I tried to set queue_size=None
, but the publisher is not blocked. It publishes whether there is a subscriber. Both pub and sub are asynchronous.
And I read that publish()
in roscpp is totally asynchronous. And one introduction says *The asynchronous nature of publish/subscribe messaging works for many communication needs in robotics, but sometimes you want synchronous request/response interactions between *
These articles really confuse me. So I just want to ask :
- Can msgs be published to a topic in a synchronous way?
- If it can, can you give me an example?
I think the documentation means to say: invoking
publish(..)
is synchronous, not that messages are exchanged in a synchronous manner. For that, we have services (or actions).Can you please explain invoking publish(..) synchronously ?
I thought that in Topics, everything is asynchronous. And it is Service or Action synchronous.
I think that the documentation/wiki is probrably wrong (... and/or it is only supported in older versions of ROS. According to the docs, since >= Indigo, you get a warning). AFAIK, topic are always asynchronous and you have no control of when your message is actually being send over the wire.
There is a difference between queueing a message and the middleware transmitting your message. I think the documentation talks about the former, while you are referring to the latter.
@gvdhoorn: I don't think so because queuing a message (= calling
publish()
) is always synchronous in ROS.