-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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
Define specific client in MessagePattern decorator (microservices) #11298
Comments
UPD: app.connectMicroservice({
transport: Transport.NATS,
options: {
servers: [`nats://${process.env.FIRST_NATS_HOST}`],
serializer: new OutboundResponseExternalSerializer(),
deserializer: new InboundMessageExternalDeserializer(),
},
});
app.connectMicroservice({
transport: Transport.NATS,
options: {
servers: [`nats://${process.env.SECOND_NATS_HOST}`],
serializer: new OutboundResponseExternalSerializer(),
deserializer: new InboundMessageExternalDeserializer(),
},
}); For a better flexibility there must be feature to specify microservice client ID/unique name to inject it into DI (like in case with ClientsModule) that can be used in |
Would you like to create a PR for this feature? |
I guess so. I'm not sure about what is more declarative way to define key for client ? Is the same definition like in |
I have a similar issue where I have two MQTT brokers and I would like to have some context about which broker the message came from. The concept of named transports would be useful here along with some way of getting that information via a decorator. |
I found some way to solve it temporary. Looks like it is working but code isn't beautiful import { mixin } from '@nestjs/common';
import {ServerNats } from '@nestjs/microservices';
import { EVENTS_CLIENT, SCHEDULER_CLIENT } from './symbols';
export const NatsCustomStrategy = (transport_symbol: symbol) => {
// eslint-disable-next-line @typescript-eslint/ban-types
return function <T extends { new (...args: any[]): any }>(constructor: T) {
const new_class = class extends constructor {
transportId = transport_symbol;
};
const mixed_classes = mixin(new_class);
return mixed_classes;
};
};
@NatsCustomStrategy(SCHEDULER_CLIENT)
export class NatsSchedulerClient extends ServerNats {}
@NatsCustomStrategy(EVENTS_CLIENT)
export class NatsEventsClient extends ServerNats {} Depends on your transport you can replace |
I got same issue about kafka client. I want to consume samely named topics from two different kafka. but, that two topics are on different kafka broker(not replica set) each other(and function is different too). In this case, @MessagePattern('topic') is applied both of them Although I want to use different function logic(post-processing). so It needs to seperate different client id. |
I'm interested in this feature as well. My use case is distributing one message across all instances connected to the same topic. I have one consumer who uses one group ID, and I need another consumer with |
Is there an existing issue that is already proposing this?
Is your feature request related to a problem? Please describe it
Hello,
We have case to always keep connections to multiple NATS servers in the same time but each of them are specific service and there could be same subject across from producers. I can see that
@MessagePattern
have argument with type ofTransport | symbol
.Describe the solution you'd like
So this approach will provide a better flexibility for the developers.
Teachability, documentation, adoption, migration strategy
No migration steps
What is the motivation / use case for changing the behavior?
Better flexibility for microservices
The text was updated successfully, but these errors were encountered: