mercure icon indicating copy to clipboard operation
mercure copied to clipboard

Using NATS as backend for Mercure API/Protocol?

Open nickchomey opened this issue 2 years ago • 6 comments

My application architecture revolves around NATS and I would like to add an SSE + Ajax mechanism to communicate with browsers. I also intend to switch my php webserver from Litespeed to Frankenphp.

Given that NATS already has considerable pubsub capabilities and that Mercure is already integrated with Frankenphp, I'm wondering if I could use Mercure's api/protocol to communicate with the browser but use NATS as the pubsub backend.

Does this seem like it would be possible? If so, could you point me towards the parts of Mercure's code that I would need to modify? I'm happy to contribute this back to the project if I get it working. I understand, however, if it isn't something that you're interested in.

Thanks!

nickchomey avatar Dec 15 '23 12:12 nickchomey

This is planned in the on-premise (nonfree) version! I'll let you know as soon as this feature is available. We don't include clustering transports in the free version, but distributing them as standalone packages is of course totally ok if you want to contribute them!

dunglas avatar Dec 15 '23 15:12 dunglas

as far as i understand, mercure uses boltdb as events store are you going to use external broker (nats, memphis, kafka, etc ) for this purpose? looks like mercure needs plug-able storage support what do you think?

g41797 avatar Dec 16 '23 14:12 g41797

@g41797 it already has a pluggable transport support, and many transports supporting clustering as available in the paid version: https://mercure.rocks/docs/hub/cluster

dunglas avatar Dec 16 '23 16:12 dunglas

Any guidance you could provide on how to at least start implementing something like this (a particular file and class to look at?) would be much appreciated! Though I completely understand if you prefer to keep that close to the chest for your paid on prem versions

nickchomey avatar Dec 16 '23 17:12 nickchomey

i have no clue regarding clustering, but i can try to develop support for nats js and memphis your turn

g41797 avatar Dec 16 '23 18:12 g41797

I think I'm starting to understand now. Each "backend" - bolt, local, redis, Kafka, postgres - is implemented via a Transport The bolt and local ones are included in this repo, and the cluster ones are provided when you pay for the on prem version.

So, a NATS Transport would need to be made, using the Transport.go file as a starting point (and the bolt and local ones as reference). I figure it would involve importing the nats.go client in the Transport to create a connection and relay the pubsub requests.

I'll poke around to see what I can figure out. I've always wanted to learn Go, so this is a good opportunity to get started. I expect that Copilot Chat will be helpful here if I add the repos to a workspace and open the transport files.

nickchomey avatar Dec 16 '23 20:12 nickchomey