Large-scale technology program message queue system!

  Previous article we analyzed the decoupling process how to use the messaging middleware of the two systems. XIAOXI 

  At the same time, we also mentioned, the use of messaging middleware also facilitates multiple systems at the same time is a data subscription, for multiple systems for different purposes.

  A current architecture as shown in FIG.

  


  In this figure, we can clearly see, real-time computing platform released a data messaging middleware, and then the following:

  Data query platform will subscribe to the data, and into their own local cache database cluster and the cluster, then external services data queries

  Data quality monitoring system will monitor the results according to certain business rules, if there are data calculation error, it will immediately alarm

  The data link tracking system will collect the results as a link node, and a link to the entire computing data are collected and assembled by a series of calculated data link ground storage, and finally calculate if a data error, and on It can immediately be calculated by backtracking links troubleshooting

  Through the above review, we have clearly, in the scenario described above, using a messaging middleware to be decoupled, and secondly to implement the message "Pub / Sub" model, implement publish and subscribe messages.

  This article, we will go to a landing practice, based on the RabbitMQ messaging middleware, how to implement a data simultaneously subscribe to multiple systems "Pub / Sub" model?

  2. queue-based messaging middleware consumption model

  


  In fact, the most basic is to support the use of RabbitMQ queue consumption model on the map, you can understand there is a queue for the internal RabbitMQ, producers continue to send data to the queue, the message into the queue in the order in the queue.

  Now suppose there are four data queue, we have two consumers with consumption of the queue data.

  At this time, each consumer will be evenly distributed to the two data, that is to say four data evenly assigned to each consumer, every consumer is only part of the data processing Bale, this is a typical consumer queue model.

  This articles gives RabbitMQ codes in the queue that basic consumption model to achieve, and how to ensure that data is not lost when the consumer goes down, how to get RabbitMQ cluster of queue and message are for persistence, the overall code to achieve more complete , you can reference.

  3. Based on the message middleware "Pub / Sub" Model

  In addition to the basic model, messaging middleware can also implement a "Pub / Sub" model, or "publish / subscribe" model, Pub is Publish, Sub is Subscribe.

  This model can support multiple systems at the same time a data consumer, that is to say each data release out of you, will be broadcast to each system, look:

  


  In other words, the effect on the graph we want to achieve: real-time computing platform to publish a series of data messaging middleware, and then data query platform, data quality monitoring systems, data link tracking system, will subscribe to data, will consume to complete the data with a copy of each system can use the data according to their needs.

  Well, this so-called "Pub / Sub" model, based on RabbitMQ should be how to deal with it?

  4. RabbitMQ of exchange in the end is what?

  In fact, in RabbitMQ is not allowed inside the producers deliver the messages directly to a queue (queue) in, but only so that producers deliver a special message to the components inside the RabbitMQ, called the "exchange", you can probably understand as a message routing component.

  In other words, real-time computing platform message sent out to the RabbitMQ are made in exchange for a reception.

  Then the exchange will decide according to certain rules you want to forward this message queue to which route to go, which is actually a core of the RabbitMQ messaging model.

  We look at the following chart to understand it.

  


  The default exchange

  You might say, when I delivered the message to RabbitMQ, and there is no exchange with, but why was the message delivered to the queue go of it?

  That's because you use the default exchange, he will direct routes the message to the queue you specify go, so if you use simple queue consumption model, eliminating the need for the concept of exchange.

  


  Prior to the above paragraph is to show you, so that the message persistence way of delivering the message.

  We note inside the first argument is an empty string, the empty string mean, that deliver the message to the default exchange to go, then he will route messages to a specified queue we go.

  6. The message delivered to the fanout exchange

  In RabbitMQ years, exchange such assemblies there are many types, such as: direct, topic, headers and fanout, this article we look at the last fanout.

  This exchange component is actually very simple, you can create a fanout type of exchange, then the exchange to bind multiple queue, then as long as you deliver a message to this exchange, he will route messages to all his bindings queue.

  Use the following code to create an exchange, for example, in real-time computing platform (producer) of the code, you can add the following paragraph, to create a fanout type of exchange.

  The first parameter we call "rt_compute_data", this is the exchange of names, rt is the abbreviation for "RealTime", meaning that real-time calculation system of result data.

  The second parameter is the definition of this type of exchange is "fanout".

  channel.exchangeDeclare(rt_compute_data, fanout);

  Then we use the following code to deliver a message to us to create a good exchange components go:

  


  It will be noted at this time the message is delivered to a specified exchange gone, but the route to which queue to go do? At this point we do not yet determined, allowing consumers to own their own queue is bound to go up this exchange can.

  7. Binding own queue to the exchange

  The code to consumers also modify here before we closed the autoAck mechanism, and then each time to manually ack.

  


  The code above, each consumer system, there will be something different, that every consumer needs to define its own queue, and then bound to exchange up.

  For example, data query platform of the queue is "rt_compute_data_query", data quality monitoring platform queue is "rt_compute_data_monitor", the queue data link tracking system is "rt_compute_data_link".

  Subscribe to this data so that each system has in fact one of their own queue, the queue is then routed into the exchange will be calculated for all real-time data platform production.

  And because multiple modes of queues, each system can be deployed in clusters of consumers to make purchases and processing of data, very convenient.

  8. Overall Chart

  


  As shown above, real-time computing platform will deliver the message to "rt_compute_data" this "exchange" to go, but he did not specify the exchange to route the message to which queue, because he himself is not known.

  Then data query platform, data quality monitoring systems, data link tracking system, you can declare your own queue, are bound to exchange up.

  Because the binding queue and exchange, where the data is to subscribe to their own designated platform. And because this is a fanout exchange type, as long as he received the data, the data will be routed to all bound to go to his queue, the queue so that each has the same copy of the data for the corresponding platform to the consumer.

  And for each platform own queue, he still can be deployed in clusters to consumer services consumption own a queue, their queue data is evenly distributed to various consumer service instance to handle each consumer will get to the part of the service instance The data.

  This is not to achieve a subscription to a different system data "Pub / Sub" model?

  Of course, RabbitMQ also supports a variety of different types of exchange, can achieve a variety of complex functions, the follow-up we come back to you through the actual online system architecture case to illustrate the use of messaging middleware technology.


Reproduced in: https: //juejin.im/post/5cf61ae0e51d45554877a589

Guess you like

Origin blog.csdn.net/weixin_33912638/article/details/91435538