Skip to content

Define specific client in MessagePattern decorator (microservices) #11298

@frct1

Description

@frct1

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

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 of Transport | symbol.

Describe the solution you'd like

So this approach will provide a better flexibility for the developers.

ClientsModule.register([
      {
        name: FIRST_SERVICE_CLIENT, // Symbol
        transport: Transport.NATS,
        options: {
            url: `nats://${process.env.FIRST_NATS_HOST}`,
            name: 'FIRST_SERVICE_LISTENER',
            headers: { 'x-version': '1.0.0' },
            serializer: new OutboundResponseExternalSerializer(),
            deserializer: new InboundMessageExternalDeserializer(),
        }
      },
       {
        name: SECOND_SERVICE_CLIENT, // typeof Symbol
        transport: Transport.NATS,
        options: {
            url: `nats://${process.env.SECOND_NATS_HOST}`,
            name: 'SECOND_SERVICE_LISTENER',
            headers: { 'x-version': '1.0.0' },
            serializer: new OutboundResponseExternalSerializer(),
            deserializer: new InboundMessageExternalDeserializer(),
        }
      },
    ]),
async onApplicationBootstrap() {
    await this.first_client.connect()
    await this.second_client.connect()
}
@MesssagePattern('message_title', FIRST_SERVICE_CLIENT) // Symbol is passed here
async act_on_message_from_first_service(){}

@MesssagePattern('message_title', SECOND_SERVICE_CLIENT) //Symbol is passed here
async act_on_message_from_second_service(){}

Teachability, documentation, adoption, migration strategy

No migration steps

What is the motivation / use case for changing the behavior?

Better flexibility for microservices

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions