nats-io / nats.net

Full Async C# / .NET client for NATS
https://nats-io.github.io/nats.net
Apache License 2.0
251 stars 51 forks source link

Proposal: Real-World Examples and Setup for Long-Lived Services #568

Open mtmk opened 3 months ago

mtmk commented 3 months ago

Problem Statement: Users coming from other messaging platforms (e.g. RabbitMQ, Masstransit) might find it challenging to register NATS constructs (e.g. consumers) and process messages in the current setup. Most examples and samples provided are overly simplistic, often showcasing a single consumer in a console application. There is a need for more realistic examples, particularly for long-lived services with multiple consumers.

Proposed Enhancements:

Benefits:

Kunal-Thakur commented 3 months ago

I am facing a similar problem while running multiple NATS jetstream consumers as background operations in .net webapi. Feel like dependency injection operations would also be difficult in this. Comming from Masstransit RabbitMq world implementing these operations are quite easy over there.

robertmircea commented 3 months ago

Suggestions for samples:

to11mtm commented 2 months ago

I just came up with a fun/useful idea!

General thought, what if we could use Jetstream and/or KV (I'm thinking primarily KV here) for implementing a JWT jti token validator?

As a background, jti is an optional field in JWTs intended to prevent replay of a token; if included it is expected to be used only once across the auth context.

My general thought being, a service could take in JTIs along with an expiration time, and then return whether the JTI has been used or not. The assumption being, the consumer will be pre-checking expiration as part of normal JWT flow, so one could set an expiration time on the buicket of the ceiling for JWT lifetime.

I'm pretty sure it would be fairly easy to wire up, also could be expandable to something like 'use NATS in ASPNETCORE middleware' case.

(I'm willing to give this a crack but if someone else wants to beat me to it, all the better.)

Jarema commented 2 months ago

Those are some great examples to consider! Some are very .NET specific, but most are general NATS challenges, that can be fact by using any client. I would love if those ideas were somehow realized in a way, that provides a solution in each major client.

Maybe a section in https://natsbyexample.com that is focused on Real-World examples would be a good idea, maybe some other medium.