nsq.reader错误connection closed
gorm模型定义原理借鉴分析

nsq双机集群部署

妙音 posted @ 2021年4月02日 13:27 in golang with tags nsq , 1471 阅读

问题

 
双机nsq如果部署集群,如何保证高可用性
 
1. 单节点nsqlookup故障?
 
2. 单节点nsq故障?
 
3. 消息丢失?
 

环境说明

 
两台机器
 
机器A 192.168.120.1
 
机器B 192.168.120.101
 

部署过程

 
部署方法
 
1. 机器A部署一套nsqlookup+nsqd
 
2. 机器B部署一套nsqlookup+nsqd
 
3. 生产者将消息同时写入两个nsqd
 
3. 消费者监听两个nsqlookup
 
结构图
 
 
机器A
 
nsqlookupd -broadcast-address 192.168.120.1
nsqd -lookupd-tcp-address=192.168.120.1:4160 -lookupd-tcp-address=192.168.120.101:4160 -broadcast-address 192.168.120.1
 
机器B
 
nsqlookupd -broadcast-address 192.168.120.101
nsqd -lookupd-tcp-address=192.168.120.1:4160 -lookupd-tcp-address=192.168.120.101:4160 -broadcast-address 192.168.120.101
 

pynsq测试脚本

 
生产者
 
import nsq
import tornado.ioloop
import time

def pub_message():
    writer.pub('test', str(time.strftime('%H:%M:%S')).encode("utf-8"), finish_pub)

def finish_pub(conn, data):
    print(data)

# 写入两个nsq好处: 1.防止nsqd单点故障  2.防止消息丢失
writer = nsq.Writer(['192.168.120.101:4150', '192.168.120.1:4150'])

tornado.ioloop.PeriodicCallback(pub_message, 1000).start()
nsq.run()
 
消费者
 
import nsq


def handler(message):
    print(message, message.id, message.timestamp, message.attempts, message.body)
    return True

# 防止nsqlookup故障
r = nsq.Reader(message_handler=handler,
               lookupd_http_addresses=['http://192.168.120.1:4161', 'http://192.168.120.101:4161'],
               topic='test', channel='abc', lookupd_poll_interval=15)

nsq.run()
 

总结

 
只要有一个nsqlookup和一个nsqd存活,系统就不会挂
 
 
 
Avatar_small
Imamia Quran Academy 说:
2023年8月04日 07:26

Very nice article, I enjoyed reading your post, very nice share, I want to twit this to my followers. Thanks. It is very difficult to find a good Shia Quran Center with Shia teachers abroad except in Muslim or especially Shia majority countries. Fortunately, Imamia Quran Academy has realized this need and has launched the Shia Online Quran Center.

Avatar_small
Imamia Quran Academy 说:
2023年8月04日 07:28

Nice blog. I enjoyed reading your articles. This is truly a great read for me. I am from Imamia Quran Academy. The Shia Online Yassarnal Quran classes provide one on one interaction features between teacher and student.

Avatar_small
hkseo 说:
2023年9月09日 20:43

2nd amendment apparel is more than clothing; it's a symbol of your values. Visit here to find the perfect piece. 2nd amendment apparel

Avatar_small
hkseo 说:
2023年9月10日 22:34

Internet marketing is a powerful tool that can help you grow your business, but it's important to use it wisely. marketiing 1on1

Avatar_small
hkseo 说:
2023年9月11日 15:08

Experience the thrill of connection with these intimate mementos, each one carrying the whispers of desire. Want to know more? Click here for an intriguing experience. used panties websiteused panty sites


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter