Did*_*dot 4 node.js typescript microservices
我想学习如何使用 kafka 和 nestjs 创建微服务。但我得到如下错误
[Nest] 61226 - 07/18/2021, 12:12:16 PM [NestFactory] Starting Nest application...
[Nest] 61226 - 07/18/2021, 12:12:16 PM [InstanceLoader] AppModule dependencies initialized +27ms
[Nest] 61226 - 07/18/2021, 12:12:16 PM [ServerKafka] INFO [Consumer] Starting {"timestamp":"2021-07-18T05:12:16.850Z","logger":"kafkajs","groupId":"group-account-server"}
[Nest] 61226 - 07/18/2021, 12:12:41 PM [ServerKafka] INFO [ConsumerGroup] Consumer has joined the group {"timestamp":"2021-07-18T05:12:41.984Z","logger":"kafkajs","groupId":"group-account-server","memberId":"nestjs-consumer-server-d90648a1-60cf-4c23-8237-94ab2ea106d5","leaderId":"nestjs-consumer-server-d90648a1-60cf-4c23-8237-94ab2ea106d5","isLeader":true,"memberAssignment":{},"groupProtocol":"RoundRobinAssigner","duration":25120}
(node:61226) UnhandledPromiseRejectionWarning: TypeError: this.flushLogs is not a function
at /Users/skinnyguy/Projects2020/microservices-lamexpress/kafka-services/node_modules/@nestjs/microservices/nest-microservice.js:88:26
at ServerKafka.listen (/Users/skinnyguy/Projects2020/microservices-lamexpress/kafka-services/node_modules/@nestjs/microservices/server/server-kafka.js:43:13)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:61226) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:61226) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Run Code Online (Sandbox Code Playgroud)
如何解决这个错误?
这是我的 main.ts 文件
[Nest] 61226 - 07/18/2021, 12:12:16 PM [NestFactory] Starting Nest application...
[Nest] 61226 - 07/18/2021, 12:12:16 PM [InstanceLoader] AppModule dependencies initialized +27ms
[Nest] 61226 - 07/18/2021, 12:12:16 PM [ServerKafka] INFO [Consumer] Starting {"timestamp":"2021-07-18T05:12:16.850Z","logger":"kafkajs","groupId":"group-account-server"}
[Nest] 61226 - 07/18/2021, 12:12:41 PM [ServerKafka] INFO [ConsumerGroup] Consumer has joined the group {"timestamp":"2021-07-18T05:12:41.984Z","logger":"kafkajs","groupId":"group-account-server","memberId":"nestjs-consumer-server-d90648a1-60cf-4c23-8237-94ab2ea106d5","leaderId":"nestjs-consumer-server-d90648a1-60cf-4c23-8237-94ab2ea106d5","isLeader":true,"memberAssignment":{},"groupProtocol":"RoundRobinAssigner","duration":25120}
(node:61226) UnhandledPromiseRejectionWarning: TypeError: this.flushLogs is not a function
at /Users/skinnyguy/Projects2020/microservices-lamexpress/kafka-services/node_modules/@nestjs/microservices/nest-microservice.js:88:26
at ServerKafka.listen (/Users/skinnyguy/Projects2020/microservices-lamexpress/kafka-services/node_modules/@nestjs/microservices/server/server-kafka.js:43:13)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:61226) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:61226) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Run Code Online (Sandbox Code Playgroud)
这是我的 Kafka 配置
import { NestFactory } from '@nestjs/core';
import { MicroserviceOptions } from '@nestjs/microservices';
import { AppModule } from './app.module';
import { KafkaConsumerOptions } from './infrastructure/kafka/kafka.config';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.connectMicroservice<MicroserviceOptions>(KafkaConsumerOptions);
await app.startAllMicroservicesAsync();
await app.listen(3000);
console.log(`Application running in url ${app.getUrl()}`);
}
bootstrap();
Run Code Online (Sandbox Code Playgroud)
这里有没有人用 kafka 和 nestjs 创建过微服务?请分享。谢谢
| 归档时间: |
|
| 查看次数: |
674 次 |
| 最近记录: |