1) Create a B4J Application which has MQTT Server that exposes port {#port} and it also has an MQTT client impemented and that has access to DB
2) Connect the B4J client to 127.0.0.1:{#port} and subscribe to channel "CHANNELNAME"
3) Connect ESP8266 to this server with rMQTT library and subscribe to channel "CHANNELNAME"
4) When someone posts to this MQTT server to channel "CHANNELNAME" a JSON for example like
{"cmd":"send", "value": 1}
it will parse the json and according to cmd it will save to the DB
5) The ESP8266 wakes up and publishes to this MQTT server to channel "CHANNELNAME" a JSON for example like
{"cmd":"pull"}
, the MQTT server gets the message and according to the cmd it will pull the last value that was saved and post it through the MQTT client to channel "CHANNELNAME" with a JSON for example
{"cmd":"resp_pull", "last_cmd_id": 1, "value": 1}
. The ESP8266 waits some milliseconds to get the answer, saves it to the EEPROM and goes to sleep again until the reboot.
6) Next time the ESP8266 wakes up it reads the json saved in the EEPROM and creates a new json like
{"cmd":"pull", "last_cmd_id": 1, "value": 1}
and publishes it to the B4J app and if the last_cmd_id is lower than the last cmd id that was saved in the DB the same thing happens again as before (B4J app reads last saved value -> B4J MQTT client posts -> ESP8266 receives -> ESP8266 writes to the EEPROM the response and goes to sleep).
7) Goto 6 again and again. This command is for the MCU but you can continue to the next line
8) Have fun programming it
P.S. There is a catch though in this solution but there is no other solution - at least that I can think of. You will be able to write to EEPROM only around 100000 times and then it will not work but you can extend EEPROM's working time by not saving anything to EEPROM if the response of "last_cmd_id" is the same as the one that has been saved in the EEPROM.