分布式实时消息平台NSQ

NSQ

NSQ是一个基于Go语言的分布式实时消息平台,它基于MIT开源协议发布,由bitly公司开源出来的一款简单易用的消息中间件。
NSQ可用于大规模系统中的实时消息服务,并且每天能够处理数亿级别的消息,其设计目标是为在分布式环境下运行的去中心化服务提供一个强大的基础架构。
NSQ具有分布式、去中心化的拓扑结构,该结构具有无单点故障、故障容错、高可用性以及能够保证消息的可靠传递的特征。NSQ非常容易配置和部署,且具有最大的灵活性,支持众多消息协议。

组件

NSQ 由 3 个守护进程组成:

nsqd 是接收、队列和传送消息到客户端的守护进程。
是NSQ的核心部分,它是一个单独的监听某个端口进来的消息的二进制程序。每个nsqd节点都独立运行,不共享任何状态。当一个节点启动时,它向一组nsqlookupd节点进行注册操作,并将保存在此节点上的topic和channel进行广播。
客户端可以发布消息到nsqd守护进程上,或者从nsqd守护进程上读取消息。通常,消息发布者会向一个单一的local nsqd发布消息,消费者从连接了的一组nsqd节点的topic上远程读取消息。如果你不关心动态添加节点功能,你可以直接运行standalone模式。
nsqlookupd 是管理的拓扑信息,并提供了最终一致发现服务的守护进程。
nsqlookupd服务器像consul或etcd那样工作,只是它被设计得没有协调和强一致性能力。每个nsqlookupd都作为nsqd节点注册信息的短暂数据存储区。消费者连接这些节点去检测需要从哪个nsqd节点上读取消息。

nsqadmin 是一个 Web UI 来实时监控集群(和执行各种管理任务)。
在这里插入图片描述

消费信息

每条消息有3种结果:消费成功(FIN)、消费失败(REQ)、消费超时(TIMEOUT)。若nsqd进程意外退出,则内存中以及还没来得及刷入硬盘的消息都会丢失。
若消息在msg_timeout内没消费,则会自动重新入队列REQ;若消息在max_msg_timeout内还没消费,则会记为TIMEOUT。

admin参数

  • Message Queues:Anchor link for: message queues

Depth: Current sum of messages in memory + on disk (i.e. the “backlog” of messages pending delivery).
在内存和硬盘转存的消息总数
In-Flight: Current count of messages delivered but not yet finished (FIN), requeued (REQ) or timed out.
当前未完成的消息总数:包括发送但是没有结束,重新入队,以及超市
Deferred: Current count of messages that were requeued and explicitly deferred which are not yet available for delivery.

  • Statistics:Anchor link for: statistics

Requeued: Total times a message has been added back to the queue due to time outs or explicit requeues.

Timed Out: Total times a message has been requeued after not receiving a response from the client before the configured timeout.
Messages: Total count of new messages recieved since node startup.
Rate: The per-second rate of new messages over the previous two statsd intervals (available only when graphite integration is enabled).
Connections: Current number of connected clients.

  • Client Connections:Anchor link for: client connections

Client Host: Client ID (hostname) and on-hover the connection remote-address.
Protocol: NSQ protocol version and client user-agent.
Attributes: TLS and AUTH connection state.
NSQd Host: Address of the nsqd node this client is connected to.
In-flight: Current count of messages awaiting response that have been delivered to this client.
Ready Count: Max number of messages that can be in-flight on this connection. This is controlled by a client’s max_in_flight setting.
Finished: Total count of messages that this client has finished (FIN).
Requeued: Total count of messages that this client has requeued (REQ).
Messages: Total count of messages delivered to this client.

架构

topic消息的逻辑关键词

topic 是 NSQ 消息发布的 逻辑关键词 ,可以理解为人为定义的一种消息类型。当程序初次发布带 topic 的消息时,如果 topic 不存在,则会在 nsqd中创建。
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值