Skip to content

event publisher(nestjs) -> nats(jetstream) -> event consumer(nestjs)

License

Notifications You must be signed in to change notification settings

developer-shkim/nestjs-event-stream-app

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

실행 방법

1. nats-publisher, nats-listener 서버를 실행한다.

➜  nestjs-plugins git:(master) npm install
➜  nestjs-plugins git:(master) npx lerna run build
➜  nestjs-plugins git:(master) npx lerna run start

2. docker 로 nats(jetstream) 를 실행한다.

  • docker desktop 을 실행한다.
  • docker run -d --name nats-main -p 4222:4222 -p 6222:6222 -p 8222:8222 nats -js -m 8222

3. postman 과 같은 도구로 API 를 요청하고, 이벤트 pub/sub 을 확인한다.

  • request: GET 127.0.0.1:3001/create
  • response: order created.
  • nats-listener 에서 console 에 출력한 received: 이벤트명 이 출력되는 것을 확인한다.
{ stream: 'mystream', seq: 2, duplicate: false }
MsgHdrsImpl {
  _code: 0,
  _description: '',
  headers: Map(2) {
    'x-custom-header' => [ 'custom-header-value' ],
    'Nats-Expected-Stream' => [ 'mystream' ]
  }
}
{
  domain: '',
  account_hash: '',
  stream: 'mystream',
  consumer: 'myservice-durable-order_created',
  redeliveryCount: 1,
  redelivered: false,
  streamSequence: 2,
  deliverySequence: 2,
  timestampNanos: 1705985034459888400,
  pending: 0
}
received: order.created { id: 1, product: 'NestJS', quantity: 10 }

About

event publisher(nestjs) -> nats(jetstream) -> event consumer(nestjs)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 93.6%
  • JavaScript 6.4%