Exploring Effect for Integration Events Communication Between Bounded Contexts

Hello,

I wanted to try and use Effect to handle my integration events to enable the communicate between my bounded contexts in a nice manner.

I had a look at PubSub and figured it could be a nice tool for that. However (I guess I am tired) I do not manage to really understand how I can use it to do what I want.

Basically I'd love a integrationEventsPubSub to be created at server boot time. Then having some subscribers to... subscribe to it.

And having the pubsub dequeue/broadcast regularly events every time some events are published.

I am uisng a platform called gadget, relying on fastify, that do not let me touch much thing regarding how the fastify instance is set up.

However they give access to what they call "Boot plugins" which are some simplified server customizations.

So I have something like this:
import { PubSub } from "effect";

import { IntegrationEvent } from "#server/contexts/sharedKernel/infrastructure/schemas/integrationEvents/integrationEvent";

import { Server } from ".gadget/server/types";

export default async function integrationEventsPubSub(server: Server) {
  const integrationEventsPubSub = PubSub.unbounded<IntegrationEvent>();

  server.decorate("integrationEventsPubSub", integrationEventsPubSub);
}


And then I should be able to subscribe from it using server.integrationEventsPubSub however I am unsure how to dequeue regularly the events using effect.
Should I have some kind of setInterval calling Queue.takeAll ?

Could someone point me to an example I missed on github or anything?

Sorry if it feels like a dumb question but I did not manage to do what I wanted from the effect.website doc page
Was this page helpful?