后浪笔记一零二四

2安装及命令行基础功能使用

nats服务端和客户端

服务端: github.com/nats-io/nats-server

客户端: github.com/nats-io/natscli

启动服务端

1
$ nats-server

常用的客户端操作

发布-订阅模式

  1. 订阅消息(开两个窗口执行如下命令)
1
2
# 订阅hello 这个主题
$ nats sub hello
  1. 发送消息
1
2
# 往hello主题发送 world 消息
$ nats pub hello world

发送完消息,所以订阅hello主题的客户端都会收到消息

队列模式

  1. 订阅消息(多窗口,模拟多个订阅者)
1
$ nats sub hello --queue=q1
  1. 发布消息
1
2
3
4
$ nats pub hello world

# 连续发10个消息
$ nats pub --count=100 hello "world-{{Count}}"

request-response 模式

  1. 接收消息
1
2
# 订阅hello主题,收到消息后,就回复消息“cj”
$ nats reply hello "cj"
  1. 发送消息
1
nats request hello "world"

专题:

本文发表于 2022-01-01,最后修改于 2022-01-01。

本站永久域名「 jiavvc.top 」,也可搜索「 后浪笔记一零二四 」找到我。


上一篇 « 1消息中间件NATS基础知识 下一篇 » 3Go SDK的使用

赞赏支持

请我吃鸡腿 =^_^=

i ysf

云闪付

i wechat

微信

推荐阅读

Big Image