Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using NATS as backend for Mercure API/Protocol? #847

Open
nickchomey opened this issue Dec 15, 2023 · 6 comments
Open

Using NATS as backend for Mercure API/Protocol? #847

nickchomey opened this issue Dec 15, 2023 · 6 comments

Comments

@nickchomey
Copy link

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!

@dunglas
Copy link
Owner

dunglas commented Dec 15, 2023

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!

@g41797
Copy link

g41797 commented Dec 16, 2023

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?

@dunglas
Copy link
Owner

dunglas commented Dec 16, 2023

@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

@nickchomey
Copy link
Author

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

@g41797
Copy link

g41797 commented Dec 16, 2023

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

@nickchomey
Copy link
Author

nickchomey commented Dec 16, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants