本篇演示如何使用NSQ消息中间件来编写Micro的Pubsub服务,本篇由Jayn Yang提供,略作结构上的删改。
我们假设读者的NSQ工作在本地标准地址:
- NSQ:127.0.0.1:4150
cd cli
go run client.go
cd srv
go run server.go
我们可以看到日志打印如下信息
2019/08/05 23:54:48 Receive info: Id 0 & Timestamp 1565020484
2019/08/05 23:54:48 Receive info: Id 1 & Timestamp 1565020485
2019/08/05 23:54:48 Receive info: Id 2 & Timestamp 1565020486
2019/08/05 23:54:48 Receive info: Id 3 & Timestamp 1565020487
2019/08/05 23:54:48 Receive info: Id 4 & Timestamp 1565020488
2019/08/05 23:54:49 Receive info: Id 5 & Timestamp 1565020489
2019/08/05 23:54:50 Receive info: Id 6 & Timestamp 1565020490