-
-
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
Microservices: Order of pattern fields #2428
Conversation
…tRouteFromPattern`
Pull Request Test Coverage Report for Build 3326
💛 - Coveralls |
@@ -18,11 +18,14 @@ import { | |||
WritePacket, | |||
} from '../interfaces'; | |||
|
|||
import * as Utils from '../utils'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you use import * as
instead of importing a particular class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any reason why I can't use it :) It provides an isolated scope (utils/interfaces/enums etc) and allows me to make import section more simple.
export abstract class ClientProxy { | ||
public abstract connect(): Promise<any>; | ||
public abstract close(): any; | ||
|
||
protected routingMap = new Map<string, Function>(); | ||
protected readonly msvcUtil = Utils.MsvcUtil; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable name isn't very descriptive (+using msvc
seems to be redundant here)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion, if other programmer sees this variable it will understand what is it. What name do you suggest?
@@ -18,27 +18,31 @@ import { | |||
} from '../interfaces'; | |||
import { NO_EVENT_HANDLER } from './../constants'; | |||
|
|||
import * as Utils from '../utils'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any reason why I can't use it :) It provides an isolated scope (utils/interfaces/enums etc) and allows me to make import section more simple.
export abstract class Server { | ||
protected readonly messageHandlers = new Map<string, MessageHandler>(); | ||
protected readonly logger = new Logger(Server.name); | ||
protected readonly msvcUtil = Utils.MsvcUtil; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion, if other programmer sees this variable it will understand what is it. What name do you suggest?
* @returns string | ||
*/ | ||
private getRouteFromPattern(pattern: string): string { | ||
let validPattern: any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any
-> Record<string, unknown> | string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed.
let validPattern: any; | ||
|
||
try { | ||
// Gets the pattern in JSON format |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment seems to be needless
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I write code, I adhere to PPP (Pseudocode Programming Process). If you want, I will remove this comment.
validPattern = pattern; | ||
} | ||
|
||
// Transform the Pattern to Route |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment seems to be needless
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I write code, I adhere to PPP (Pseudocode Programming Process). If you want, I will remove this comment.
@@ -0,0 +1,39 @@ | |||
import { isString, isObject } from '@nestjs/common/utils/shared.utils'; | |||
|
|||
export class MsvcUtil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The filename + class name aren't very descriptive (+using msvc prefix seems to be redundant here)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What name do you suggest?
* @param {any} pattern - client pattern | ||
* @returns string | ||
*/ | ||
public static transformPatternToRoute(pattern: any): string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why static
? Why pattern: any
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I use classes for utils and static
method allows me to use utils as singleton. Changed.
* @returns string | ||
*/ | ||
public static transformPatternToRoute(pattern: any): string { | ||
// Returns the pattern according to the 1st |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment seems to be redundant (it's easy to infer from the context)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I write code, I adhere to PPP (Pseudocode Programming Process). If you want, I will remove this comment.
return pattern; | ||
} | ||
|
||
// Throws the error if the pattern has an incorrect type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment seems to be redundant (it's easy to infer from the context)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I write code, I adhere to PPP (Pseudocode Programming Process). If you want, I will remove this comment.
const sortedPatternParams = sortedKeys.map((key) => | ||
`${key}:${MsvcUtil.transformPatternToRoute(pattern[key])}`); | ||
|
||
// Creates and returns the Route |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment seems to be redundant (it's easy to infer from the context)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I write code, I adhere to PPP (Pseudocode Programming Process). If you want, I will remove this comment.
Great idea! Thanks for contribution :) I left a few comments, could you look at them? |
I have nothing against your coding style, just want to ensure that newly added code is consistent with the project. I fixed gRPC issues (broken integration tests) + adjusted code style a little bit. Thanks for your contribution! I'll release it soon |
Hello @kamilmysliwiec, we have around 15 microservices in production. Upgrading to version > 6.4.0 changes the command name because of this feature. Before this the command name was Thanks in advance, |
Hi @JonathanMeyer2600, |
Hi @kamilmysliwiec |
Hello @kamilmysliwiec When I was writing this code, I didn’t think about messages from other sources. I didn’t use JSON.stringify to encode the message and it made pattern (route) a bit smaller. But now code does the same thing as JSON.stringify and I see no reason not to use it. If you want, you can use something like that:
I apologize about any inconvenience. :( |
No worries @Geass1000! :) I'll look at this soon, just wanted to fix the issue as quick as possible |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
When we
send
/emit
request according to someobject
pattern, pattern doesn’t sort pattern’s fields . Pattern:doesn’t equal:
Thus, if we try to catch a pattern using
MessagePattern
orEventPattern
, nest will not call a required handler.What is the new behavior?
I added simple middle-logic, that parses a patterns, sorts fields and creates a new pattern (route).
Does this PR introduce a breaking change?
Other information