Publishing on a topic with retain flag set will store a message on a specified topic permanently. With MQTT5 you could also specify message expiry so message would get deleted automatically after specified time. Depending on the broker configuration the data could stay persisted after server restart. It will work on any MQTT broker, but for testing you can run Mosquitto in Docker:
docker run -d -p 1883:1883 eclipse-mosquitto:1.6.14