What to use to have pubsub buffer and backlog

I do use pubsub a lot in my app and I was wondering what was the easiest way to get older messages based on rules.

For example, I’d like to do something like this:

PubSub.subscribe(Box.PubSub, "music", replay_messages: rules)

Where rules would be something to specifiy what messages to replay. What I need is:

  • last N
  • lasts since date
  • matching pattern, for example: {:track_change, track}

combinable (last 5 messages since one hour ago matching pattern …)

Do you know any existing library that can do that, or should I roll my own?