#[Microservices/Kafka] One producer with multiple consumers

6 messages · Page 1 of 1 (latest)

gaunt ivy
#

Hello!
I'm very new with microservice implementation. Been testing for a couple days and have successfully emitted events from one MS to another (example service injection attached in the image)

As you can see in that image I'm simply injecting the MS token, but wondering about what happens when having more than 2 microservices listening to a same event. Is there a way to publish one event for many to listen, plus avoiding having to inject a MS token for every client on .service files?

I feel like this is related to consumer group ids, but still not sure about the token injection part. Would appreciate some guidance 🙏

thin hawk
#

I have same question.

steel flume
#

This is not entirely related to NestJS microservices, but rather to how Kafka actually works

#

read up on topic partitions and consumer groups

#

The client injection is also completely separate from the consuming. You can have an app with only kafka publisher (Client) and with only consumer (event pattern decorators). NestJS actually creates 2 connections to the Kafka broker, one for each part.

#

So you only need to inject the client in services where you want to emit messages (you can also wrap it in another class which gets injected instead, so you don't need to use Inject everywhere)