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

Which message pattern does the Pub/Sub library expose for effective routing #264

Closed
kylehouston opened this issue Aug 23, 2021 · 9 comments
Labels
bug Something isn't working question Further information is requested

Comments

@kylehouston
Copy link

When using the NestJS hybrid approach what transport do we add to the @MessagePattern to ensure the events get routed to the correct callback?

export declare const MessagePattern: <T = string | PatternMetadata>(metadata?: T, transport?: Transport) => MethodDecorator;

@MessagePattern('test-topic', ???)
  async handlePubSubMessage(payload: any) {
    console.log(`Pub/Sub ----> ${JSON.stringify(payload)} created`);
  }
@kylehouston
Copy link
Author

Looks like GCPPubSubServer Class needs to expose a transportId similar to https://github.com/nestjs/nest/blob/master/packages/microservices/server/server-redis.ts#L24

@ccoeurderoy
Copy link
Contributor

ccoeurderoy commented Aug 24, 2021

Hey @kylehouston, that is a good question! And yes you are right, we should add the transportId property to this class. However, according to the CustomTransportStrategy interface, it expects a value from the Transport enum 😕 (even if we can hack this and disable typescript in this particular case, but I want to avoid this 😅)

It might be interesting to ask the question to the Nest Discord channel in order to know how we could handle hybrid applications with a custom microservice.

@kylehouston
Copy link
Author

Thanks @ccoeurderoy - yeah the CustomTransportStrategy expecting the Transport enum was the bit that has me concerned. Out of interest, how would you hack this?

I'll reach out in the Discord for sure and see where things go!

@ccoeurderoy
Copy link
Contributor

ccoeurderoy commented Aug 24, 2021

Out of interest, how would you hack this?

I could disable the TS check with a dirty // @ts-ignore since there is a condition on transportId here:

  /**
   * Transport ID required to bind transport when using hybrid applications
   * ⚠️ Custom number but could have conflict if Nest creates a new transport with this number
   */
  // @ts-ignore
  public readonly transportId: number = 10000;

But I don't like that honestly 😅 It also requires the MessagePattern decorator to ignore the TS build

@ccoeurderoy
Copy link
Contributor

I'll keep this issue open until Nest provides a clean answer

@kylehouston
Copy link
Author

Thanks @ccoeurderoy, looking again at the MessagePattern, there's a param for metadata - is there anything in the pub/sub library options I could use?

export declare const MessagePattern: <T = string | PatternMetadata>(metadata?: T, transport?: Transport) => MethodDecorator;

Logged a message in the support channel, hopefully someone will come back with a nice way to make this work :)

@ccoeurderoy
Copy link
Contributor

is there anything in the pub/sub library options I could use?

Well, honestly I don't know since this signature has never been mentioned in the Nest documentation (sorry for the late answer)

By the way, did you get an answer from Discord?

@ccoeurderoy ccoeurderoy added bug Something isn't working question Further information is requested labels Aug 31, 2021
@kylehouston
Copy link
Author

No worries @ccoeurderoy - no reply in discord :/ I'll try following up, doesn't make sense that a custom strategy transport id should be a list of known nestjs enums

@ccoeurderoy
Copy link
Contributor

ccoeurderoy commented Feb 15, 2022

Hey @kylehouston, I may be wrong, but it seems to be available since v8.3.0 (see this pull request) 🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants