1-message transmission system (chapter 3 of the original book)

Source: Internet
Author: User
Tags msmq

The message passing system is a solution for sharing data. Its existence enables the integrated applications to focus on the data to be shared.

PS: the term is Microsoft's name.

1. Message channel (Queue)
A Message channel is a pre-configured message container based on rules published in the system.
Channel technology is the core of asynchronous communication. Although sender and consumer er do not know where each other is, they must know the queue in which the message should be placed.
A new message transmission system generally does not have any channels. Communication can only start after the queue is set according to rules.
PS: channel is called in the original text. This name is easily confused with the Chinese name "Pipeline" of pipe. In addition, Ms uses the "queue" to more visually indicate that this is a container.

2. Message)
The data container carries the data into the system exists specifically to transmit it to each demand side.
Messages are encapsulated instead of directly passing data. Because each application may have different definitions on the data format and dependency environment, and the data itself is not suitable for complex transfer environments. A message is not interested in the encapsulated data itself. Its main task is to describe the transmitted information, source, and sink, and enter the queue for systematic collection.
Message Components:
You can think of the header as an envelope or a sticker on the package: It says what it is and where it is sent (source), to which to send (chinanetcenter ).
Body content or gift in the package. Well, the postman cannot see what they wrote in the love letter. Of course, his task is to send mail, and our private information is irrelevant to him.

3. Pipelines and filters (pipe & filter)
A filter is a Black Box Process of the data carried by messages. Example in the original article: encrypt and compress the text contained in the received message and then transfer it again. Filters are specially designed for the data carried by messages. They do not change the message flow or process the message header.

Pipeline: there is no specific description in the original text, and its role and purpose are completely confused with the channel.
According to my observation, the pipeline should be a special stack-type queue, and Its Entry and Exit have been fixed and pointed to at the time of creation. Its main function is to provide a dedicated queue buffer for the filter. The filter entry requires an MTS queue to provide the buffer function, because the filter exists as the internal processing mechanism of the message system, and the processing delay must be considered.

Pipeline processing: The image in the book can be understood faster. However, the original intention is quite simple. It splits the serial processing of a single thread into multiple units, units are connected by asynchronous messages (that is, messages processed by the last unit are buffered by a queue and provided to the next unit for processing ). In this way, it becomes multi-thread, because Unit B reports that unit A is idle to get new messages while processing the data transmitted by unit. There are active jobs on both the and B hands that are successively related in the process. This is the pipeline.
This mode maximizes throughput. However, because the maximum speed of serial processing depends on the worker with the slowest hands, you need to add a helper (Parallel Processing) to the worker ).

Parallel Processing: If the processing delay of a filter in multiple serialized filters is intolerable, multiple identical filters can be used to concurrently process messages accumulated in the ingress pipeline. In this mode, a competitive consumer mechanism (point-to-point channel function) needs to be added to the ingress channel ). If the messages in the stack in the Entrance Pipeline are ordered, the egress management of the Parallel processor needs to be attached with the reshuffling tool to restore the sequence.

PS: filter is an old term. It exists in the Communication Field at birth (the original article records the pipe & filter concept proposed in 1978, -_-.........), It is a widely spread professional term. At present, it does not simply stop some messages or delete some parts of the message. The work it undertakes is diversified, and all data processing can be done within it. Therefore, the "component" name is more suitable for its role. Of course, we still call it a filter, because those who better understand this concept are used to this term.

PS2: In the original article, C # And MSMQ are used as a filter base class processor (oh my God, which is also called a processor by Microsoft ......... It seems that it is Ms fans. After reading the concept and sketch, it is also called its processor. However, I like C1's samples and I hate msdn .).
Hehe, don't complain. This sectionCodeThe pipe & filter concept is provided. This class has two external interfaces: inputqueue and outqueue. It is the messagequeue Class Object of MSMQ, which are the asynchronous communication and buffer mechanism of proxy Entry and Exit respectively.
The core of the class is the trigger and Implementation of the Message Processing Method processmessage (some code is not written in the base class, which is reloaded by the specific class ), triggered by the receivecompleted event of inputqueue and passed the passed message object to processmessage for processing. The output message object is sent to the outqueue column to complete a processing process.
At the end of the Code, retrieve the beginreceive method of inputqueue and return to the initial listening status.

4. vro
The emergence of routers is inevitable. The router provides a one-to-multiple branch Mechanism for the message system. (A system without selectable branches does not exist. If so, it would be great. The flow chart would be like a waterfall, and it would be as refreshing as it was.
The message system also needs to determine the message flow, which is as natural as if and switch in our code.

Router features: Do not process any messages, but only specify a point for message transmission.
Based on the internal logic, the vro determines which egress channel the message is connected. Inserting a vro increases the scalability of the process. The vro integrates all logic judgments. The filter on each branch only needs to care about how to process messages (processor-based ). When a new situation is added, you only need to modify the logic of the router and insert the processing component of the new situation. If you do not need to modify the vro as you expand the vro, you can refer to the solution described in later sections in the original article.

A fixed router is a router with only one input and one output channel. It can be used as a preparation for future expansion or as a repeater to provide relay for other passive components (transformer or channel adapter) that do not have the message fetching function.

Vro status: A stateless vro creates a routing policy based on only one message at a time (referenced in the original article, which is super APT ). A vro that can save the status can provide other functions, such as recording a list of passing message headers. It is found that the incoming messages are duplicated with the list, the duplicate messages are routed to the channel to be destroyed.

Vro and control bus: the connection between the vro and the control bus. You can introduce global variables to the router's routing policy. The unchangeable logic in the vro is called hard encoding. It is equivalent to the BIOS of the hardware router.

Of course, the pipe & filter module can also implement conditional judgment to block unwanted flows. This will reduce the reusability of the filter because of the synthesis of the conditional logic, and cause errors when the module is combined with other modules. Worse, the filter is unidirectional, meaning that it cannot forward messages to the egress pipeline or destroy messages because another branch is waiting to read the message. To put unused messages that have been consumed back into the original channel, you must write a new non-conforming channel for implementation. Therefore, using pipe & filter to implement branch will become tightly coupled.

OK. It's time for example C # And MSMQ.
The interface code is similar to the filter code in the previous section. outqueue is extended to outqueue1 and outqueue2, which is a one-to-two branch.
The branch determination logic is simple and interesting, hehe. Let the routing switch swing evenly around like a tumbler. This logic can be used if two clerks share the workload equally by file in the same office. Toggle =! Toggle ^_^.

5. Message Converter
It is used to convert the formats of two messages at different levels. This XLST syntax is quite troublesome. Currently, only field conversion between data structure layers is used. You can check it later.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.