The code above is an example of MQTT publish and subscribe.
MQTT publish service: I have used the example of a smartwatch. As soon as the data comes into the smartwatch, it will be published to the MQTT topic.
MQTT subscribe service: This service will subscribe to that MQTT topic and consume the data. It will print the data on the screen.