Obtain retained MQTT message I’m using ESP8266 with Arduino code. Each device posts a ‘state’ and an ‘avail’ messages for a specific topic. 

I wish to be able to read those retained messages and not only right after connecting and subscribe to MQTT broker. 

EDIT 1  - Clarifications


I'm using Raspberry Pi Zero W as a MQTT Broker ( Local ).
When device boots, it changes its state from offline to online, but a different process checks periodically if state is offline or online for current device and others on the network.
it is not same as when subscribing to a retained topic, that you get the state at that specific time.
Storing chage of state in a variable, is one way to do it, but is there a different way ?
Once a message has passed through an MQTT broker there is not a way to retrieve it from the broker.

Consider instead deciding upon the action at the time the message is received by the subscriber.  If this decision needs to be made at a later time consider storing the state in the of the payload of the message on the subscriber.

Also consider running Node-RED.  If the platform running the MQTT broker can support Node-RED (such as a Raspberry Pi), it turns out to be convenient to run both on the same computer.  Node-RED contains nodes (graphical programming blocks) which can subscribe to and publish to MQTT topics.  By connecting other nodes to these, the topic and payload can be manipulated.  Of interest is an option within the Output MQTT node.  Here you can select Retain True.  This page explains how this option works:


  Once you have sent a retained message to a topic, all subscribers will
  receive that message when they subscribe.
  
  To clear a previously retained topic from the broker, send a blank
  message to that topic with the retain flag set.