Go 操作 nsq
一. 基于 docker-compose 搭建 nsq 集群
二. nsq 简单了解
- nsqd:一个负责接收、排队、转发消息到客户端的守护进程
- nsqlookupd:管理拓扑信息并提供最终一致性的发现服务的守护进程
- nsqadmin:一套 Web 用户界面,可实时查看集群的统计数据和执行各种各样的管理任务
- utilities:常见基础功能、数据流处理工具,如 nsq_stat、nsq_tail、nsq_to_file、nsq_to_http、nsq_to_nsq、to_nsq
三. docker-compose.yml
version: "3"
services:
my-nsq-admin:
image: nsqio/nsq:v1.1.0
command: /nsqadmin -lookupd-http-address my-nsq-nsqlookupd1:4161 -lookupd-http-address my-nsq-nsqlookupd2:4261
ports:
- "4171:4171"
my-nsq-nsqd1:
image: nsqio/nsq:v1.1.0
hostname: my-nsq-nsqd1
command: /nsqd -tcp-address 0.0.0.0:4150 -data-path /usr/local/nsq/bin/data --http-address 0.0.0.0:4151 -lookupd-tcp-address my-nsq-nsqlookupd1:4160 -lookupd-tcp-address my-nsq-nsqlookupd2:4260 -broadcast-address my-nsq-nsqd1
volumes:
- "./data1:/usr/local/nsq/bin/data"
ports:
- "4150:4150"
- "4151:4151"
my-nsq-nsqd2:
image: nsqio/nsq:v1.1.0
hostname: my-nsq-nsqd2
command: /nsqd -tcp-address 0.0.0.0:4250 -data-path /usr/local/nsq/bin/data -http-address 0.0.0.0:4251 -lookupd-tcp-address my-nsq-nsqlookupd1:4160 -lookupd-tcp-address my-nsq-nsqlookupd2:4260 -broadcast-address=my-nsq-nsqd2
volumes:
- "./data2:/usr/local/nsq/bin/data"
ports:
- "4250:4250"
- "4251:4251"
my-nsq-nsqd3:
image: nsqio/nsq:v1.1.0
hostname: ysdp-nsq-nsqd3
command: /nsqd -tcp-address 0.0.0.0:4350 -data-path /usr/local/nsq/bin/data --http-address 0.0.0.0:4351 -lookupd-tcp-address my-nsq-nsqlookupd1:4160 -lookupd-tcp-address my-nsq-nsqlookupd2:4260 -broadcast-address=my-nsq-nsqd3
volumes:
- "./data3:/usr/local/nsq/bin/data"
ports:
- "4354:4350"
- "4355:4351"
my-nsq-nsqlookupd1:
image: nsqio/nsq:v1.1.0
command: /nsqlookupd -http-address 0.0.0.0:4161 -tcp-address 0.0.0.0:4160 -broadcast-address my-nsq-nsqlookupd1
ports:
- "4160:4160"
- "4161:4161"
my-nsq-nsqlookupd2:
image: nsqio/nsq:v1.1.0
command: /nsqlookupd -http-address 0.0.0.0:4261 -tcp-address 0.0.0.0:4260 -broadcast-address my-nsq-nsqlookupd2
ports:
- "4260:4260"
- "4261:4261"
四. 启动集群
docker-compose up -d
浏览器访问:127.0.0.1:4171/nodes
五. 配置本机 hosts
因为基于 nsqlookupd 的数据发现需要访问 broadcast-address 暴露的地址,所以需要配置,同时都需要加上
127.0.0.1 my-nsq-nsqd1
127.0.0.1 my-nsq-nsqd2
127.0.0.1 my-nsq-nsqd3
六. Go 使用
正文完