{"id":"72adc7c6b24be9a9","repo":"nestjs/nest","slug":"not-initialized-please-call-the-listen-startal","errorCode":null,"errorMessage":"Not initialized. Please call the \"listen\"/\"startAllMicroservices\" method before accessing the server.","messagePattern":"Not initialized\\. Please call the \"listen\"/\"startAllMicroservices\" method before accessing the server\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/microservices/server/server-kafka.ts","lineNumber":262,"sourceCode":"    return this.onProcessingStartHook(\n      this.transportId,\n      kafkaContext,\n      async () => {\n        const response$ = this.transformToObservable(\n          handler(packet.data, kafkaContext),\n        );\n\n        const replayStream$ = new ReplaySubject();\n        await this.combineStreamsAndThrowIfRetriable(response$, replayStream$);\n\n        this.send(replayStream$, publish);\n      },\n    );\n  }\n\n  public unwrap<T>(): T {\n    if (!this.client) {\n      throw new Error(\n        'Not initialized. Please call the \"listen\"/\"startAllMicroservices\" method before accessing the server.',\n      );\n    }\n    return [this.client, this.consumer, this.producer] as T;\n  }\n\n  public on<\n    EventKey extends string | number | symbol = string | number | symbol,\n    EventCallback = any,\n  >(event: EventKey, callback: EventCallback) {\n    throw new Error('Method is not supported for Kafka server');\n  }\n\n  private combineStreamsAndThrowIfRetriable(\n    response$: Observable<any>,\n    replayStream$: ReplaySubject<unknown>,\n  ) {\n    return new Promise<void>((resolve, reject) => {","sourceCodeStart":244,"sourceCodeEnd":280,"githubUrl":"https://github.com/nestjs/nest/blob/6ec0e2783d15290732447f304d8549b591b9749e/packages/microservices/server/server-kafka.ts#L244-L280","documentation":"Error \"Not initialized. Please call the \"listen\"/\"startAllMicroservices\" method before accessing the server.\" thrown in nestjs/nest.","triggerScenarios":"Thrown at packages/microservices/server/server-kafka.ts:262 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Call app.listen() (or app.startAllMicroservices()) before accessing the underlying Kafka server/client, consumer, or producer.","Await the listen promise so initialization completes before any access.","Check initialization order: access this.client/consumer/producer only inside code that runs after bootstrap listening has started."],"exampleFix":"const app = await NestFactory.createMicroservice(AppModule, opts);\nawait app.listen();\n// now safe to access the server instance\nconst kafka = app.get(ServerKafka);","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"6ec0e2783d15290732447f304d8549b591b9749e","analyzedAt":"2026-08-03T17:42:23.673Z","schemaVersion":2}