git clone <project>
cd first-nestjs
code .
Dann
-
falls nicht sichtbar, ein Terminal (Menü Terminal/New Terminal) öffnen,
-
die Docker Container starten
docker compose up -d
-
das Terminal teilen (zwei Terminals)
-
-
linkes Terminal:
npm install npm run start:dev # #> [email protected] start #> nest start # #[Nest] 1892 - 08/01/2022, 10:31:45 AM LOG [NestFactory] #Starting Nest application...
-
rechtes Terminal:
curl localhost:3000 # Hello World!% curl localhost:3000/kafka-test # [{"topicName":"medium.rocks","partition":0,"errorCode":0,"baseOffset":"0","logAppendTime":"-1","logStartOffset":"-1"}]% # ... # [main.ts] Application is running on: http://[::1]:3000
Durch den zweiten
curl
Aufruf wird ein event erzeugt und gleich auch konsumiert, im linken Terminal erscheint:[app.controller.ts] kafka-test emitting now [consumer.controller.ts] Receiving a message from topic: medium.rocks{"foo":"bar","data":"Mon Aug 01 2022 10:32:16 GMT+0000 (Coordinated Universal Time)"}
-
-
Der get Endpunkt
/kafka-test
ist in app.controller.ts implementiert. -
Der Event Consumer ist in consumer.controller.ts implementiert.
Zum NestJS Framework:
Aufbau des Projekts: