Event manager/message bus in Haskell

I’m looking for a Haskell implementation of an event manager/message bus.

Basically something like the following

data EventManager = ...

attach :: EventTag -> (Event -> m ()) -> EventManager -> EventManager

trigger :: EventManager -> EventTag -> Event -> m ()

which would allow to trigger events and react to them with some listeners.

Would be nice if it allowed to persist events with multiple storages and if it allowed both synchronous and asynchronous listeners.

Is there something like this in the Haskell ecosystem? I tried to search for it on Hackage, but was not able to find something relevant

2 Likes

You probably can dig something out of hackage if you look hard enough, but I’d be inclined to roll my own and call it a day: A simple, functional event manager. · GitHub

1 Like

That’s the current option…

defining the interface of the Event Manager is the easy part, handling well both synchronous and asynchronous messages and allowing different persistence mechanisms is the hard/tedious part

Well, I think you can leave synchronicity to the user? As written above, the work happens on the thread that triggers it, but both attach and trigger have the option to forkIO or send the job to a worker.

Re persistence, I’m honestly not sure what you’re looking for (or why).

When I write asynchronous, I mean it could be done hours later. That means that it needs to be kept/persisted somewhere in the meanwhile. The burden of handling this should not be on the end user, but the library should provide some configuration/helper to say something like handle this job asynchronously using Postgresql/Kafka/… as a persistence mechanism

Do you mean that it should persist, even if the program stops and later restarts?

yes, or at least you should have the option to make that happen

1 Like

Hmmm, that’s a pretty involved ask.Though I feel it’s also kind of something that we made at our company, so I definitely understand the want for it.
I guess this is indeed something useful that would be great if added to the ecosystem in a way that’s modular and easy to use by different people in different circumstances :thinking:

1 Like

At that point I would go for something like Kafka