Giter Site home page Giter Site logo

dubbo-notes's People

Contributors

kun-song avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

205140040

dubbo-notes's Issues

Multicast 注册中心

Dubbo 有多重注册机制,例如广播、Zookeeper 和 Redis,其中广播注册是通过 MulticastSocket 实现的。

为什么需要注册中心?

几乎所有分布式系统中,都有类似注册中心的概念( or 组件),注册中心解决了 服务发现 的问题。

服务发现

概念

服务发现是指 consumer 查找 provider 地址(IP + port)的过程。

服务是什么?

服务发现中的服务含义非常广泛,数据库实例、缓存实例、RPC provider、微服务、网络设备等等,都可被视为服务。

在云计算之前,服务部署在物理机器上,IP 地址不变,因此即使没有服务发现,通过 硬编码 服务的地址,也能满足需求。

云计算时代,尤其是 Docker 的快速发展,使得 硬编码 几乎无用武之地,因为服务不再部署在物理机上,每次新创建的实例,其 IP 很可能与上次不同,因此需要更加灵活的服务发现机制。

核心功能

服务发现是 SOA 架构(service oriented architecture)、微服务架构的核心组件,必须提供以下 3 个功能:

  • 服务注册(Registration)
  • 服务目录(Directory)
  • 服务查找(Lookup)

复杂系统中,服务的元数据非常复杂,因此 lookup 非常重要,这里的查找不仅仅指查找到服务的元数据(地址、配置等),还包括服务的部署状态,并提供集中管理服务实例的能力。

实现方式

  • Zookeeper
    • 提供配置管理、leader 选举、分布式锁等;
    • 缺点:复杂
  • etcd
    • 与 Zookeeper 类似,在 Docker 相关设施中使用广泛
  • Consul
    • 服务发现、节点健康检查、K/V 存储、配置管理
    • 支持 DNS/HTTP 两种 API,而 Zookeeper 需要单独的客户端
  • Eureka

参考:

Dubbo 中的服务发现

Dubbo 是 SOA 框架,自然也需要支持服务发现,Dubbo 有 5 中服务发现机制,其中常用的有 3 种:

  • 基于 multi cast
  • 基于 Redis
  • 基于 Zookeeper

阿里内部通过数据库实现注册中心,而外部一般使用 Zookeeper 实现。

Redis 注册中心

Redis Pub/Sub 模式

publish/subscribe 模式是一种常见的消息模式,该模式下,publisher 不直接向 subscriber 发送消息,而是将消息发送到 channel/topic,subscriber 订阅自己感兴趣的 channel/topic,不需要了解 publisher 即可获取消息。

pub/sub 模式解耦了 publisher 和 subscriber,可扩展性更强,允许更动态的网络拓扑。

Redis 通过 PUBLISH, SUBSCRIBEUNSUBSCRIBE 3 个命令实现了 pub/sub 模式。

subscribe

Redis 客户端通过 SUBSCRIBE 指令订阅 channel:

SUBSCRIBE c1 c2

Redis 服务器会将其他客户端 publish 到 c1 c2 的消息 推送 到订阅 c1 c2 的客户端。

注意

  • 客户端订阅 channel 后成为 subscriber,此后不应该再 发送指令
  • 订阅模式下,允许使用的指令:
    • SUBSCRIBE
    • PSUBSCRIBE
    • UNSUBSCRIBE
    • PUNSUBSCRIBE
    • PING
    • QUIT

Dubbo Redis 注册中心

Dubbo 使用 hash 保存注册信息,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.