If you are using ESP32, I recommend exploring Xedge32, as it simplifies the design of secure MQTT edge solutions. The following tutorials list includes several MQTT projects: https://realtimelogic.com/xedge32-tutorials/
And don't forget to read how horrible MQTT can be if you do not set it up correctly: https://realtimelogic.com/articles/How-Hackers-Can-Easily-Pe...