Skip to content

Commit 126825d

Browse files
docs: move healthchecks below the streaming section
1 parent c63fe8c commit 126825d

File tree

1 file changed

+36
-36
lines changed

1 file changed

+36
-36
lines changed

content/microservices/grpc.md

+36-36
Original file line numberDiff line numberDiff line change
@@ -377,42 +377,6 @@ Nest supports GRPC stream handlers in two possible ways:
377377

378378
<app-banner-enterprise></app-banner-enterprise>
379379

380-
#### Health checks
381-
382-
When running a gRPC application in an orchestrator such a Kubernetes, you may need to know if it is running and in a healthy state. The [gRPC Health Check specification](https://grpc.io/docs/guides/health-checking/) is a standard that allow gRPC clients to expose their health status to allow the orchestrator to act accordingly.
383-
384-
To add gRPC health check support, first install the [grpc-node](https://github.com/grpc/grpc-node/tree/master/packages/grpc-health-check) package:
385-
386-
```bash
387-
$ npm i --save grpc-health-check
388-
```
389-
390-
Then it can be hooked into the gRPC service using the `onLoadPackageDefinition` hook in your gRPC server options, as follows. Note that the `protoPath` needs to have both the health check and the hero package.
391-
392-
```typescript
393-
@@filename(main)
394-
import { HealthImplementation, protoPath as healthCheckProtoPath } from 'grpc-health-check';
395-
396-
const app = await NestFactory.createMicroservice<MicroserviceOptions>(AppModule, {
397-
options: {
398-
protoPath: [
399-
healthCheckProtoPath,
400-
protoPath: join(__dirname, 'hero/hero.proto'),
401-
],
402-
onLoadPackageDefinition: (pkg, server) => {
403-
const healthImpl = new HealthImplementation({
404-
'': 'UNKNOWN',
405-
});
406-
407-
healthImpl.addToServer(server);
408-
healthImpl.setStatus('', 'SERVING');
409-
},
410-
},
411-
});
412-
```
413-
414-
> info **Hint** The [gRPC health probe](https://github.com/grpc-ecosystem/grpc-health-probe) is a useful CLI to test gRPC health checks in a containerized environment.
415-
416380
#### Streaming sample
417381

418382
Let's define a new sample gRPC service called `HelloService`. The `hello.proto` file is structured using <a href="https://developers.google.com/protocol-buffers">protocol buffers</a>. Here's what it looks like:
@@ -543,6 +507,42 @@ lotsOfGreetings(requestStream: any, callback: (err: unknown, value: HelloRespons
543507

544508
Here we used the `callback` function to send the response once processing of the `requestStream` has been completed.
545509

510+
#### Health checks
511+
512+
When running a gRPC application in an orchestrator such a Kubernetes, you may need to know if it is running and in a healthy state. The [gRPC Health Check specification](https://grpc.io/docs/guides/health-checking/) is a standard that allow gRPC clients to expose their health status to allow the orchestrator to act accordingly.
513+
514+
To add gRPC health check support, first install the [grpc-node](https://github.com/grpc/grpc-node/tree/master/packages/grpc-health-check) package:
515+
516+
```bash
517+
$ npm i --save grpc-health-check
518+
```
519+
520+
Then it can be hooked into the gRPC service using the `onLoadPackageDefinition` hook in your gRPC server options, as follows. Note that the `protoPath` needs to have both the health check and the hero package.
521+
522+
```typescript
523+
@@filename(main)
524+
import { HealthImplementation, protoPath as healthCheckProtoPath } from 'grpc-health-check';
525+
526+
const app = await NestFactory.createMicroservice<MicroserviceOptions>(AppModule, {
527+
options: {
528+
protoPath: [
529+
healthCheckProtoPath,
530+
protoPath: join(__dirname, 'hero/hero.proto'),
531+
],
532+
onLoadPackageDefinition: (pkg, server) => {
533+
const healthImpl = new HealthImplementation({
534+
'': 'UNKNOWN',
535+
});
536+
537+
healthImpl.addToServer(server);
538+
healthImpl.setStatus('', 'SERVING');
539+
},
540+
},
541+
});
542+
```
543+
544+
> info **Hint** The [gRPC health probe](https://github.com/grpc-ecosystem/grpc-health-probe) is a useful CLI to test gRPC health checks in a containerized environment.
545+
546546
#### gRPC Metadata
547547

548548
Metadata is information about a particular RPC call in the form of a list of key-value pairs, where the keys are strings and the values are typically strings but can be binary data. Metadata is opaque to gRPC itself - it lets the client provide information associated with the call to the server and vice versa. 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.

0 commit comments

Comments
 (0)