nsq基础

介绍

技术 特性 适用场景 说明
NSQ
- 基于Go语言编写
- 分布式和分散的拓扑,没有单点故障,支持容错和高可用性,并提供可靠的消息交付保证
- 支持横向扩展,没有任何集中式代理
- 易于配置和部署,并且内置了管理界面
消息队列 - 官网
- Doc
- quick_start
- Github

运维

安装

MacOS

1
$ brew install nsq

CentOS

1
2
$ wget https://s3.amazonaws.com/bitly-downloads/nsq/nsq-1.2.0.linux-amd64.go1.12.9.tar.gz
$

Docker

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Run nsqlookupdAnchor link for: run nsqlookupd
$ docker pull nsqio/nsq
$ docker run --name lookupd -p 4160:4160 -p 4161:4161 nsqio/nsq /nsqlookupd

# Run nsqd
$ docker pull nsqio/nsq
$ docker run --name nsqd -p 4150:4150 -p 4151:4151 \
nsqio/nsq /nsqd \
--broadcast-address=<host> \
--lookupd-tcp-address=<host>:<port>

# Using TLS
$ docker run -p 4150:4150 -p 4151:4151 -p 4152:4152 -v /home/docker/certs:/etc/ssl/certs \
nsqio/nsq /nsqd \
--tls-root-ca-file=/etc/ssl/certs/certs.crt \
--tls-cert=/etc/ssl/certs/cert.pem \
--tls-key=/etc/ssl/certs/key.pem \
--tls-required=true \
--tls-client-auth-policy=require-verify

# Persisting NSQ Data
$ docker run nsqio/nsq /nsqd \
--data-path=/data

Docker-Compose

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# docker-compose.yml
version: '3'
services:
nsqlookupd:
image: nsqio/nsq
command: /nsqlookupd
ports:
- "4160"
- "4161"
nsqd:
image: nsqio/nsq
command: /nsqd --lookupd-tcp-address=nsqlookupd:4160
depends_on:
- nsqlookupd
ports:
- "4150"
- "4151"
nsqadmin:
image: nsqio/nsq
command: /nsqadmin --lookupd-http-address=nsqlookupd:4161
depends_on:
- nsqlookupd
ports:
- "4171"
1
2
3
4
5
6
7
8
# 启动
$ docker-compose up -d

# 查看容器状态
$ docker-compose ps

# 查看日志
$ docker-compose logs

启动

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 启动nsqlookup
$ nsqlookupd

# 启动nsqd
$ nsqd --lookupd-tcp-address=127.0.0.1:4160

# 启动nsqadmin
$ nsqadmin --lookupd-http-address=127.0.0.1:4161

# 发布第一个消息(同时创建topic)
$ curl -d 'hello world 1' 'http://127.0.0.1:4151/pub?topic=test'

# 使用nsq_to_file启动一个client来接收消息
$ nsq_to_file --topic=test --output-dir=/tmp --lookupd-http-address=127.0.0.1:4161

# 验证
$ tail -f test.192.2020-03-25_16.log

查看管理后台

http://127.0.0.1:4171/

坚持原创技术分享,您的支持将鼓励我继续创作!
0%