Skip to content

feature(microservice): decorator MessagePattern get new attribute 'transport' #4768

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

Conversation

barbarosh
Copy link

@barbarosh barbarosh commented May 9, 2020

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[x] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Other... Please describe:

What is the current behavior?

Issue Number: #4769
Docs changes: nestjs/docs.nestjs.com#1246

What is the new behavior?

Decorator MessagePattern get new attribute 'transport' for pass transport id and avoid bind patterns to wrong microservices in multiple microservices architecture

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

Sorry, something went wrong.

@barbarosh barbarosh changed the title Add ability for pass transport to MessagePattern Decorator MessagePattern get new attribute 'transport' for pass transport id and avoid bind patterns to wrong microservices in multiple microservices architecture May 9, 2020
@barbarosh barbarosh changed the title Decorator MessagePattern get new attribute 'transport' for pass transport id and avoid bind patterns to wrong microservices in multiple microservices architecture feature(microservice): Decorator MessagePattern get new attribute 'transport' for pass transport id and avoid bind patterns to wrong microservices in multiple microservices architecture May 9, 2020
@barbarosh barbarosh changed the title feature(microservice): Decorator MessagePattern get new attribute 'transport' for pass transport id and avoid bind patterns to wrong microservices in multiple microservices architecture feature(microservice): Decorator MessagePattern get new attribute 'transport' May 9, 2020
@barbarosh barbarosh changed the title feature(microservice): Decorator MessagePattern get new attribute 'transport' feature(microservice): decorator MessagePattern get new attribute 'transport' May 9, 2020
@coveralls
Copy link

coveralls commented May 9, 2020

Pull Request Test Coverage Report for Build 148a1380-0645-4cd5-95e8-98ad88b42fcc

  • 33 of 33 (100.0%) changed or added relevant lines in 12 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.02%) to 94.653%

Totals Coverage Status
Change from base Build d22e62a5-436d-439a-995e-5cc0c88277ea: 0.02%
Covered Lines: 4709
Relevant Lines: 4975

💛 - Coveralls

@barbarosh barbarosh force-pushed the feature/message-pattern-bind-to-transport branch 2 times, most recently from c244aa3 to 0845dab Compare May 10, 2020 18:07
@kamilmysliwiec
Copy link
Member

Thanks @barbarosh. I'll review asap

@@ -14,6 +19,7 @@ export enum GrpcMethodStreamingType {
*/
export const MessagePattern = <T = PatternMetadata | string>(
metadata?: T,
transport?: number,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use Transport enum here instead?

export const EventPattern = <T = string>(metadata?: T): MethodDecorator => {
export const EventPattern = <T = string>(
metadata?: T,
transport?: number,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use Transport enum here instead?

@@ -1,4 +1,5 @@
export interface CustomTransportStrategy {
listen(callback: () => void): any;
getTransport(): number;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add an abstract, optional method in the Server class instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, can we name it "getTransportId" instead? getTransport sounds slightly ambiguous

Copy link
Author

@barbarosh barbarosh May 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kamilmysliwiec

Can we add an abstract, optional method in the Server class instead?

I not sure about optional method it is good idea, in my vision we need know which Transport using each server. If new servers not implement this method for this server we need bind all message patterns for all transports or only without transport?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making this method required will introduce a breaking change.

If new servers not implement this method for this server

If one creates a new "custom strategy", we should allow him/her to decide whether it should be bound to all methods by default, or not.

Copy link
Author

@barbarosh barbarosh May 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood, will make abstract optional method and bind all message patterns to server without getTransportId

@@ -18,6 +19,7 @@ export interface ClientProperties {

export interface PatternProperties {
pattern: PatternMetadata;
transport: number;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use Transport enum here instead? + transport?

@@ -48,6 +49,10 @@ export class ServerGrpc extends Server implements CustomTransportStrategy {
grpcProtoLoaderPackage = this.loadPackage(protoLoader, ServerGrpc.name);
}

public getTransport(): number {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use Transport enum here instead?

@barbarosh
Copy link
Author

barbarosh commented May 16, 2020

@kamilmysliwiec Please review again, I made changes move getTransport() function to variable transportId and updates in docs nestjs/docs.nestjs.com#1246

@barbarosh
Copy link
Author

Added test

@kamilmysliwiec
Copy link
Member

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants