Some time ago I developed a TeslaScada2 application that used an Arduino client monitoring a number of switches and controlling several motors. The communications between the TeslaScada2 and the Arduino was via an MQTT broker. Since Arduino is the same technology as ESP8266 and ESP32, then the answer to your question has to be yes. Take a look at MQTT options.