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
@@ -135,7 +135,7 @@ export class HeroesController {
135
135
@Controller()
136
136
exportclassHeroesController {
137
137
@GrpcMethod('HeroesService', 'FindOne')
138
-
findOne(data, metadata) {
138
+
findOne(data, metadata, call) {
139
139
const items = [
140
140
{ id: 1, name: 'John' },
141
141
{ id: 2, name: 'Doe' },
@@ -149,7 +149,9 @@ export class HeroesController {
149
149
150
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
-
The `findOne()` handler method takes two arguments, the `data` passed from the caller and `metadata` that stores gRPC request metadata.
152
+
The `findOne()` handler method takes three arguments, the `data` passed from the caller, `metadata` that stores gRPC
153
+
request metadata and `call` to obtain the `GrpcCall` object properties such as `sendMetadata` for send metadata to client.
154
+
153
155
154
156
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
157
@@ -158,7 +160,7 @@ Both `@GrpcMethod()` decorator arguments are optional. If called without the sec
Here we used the `callback` function to send the response once processing of the `requestStream` has been completed.
445
+
446
+
#### gRPC Metadata
447
+
448
+
gRPC metadata is additional data that may be useful during the processing of requests and responses, but is not part of the actual application data. Metadata may include authentication tokens, request identifiers and tags for monitoring purposes, and data information such as the number of records in a data set.
449
+
450
+
To read the metadata in `@GrpcMethod()` use the second handler metadata argument, which returns the gRPC class `Metadata`.
451
+
452
+
You can send metadata from `@GrpcMethod()` using the function `sendMetadata()` which is provided by the object `GrpcCall` in the third handler argument.
0 commit comments