{"id":"dca14831dbe43314","repo":"nestjs/nest","slug":"not-initialized-please-call-the-listen-startal-dca148","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-rmq.ts","lineNumber":383,"sourceCode":"    correlationId: string,\n    context: RmqContext,\n  ): void {\n    const outgoingResponse = this.serializer.serialize(\n      message as unknown as OutgoingResponse,\n    );\n    const options = outgoingResponse.options;\n    delete outgoingResponse.options;\n\n    const buffer = Buffer.from(JSON.stringify(outgoingResponse));\n    const sendOptions = { correlationId, ...options };\n\n    this.onProcessingEndHook?.(this.transportId, context);\n    this.channel!.sendToQueue(replyTo, buffer, sendOptions);\n  }\n\n  public unwrap<T>(): T {\n    if (!this.server) {\n      throw new Error(\n        'Not initialized. Please call the \"listen\"/\"startAllMicroservices\" method before accessing the server.',\n      );\n    }\n    return this.server as T;\n  }\n\n  public on<\n    EventKey extends keyof RmqEvents = keyof RmqEvents,\n    EventCallback extends RmqEvents[EventKey] = RmqEvents[EventKey],\n  >(event: EventKey, callback: EventCallback) {\n    if (this.server) {\n      this.server.addListener(event, callback);\n    } else {\n      this.pendingEventListeners.push({ event, callback });\n    }\n  }\n\n  public getHandlerByPattern(pattern: string): MessageHandler | null {","sourceCodeStart":365,"sourceCodeEnd":401,"githubUrl":"https://github.com/nestjs/nest/blob/6ec0e2783d15290732447f304d8549b591b9749e/packages/microservices/server/server-rmq.ts#L365-L401","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-rmq.ts:383 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Call app.listen() or app.startAllMicroservices() before accessing the RMQ server instance.","Await listen() so the RabbitMQ channel/connection is set up before use."],"exampleFix":"const app = await NestFactory.createMicroservice(AppModule, opts);\nawait app.listen();\nconst server = app.get(ServerRMQ);","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"6ec0e2783d15290732447f304d8549b591b9749e","analyzedAt":"2026-08-03T17:42:23.673Z","schemaVersion":2}