On the message queue

  First of all we need to know why the message queue? It gives us solve the problem?

  The answer is simple, the message queue is used for high concurrent processing system causes the message to appear blocked, if your system does not appear high concurrency or message congestion does not exist, then you do not need the message queue.

       Outline

       Message Queue Middleware is a key component in a distributed system, can help solve application coupled, asynchronous messaging, traffic clipping and other issues.

       Because of its high performance, high availability and scalability, the message queue has become indispensable for large distributed systems middleware. The most commonly used ActiveMQ \ RabbitMQ \ Kafka \ ZeroMQ and so on.

  Scenarios

  1.   Asynchronous processing: e.g. SMS notifications push terminal state, App push, user registration
  2. Data synchronization: synchronize business data push
  3. Retry compensation: accounting failure retry
  4. Decoupling: uplink and downlink communications, terminal anomaly monitoring, distributed event center
  5. Cutting the peak flow rate: single spike treatment at the scene
  6. Publish-Subscribe: HSF service status change notification, distributed event center
  7. High concurrency buffer: logging services, monitoring report

  This place is relatively concise summary, if not quite understand the details can look at other blog, there will be illustrated explanation.

  

  Message Model 

  There are two news models P2P (Point to Point), Publish / Subscribe (Pub / Sub).

   P2P mode

  P2P mode comprising three roles: a message queue (Queue), a sender (Sender), receivers (Receiver). Each message is sent to a particular queue, the receiver acquires the message from the queue. It retains the message queue until they are consumed or timeout.

  P2P features:
    1, each message has only one consumer (Consumer) (i.e., once the consumer, it is no longer message in the message queue)
    2, between the sender and the receiver is not dependent on time, that is to say when the sender sent the message, whether the recipient has no running, it will not affect the message is sent to the queue
    3, the recipient needs to successfully reply to a message queue after successful reception
  of each message will be sent if you want to succeed deal with the case, you need a P2P mode.

 

  Pub / Sub mode

  Contains three roles topics (Topic), Publisher (Publisher), subscribers (Subscriber) more publishers send a message to Topic, the system will deliver these messages to multiple subscribers.

  Pub / Sub features:
    1, each message can have multiple consumers
    2, dependent on the time between publishers and subscribers. After for a theme (Topic) subscribers, it must create a subscriber, the publisher's message to the consumer
    3, in order to consume the message, the subscriber must keep the state running
    4, in order to alleviate such strict time correlation, allowing subscribers can create a persistent subscription. Thus, even if the subscriber is not activated (run), it can also receive the message publisher.
  If you want to send a message it can not be done any treatment, or those who are only one message processing or can be processed multiple consumers, then the Pub / Sub model can be used.

   Consumer news

  Produce and consume messages are asynchronous. For the consumer, the consumer can consume the message in two ways.
(1) Synchronous
subscriber or recipient of the message received by the receive method, method blocks receive (or timeout before) prior to receiving the message;

(2) Asynchronous
subscribers or recipients can be registered as a message listener. When the message arrives, the system automatically calls onMessage method listener.

   Comparative mainstream message queue:

  Behind it a very high performance Kafka described as an example below.

  In Kafka architecture has a plurality of Producer, a plurality Broker, Consumer plurality, may correspond to each of the plurality of Producer Topic, each corresponds to only one Consumer Consumer Group.

  整个 Kafka 架构对应一个 ZK 集群,通过 ZK 管理集群配置,选举 Leader,以及在 Consumer Group 发生变化时进行 Rebalance。

 

  消息队列的基础就讲解到这里,我已经在腾讯云申请了一个云服务器,也已经安装了kafka消息队列,后面我将用实际操作来给大家演示kafka消息队列的使用。

 

Guess you like

Origin www.cnblogs.com/chenchaochao034/p/11184946.html