You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix#1176
According to @kamilmysliwiec, "plural form is recommended".
I updated some of the singularly named classes and updated them, along
with file names.
Signed-off-by: Stanislas Lange <[email protected]>
Copy file name to clipboardExpand all lines: content/microservices/grpc.md
+26-26Lines changed: 26 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -90,15 +90,15 @@ The <strong>gRPC</strong> transporter options object exposes the properties desc
90
90
91
91
#### Sample gRPC service
92
92
93
-
Let's define our sample gRPC service called `HeroService`. In the above `options` object, the`protoPath` property sets a path to the `.proto` definitions file `hero.proto`. The `hero.proto` file is structured using <ahref="https://developers.google.com/protocol-buffers">protocol buffers</a>. Here's what it looks like:
93
+
Let's define our sample gRPC service called `HeroesService`. In the above `options` object, the`protoPath` property sets a path to the `.proto` definitions file `hero.proto`. The `hero.proto` file is structured using <ahref="https://developers.google.com/protocol-buffers">protocol buffers</a>. Here's what it looks like:
94
94
95
95
```typescript
96
96
// hero/hero.proto
97
97
syntax="proto3";
98
98
99
99
packagehero;
100
100
101
-
serviceHeroService {
101
+
serviceHeroesService {
102
102
rpcFindOne (HeroById) returns (Hero) {}
103
103
}
104
104
@@ -112,17 +112,17 @@ message Hero {
112
112
}
113
113
```
114
114
115
-
Our `HeroService` exposes a `FindOne()` method. This method expects an input argument of type `HeroById` and returns a `Hero` message (protocol buffers use `message` elements to define both parameter types and return types).
115
+
Our `HeroesService` exposes a `FindOne()` method. This method expects an input argument of type `HeroById` and returns a `Hero` message (protocol buffers use `message` elements to define both parameter types and return types).
116
116
117
117
Next, we need to implement the service. To define a handler that fulfills this definition, we use the `@GrpcMethod()` decorator in a controller, as shown below. This decorator provides the metadata needed to declare a method as a gRPC service method.
118
118
119
119
> info **Hint** The `@MessagePattern()` decorator (<ahref="microservices/basics#request-response">read more</a>) introduced in previous microservices chapters is not used with gRPC-based microservices. The `@GrpcMethod()` decorator effectively takes its place for gRPC-based microservices.
120
120
121
121
```typescript
122
-
@@filename(hero.controller)
122
+
@@filename(heroes.controller)
123
123
@Controller()
124
-
exportclassHeroController {
125
-
@GrpcMethod('HeroService', 'FindOne')
124
+
exportclassHeroesController {
125
+
@GrpcMethod('HeroesService', 'FindOne')
126
126
findOne(data:HeroById, metadata:any):Hero {
127
127
const items = [
128
128
{ id: 1, name: 'John' },
@@ -133,8 +133,8 @@ export class HeroController {
133
133
}
134
134
@@switch
135
135
@Controller()
136
-
exportclassHeroController {
137
-
@GrpcMethod('HeroService', 'FindOne')
136
+
exportclassHeroesController {
137
+
@GrpcMethod('HeroesService', 'FindOne')
138
138
findOne(data, metadata) {
139
139
const items = [
140
140
{ id: 1, name: 'John' },
@@ -147,17 +147,17 @@ export class HeroController {
147
147
148
148
> info **Hint** The `@GrpcMethod()` decorator is imported from the `@nestjs/microservices` package.
149
149
150
-
The decorator shown above takes two arguments. The first is the service name (e.g., `'HeroService'`), corresponding to the `HeroService` service definition in `hero.proto`. The second (the string `'FindOne'`) corresponds to the `FindOne()` rpc method defined within `HeroService` in the `hero.proto` file.
150
+
The decorator shown above takes two arguments. The first is the service name (e.g., `'HeroesService'`), corresponding to the `HeroesService` service definition in `hero.proto`. The second (the string `'FindOne'`) corresponds to the `FindOne()` rpc method defined within `HeroesService` in the `hero.proto` file.
151
151
152
152
The `findOne()` handler method takes two arguments, the `data` passed from the caller and `metadata` that stores gRPC request metadata.
153
153
154
154
Both `@GrpcMethod()` decorator arguments are optional. If called without the second argument (e.g., `'FindOne'`), Nest will automatically associate the `.proto` file rpc method with the handler based on converting the handler name to upper camel case (e.g., the `findOne` handler is associated with the `FindOne` rpc call definition). This is shown below.
155
155
156
156
```typescript
157
-
@@filename(hero.controller)
157
+
@@filename(heroes.controller)
158
158
@Controller()
159
-
exportclassHeroController {
160
-
@GrpcMethod('HeroService')
159
+
exportclassHeroesController {
160
+
@GrpcMethod('HeroesService')
161
161
findOne(data:HeroById, metadata:any):Hero {
162
162
const items = [
163
163
{ id: 1, name: 'John' },
@@ -168,8 +168,8 @@ export class HeroController {
168
168
}
169
169
@@switch
170
170
@Controller()
171
-
exportclassHeroController {
172
-
@GrpcMethod('HeroService')
171
+
exportclassHeroesController {
172
+
@GrpcMethod('HeroesService')
173
173
findOne(data, metadata) {
174
174
const items = [
175
175
{ id: 1, name: 'John' },
@@ -180,12 +180,12 @@ export class HeroController {
180
180
}
181
181
```
182
182
183
-
You can also omit the first `@GrpcMethod()` argument. In this case, Nest automatically associates the handler with the service definition from the proto definitions file based on the **class** name where the handler is defined. For example, in the following code, class `HeroService` associates its handler methods with the `HeroService` service definition in the `hero.proto` file based on the matching of the name `'HeroService'`.
183
+
You can also omit the first `@GrpcMethod()` argument. In this case, Nest automatically associates the handler with the service definition from the proto definitions file based on the **class** name where the handler is defined. For example, in the following code, class `HeroesService` associates its handler methods with the `HeroesService` service definition in the `hero.proto` file based on the matching of the name `'HeroesService'`.
184
184
185
185
```typescript
186
-
@@filename(hero.controller)
186
+
@@filename(heroes.controller)
187
187
@Controller()
188
-
exportclassHeroService {
188
+
exportclassHeroesService {
189
189
@GrpcMethod()
190
190
findOne(data:HeroById, metadata:any):Hero {
191
191
const items = [
@@ -197,7 +197,7 @@ export class HeroService {
197
197
}
198
198
@@switch
199
199
@Controller()
200
-
exportclassHeroService {
200
+
exportclassHeroesService {
201
201
@GrpcMethod()
202
202
findOne(data, metadata) {
203
203
const items = [
@@ -237,12 +237,12 @@ Once registered, we can inject the configured `ClientGrpc` object with `@Inject(
@@ -281,20 +281,20 @@ export class AppService implements OnModuleInit {
281
281
282
282
Finally, for more complex scenarios, we can inject a dynamically configured client using the `ClientProxyFactory` class as described <ahref="/microservices/basics#client">here</a>.
283
283
284
-
In either case, we end up with a reference to our `HeroService` proxy object, which exposes the same set of methods that are defined inside the `.proto` file. Now, when we access this proxy object (i.e., `heroService`), the gRPC system automatically serializes requests, forwards them to the remote system, returns a response, and deserializes the response. Because gRPC shields us from these network communication details, `heroService` looks and acts like a local provider.
284
+
In either case, we end up with a reference to our `HeroesService` proxy object, which exposes the same set of methods that are defined inside the `.proto` file. Now, when we access this proxy object (i.e., `heroService`), the gRPC system automatically serializes requests, forwards them to the remote system, returns a response, and deserializes the response. Because gRPC shields us from these network communication details, `heroService` looks and acts like a local provider.
285
285
286
-
Note, all service methods are **lower camel cased** (in order to follow the natural convention of the language). So, for example, while our `.proto` file `HeroService` definition contains the `FindOne()` function, the `heroService` instance will provide the `findOne()` method.
286
+
Note, all service methods are **lower camel cased** (in order to follow the natural convention of the language). So, for example, while our `.proto` file `HeroesService` definition contains the `FindOne()` function, the `heroService` instance will provide the `findOne()` method.
287
287
288
288
```typescript
289
-
interfaceHeroService {
289
+
interfaceHeroesService {
290
290
findOne(data: { id:number }):Observable<any>;
291
291
}
292
292
```
293
293
294
294
A message handler is also able to return an `Observable`, in which case the result values will be emitted until the stream is completed.
Copy file name to clipboardExpand all lines: content/microservices/kafka.md
+10-10Lines changed: 10 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -168,7 +168,7 @@ client: ClientKafka;
168
168
The `ClientKafka` class provides the `subscribeToResponseOf()` method. The `subscribeToResponseOf()` method takes a request's topic name as an argument and adds the derived reply topic name to a collection of reply topics. This method is required when implementing the message pattern.
@@ -205,9 +205,9 @@ Nest receives incoming Kafka messages as an object with `key`, `value`, and `hea
205
205
Nest sends outgoing Kafka messages after a serialization process when publishing events or sending messages. This occurs on arguments passed to the `ClientKafka``emit()` and `send()` methods or on values returned from a `@MessagePattern` method. This serialization "stringifies" objects that are not strings or buffers by using `JSON.stringify()` or the `toString()` prototype method.
Outgoing messages can also be keyed by passing an object with the `key` and `value` properties. Keying messages is important for meeting the [co-partitioning requirement](https://docs.confluent.io/current/ksql/docs/developer-guide/partition-data.html#co-partitioning-requirements).
Additionally, messages passed in this format can also contain custom headers set in the `headers` hash property. Header hash property values must be either of type `string` or type `Buffer`.
Since the Kafka microservice message pattern utilizes two topics for the request and reply channels, a reply pattern should be derived from the request topic. By default, the name of the reply topic is the composite of the request topic name with `.reply` appended.
Copy file name to clipboardExpand all lines: content/techniques/authentication.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -264,7 +264,7 @@ We've followed the recipe described earlier for all Passport strategies. In our
264
264
265
265
We've also implemented the `validate()` method. For each strategy, Passport will call the verify function (implemented with the `validate()` method in `@nestjs/passport`) using an appropriate strategy-specific set of parameters. For the local-strategy, Passport expects a `validate()` method with the following signature: `validate(username: string, password:string): any`.
266
266
267
-
Most of the validation work is done in our `AuthService` (with the help of our `UserService`), so this method is quite straightforward. The `validate()` method for **any** Passport strategy will follow a similar pattern, varying only in the details of how credentials are represented. If a user is found and the credentials are valid, the user is returned so Passport can complete its tasks (e.g., creating the `user` property on the `Request` object), and the request handling pipeline can continue. If it's not found, we throw an exception and let our <ahref="exception-filters">exceptions layer</a> handle it.
267
+
Most of the validation work is done in our `AuthService` (with the help of our `UsersService`), so this method is quite straightforward. The `validate()` method for **any** Passport strategy will follow a similar pattern, varying only in the details of how credentials are represented. If a user is found and the credentials are valid, the user is returned so Passport can complete its tasks (e.g., creating the `user` property on the `Request` object), and the request handling pipeline can continue. If it's not found, we throw an exception and let our <ahref="exception-filters">exceptions layer</a> handle it.
268
268
269
269
Typically, the only significant difference in the `validate()` method for each strategy is **how** you determine if a user exists and is valid. For example, in a JWT strategy, depending on requirements, we may evaluate whether the `userId` carried in the decoded token matches a record in our user database, or matches a list of revoked tokens. Hence, this pattern of sub-classing and implementing strategy-specific validation is consistent, elegant and extensible.
270
270
@@ -959,6 +959,6 @@ To use above decorator in your resolver, be sure to include it as a parameter of
@@ -543,7 +543,7 @@ The `@nestjs/typeorm` package exposes the `getRepositoryToken()` function which
543
543
```typescript
544
544
@Module({
545
545
providers: [
546
-
UserService,
546
+
UsersService,
547
547
{
548
548
provide: getRepositoryToken(User),
549
549
useValue: mockRepository,
@@ -553,7 +553,7 @@ The `@nestjs/typeorm` package exposes the `getRepositoryToken()` function which
553
553
exportclassUsersModule {}
554
554
```
555
555
556
-
Now a substitute `mockRepository` will be used as the `UserRepository`. Whenever any class asks for `UserRepository` using an `@InjectRepository()` decorator, Nest will use the registered `mockRepository` object.
556
+
Now a substitute `mockRepository` will be used as the `UsersRepository`. Whenever any class asks for `UsersRepository` using an `@InjectRepository()` decorator, Nest will use the registered `mockRepository` object.
557
557
558
558
#### Custom repository
559
559
@@ -862,7 +862,7 @@ import { User } from './user.model';
862
862
863
863
@Injectable()
864
864
@Dependencies(getModelToken(User))
865
-
exportclassUserService {
865
+
exportclassUsersService {
866
866
constructor(usersRepository) {
867
867
this.usersRepository=usersRepository;
868
868
}
@@ -910,13 +910,13 @@ Now if we import `UsersModule` in `UserHttpModule`, we can use `@InjectModel(Use
0 commit comments