stands for Neural Autonomic Transport System
the rationale why choose NATS over other messaging system comes from this
if you prefer to quickly run through this repository to see what is possible, and familiar enough using docker compose, you can read composing
- nats server
brew install nats-server
another way to install nats-server
- nats cli
brew tap nats-io/nats-tools
brew install nats-io/nats-tools/nats
another way to install nats cli
- nats monitoring
go install github.com/nats-io/nats-top@latest
- start nats server first
nats-server --config nats-core/nats.conf
- subscribe
go run nats-core/monitor/main.go ">"
- publish
go run nats-core/pub/main.go "profit"
- subscribe
go run nats-core/sub/main.go "profit"
- publish
go run nats-core/pub/main.go "profit.sg"
go run nats-core/pub/main.go "profit.id"
- subscribe
go run nats-core/sub/main.go "profit.*"
- publish
go run nats-core/pub/main.go "profit.id"
- subscribe
go run nats-core/sub/main.go "profit.id"
go run nats-core/sub/main.go "profit.id"
- publish
go run nats-core/pub/main.go "profit.id"
- subscribe using queue
go run nats-core/subq/main.go -q poc "profit.id"
go run nats-core/subq/main.go -q poc "profit.id"
- start replier first
go run nats-core/rep/main.go -q poc "profit.get"
- request
go run nats-core/req/main.go "profit.get"
- start nats server first
nats-server --config nats-jetstream/js.conf
what kind event data to persist
- check list of stream
nats str ls --server 0.0.0.0:5222
- check report of stream
nats stream report --server 0.0.0.0:5222
- create stream
profit
in which interest to persist event data from subjectprofit.*
go run nats-jetstream/manager/main.go --cmd add -n profit -s "profit.*"
- check stream detail
nats stream info profit --server 0.0.0.0:5222
- update stream
profit
in which interest to persist event data from subjectprofit.sg profit.id
go run nats-jetstream/manager/main.go --cmd update -n profit -s "profit.sg,profit.id"
- delete stream
go run nats-jetstream/manager/main.go --cmd delete -n profit
- sync publish
go run nats-jetstream/producer/sync/main.go -msgs 1000 "profit.id"
- async publish
go run nats-jetstream/producer/async/main.go -msgs 1000 "profit.id"
how application getting a messages from stream
- check list of consumer
nats consumer ls --server 0.0.0.0:5222
- push consumer
go run nats-jetstream/consumer/main.go --cmd add-push -sn profit -cn one-push-cprofit_id -s profit.id
- push consumer with shared load balanced queue
go run nats-jetstream/consumer/main.go --cmd add-push -sn profit -cn queue-push-cprofit_id -qn poc -s profit.id
- pull consumer is automatically shared if there are multiple subscriber
go run nats-jetstream/consumer/main.go --cmd add-pull -sn profit -cn pull-cprofit_id -s profit.id
- check consumer detail
nats consumer info --server 0.0.0.0:5222
- delete consumer
go run nats-jetstream/consumer/main.go --cmd add-push -sn profit -cn test-delete -qn poc -s profit.id
go run nats-jetstream/consumer/main.go --cmd delete -sn profit -cn test-delete
- publish
go run nats-jetstream/producer/sync/main.go -msgs 1000 -d 1 "profit.id"
- subscribe
go run nats-jetstream/consumer/push/main.go -sn profit -s "profit.id"
(save last state if disconnected)
- publish
go run nats-jetstream/producer/sync/main.go -msgs 1000 -d 1 "profit.id"
- subscribe
go run nats-jetstream/consumer/push/main.go -sn profit -cn one-push-cprofit_id -s "profit.id"
- publish
go run nats-jetstream/producer/sync/main.go -msgs 1000 -d 1 "profit.id"
- subscribe
go run nats-jetstream/consumer/push/main.go -sn profit -cn queue-push-cprofit_id -qn poc -s "profit.id"
go run nats-jetstream/consumer/push/main.go -sn profit -cn queue-push-cprofit_id -qn poc -s "profit.id"
- publish
go run nats-jetstream/producer/sync/main.go -msgs 1000 -d 1 "profit.id"
- subscribe
go run nats-jetstream/consumer/pull/main.go -sn profit -cn pull-cprofit_id -s "profit.id"
go run nats-jetstream/consumer/pull/main.go -sn profit -cn pull-cprofit_id -s "profit.id"
- create stream
scheduled-message
that interest to persist event data from subjectdelayed.profit
go run nats-jetstream/manager/main.go --cmd add -n scheduled-message -s "delayed.profit"
- create durable push consumer to get data from stream
scheduled-message
go run nats-jetstream/consumer/main.go --cmd add-push -sn scheduled-message -cn queue-push-delayed_profit -qn poc -s "delayed.profit"
- subscribe
go run nats-jetstream/consumer/push/main.go -sn scheduled-message -cn queue-push-delayed_profit -qn poc -s "delayed.profit"
- publish
go run nats-jetstream/producer/delayed/main.go -msgs 5 -d 10 "delayed.profit"