Add `flush_messages` function and remove `EventReceiver` type

This simplifies the API and makes message flushing more generic.
Update examples
Merge pull request #124 from bjz/flush-iterator

Add `flush_messages` function and remove `EventReceiver` type