传输层的各种模式——ZeroMQ 库的使用

最近在研究 ZeroMQ 库的使用,所以在这里总结一下各种模式,以便日后拿来使用。

关于 ZeroMQ 库,我就不多介绍了,大家可以参考下面一些文章,以及他的官网、使用指南、API 参考、项目仓库等内容。

开源点评:ZeroMQ简介

ZeroMQ的学习和研究

ZeroMQ 的模式

ZeroMQ 的目标是成为 OSI 模型的传输层(Transport Layer)的标准协议,所以他支持各种操作系统,支持多达30种以上的语言,是跨平台、跨语言的传输层库,而且性能是其绝对优势。所以对于进程间通信、节点间通信均可以使用他,可以用他直接替代 socket 的操作。而且用过之后就知道,他用起来非常的简单,学习成本很低,我只用了 1 天时间就把他的 3 种常用模式用 Python 实现了,代码在这里,大家可以参考一下,接下来准备用 C++ 再实现一遍。

ZeroMQ 总结的通信模式如下:

  • PUB and SUB
  • REQ and REP
  • REQ and ROUTER
  • DEALER and REP
  • DEALER and ROUTER
  • DEALER and DEALER
  • ROUTER and ROUTER
  • PUSH and PULL
  • PAIR and PAIR

ZeroMQ 总结的应用模式如下:

  • Request-reply, which connects a set of clients to a set of services. This is a remote procedure call and task distribution pattern.
  • Publish-subscribe, which connects a set of publishers to a set of subscribers. This is a data distribution pattern.
  • Pipeline, which connects nodes in a fan-out / fan-in pattern that can have multiple steps, and loops. This is a parallel task distribution and collection pattern.

当然,实际使用中还得了解一些解决具体问题的模式,所以下面把使用指南中的一些模式整理如下,方便自己日后拿来使用。

最常用的三种模式:

1. Request-Reply

Request-Reply

Extended Request-reply

Request-reply Broker

Multithreaded Server


2. Publish-Subscribe

Publish-Subscribe

Pub-Sub Network with a Proxy

Extended Publish-Subscribe

Pub-Sub Forwarder Proxy

Pub-Sub Synchronization


3. Parallel Pipeline

Parallel Pipeline

Parallel Pipeline with Kill Signaling


其他模式:

其他模式只是上面三种模式的加强而已,所以也是分为三大类。

A. Request-Reply Patterns

1. The Load-balancing Pattern

Load-Balancing Broker


2. The Asynchronous Client-Server Pattern

Asynchronous Client-Server

Detail of Asynchronous Server

Cluster Architecture

Multiple Clusters

Idea 1 - Cross-connected Workers

Idea 2 - Brokers Talking to Each Other

Cross-connected Brokers in Federation Model


3. Client-side Reliability (Lazy Pirate Pattern)

The Lazy Pirate Pattern


4. Basic Reliable Queuing (Simple Pirate Pattern)

The Simple Pirate Pattern


5. Robust Reliable Queuing (Paranoid Pirate Pattern)

The Paranoid Pirate Pattern


6. Service-Oriented Reliable Queuing (Majordomo Pattern)

The Majordomo Pattern


7. Disconnected Reliability (Titanic Pattern)

The Titanic Pattern


8. High-availability Pair (Binary Star Pattern)

High-availability Pair, Normal Operation

High-availability Pair During Failover

Binary Star Finite State Machine


9. Brokerless Reliability (Freelance Pattern)

The Freelance Pattern


B. Publish-Subscribe Patterns

1. Pub-sub Tracing (Espresso Pattern)

2. Slow Subscriber Detection (Suicidal Snail Pattern)

3. High-speed Subscribers (Black Box Pattern)

The Simple Black Box Pattern

Mad Black Box Pattern


4. Reliable Publish-Subscribe (Clone Pattern)

Publishing State Updates

State Replication

Republishing Updates

Clone Client Finite State Machine

High-availability Clone Server Pair


C. Parallel Pipeline Patterns

暂无

你可能感兴趣的:(架构,编程)