Now that you pushed the messages to a topic, you will learn how to read or consume the messages that have been sent to this topic. The Jupyter Notebook used in this segment is attached below.
Let’s look at the Python code to read the messages from the topic.
In the previous video, you learnt how to read messages from a topic. For this, you need to provide the name of the topic, group id, bootstrap servers and a parameter called auto_offset_reset, the value for which was set to earliest. This means that it will read messages from the oldest messages. You can also set this to ‘latest’.
All the message were stored in the variable named consumer. For each message that was stored in this variable, we printed the name of the topic in which this message was stored, the partition number in which the message was stored, the offset ID as well as the key and the value of the message.
We also observed that as we pushed an increasing number of messages, of messages, the offset ID of the messages was continuously increasing.
Report an error