In my experience, there are some valid situations where people tend to repeat themselves, where if you are aware, you can be of assistance to the person's needs and not be frustrated yourself.
First situation, as others have already noted, are when talking with the elderly. If the individual suffers from dementia, their short term memory is shot - so when retelling stories, they will forget what they've already said and hence repeat themselves often. If this is the situation, be patient, listen to each iteration as if it's the first time you are hearing it. Often the individual is aware they have these memory issues and when people become frustrated, it only makes them feel worse, and the symptoms get worse under stress. They feel bad because they know they must be repeating themselves, but cannot control it, which frustrates them more. By being patient and putting them at ease, they will be less stressed and happy, which won't make the symptoms worse than they already are.
The second situation, and this typically impacts women more than men, is times of overwhelm/stress. When a woman is overwhelmed, by nature, they need to vent the stress. The venting process is often retelling the situation(s) that are causing the stress over and over until the stress is released (mush like venting steam from a pressure cooker). If your friend/family appears to be venting - the best thing to do is simply be a sounding board. Whether they are aware they are venting or not, typically they just need someone to listen to them and empathize - they are not really looking for solutions. Once the venting is over and their emotions level off, the repeating should stop.
Regarding the not listening issue - some people just are not good listeners. If this is the case, and they are a friend or family - let them know how you feel. If they are unaware that they are not reciprocating by listening to you when you need it, sometimes by making them aware of this behavior gives them the opportunity to change their behavior to be a better listener. If, however, they have no interest in improving - just make a mental note that if you need someone to listen to you, this is not the person to go to. Accept them for who they are and find someone else who will be an attentive listener.