anthor addr: http://www.cppblog.com/cdy20/archive/2012/04/06/170252.html
Lastupdate : two thousand and twelve year four month six day Cai Dongyun
http://www.LomoX.hk Community publishing.
Ps: The blog can't post pictures. You can download them from the attachment: A design method using message framework segmentation and extension
Traditional interface ui and uilogic The isolation mode adopts the interface mode. In order to understand the coupling and unify the business between the isolation layers. As shown in the figure, ui Layer is responsible for the interface. You can use any language you want ; uilogic Layer, you just do ui Handed down io , keyboard and mouse operation behavior analysis ; applogic You are responsible for the business and calculate the tasks to be performed. In this way, one requirement can be developed by three people at the same time.
The isolation of large-scale basic software for decoupling causes the expansion of interface declaration. You can see applogic Layers and uilogic The interface will expand infinitely, which will bring about maintenance costs. If the interface is internally defined, you should provide a statement for each layer when writing.
Recently, I want to provide something as an isolation layer. See the figure first.
Applogic and uilogic Only data communication. Asynchronous message mode is adopted, no matter whether you are multithreaded or single threaded. The coupling between modules disappears completely. Someone will ask you this service What to use.
use Zeromq Well, this is the speed tested on my machine
http://www.cppblog.com/cdy20/archive/2012/04/01/169791.html Single thread 100 w strip 120s That's fast. If it's enough to be the server of the local dispatcher.
How to deal with communication data? zeromq The string transmission is adopted, and we can cooperate google Of protobuf Define resolution protocol data. This thing can be compressed. The decompression protocol is very convenient. It is coupled with this high-speed mq , that's fantastic.
Zeromq As a message queue that can communicate between kernels, across processes and across machines, it inevitably provides us with more design imagination. With such an intermediate message server, we can applogic Cut into several independent modules, as shown in the figure.
As shown in the figure above, we can continue to expand applogic We can think that these modules are independent Dynamic link library, independent processes, or independent threads, all communication Access is through sending send , receive recv 。
The engineering project team I meet now has this requirement. They require concurrent development, and even two people can unify a module without four branches at the same time. A powerful message framework allows my module to be any definition.
Draw a circle and sum up:
The red circle in the figure above represents bus.
On The abstract figure is as follows.
In this way, the program can be expanded at will. Arbitrary segmentation.
There are errors and improvement methods, Please send to caidongyun19@qq.com . Thanks for reading.
Sharing promotes technology development. Cai Dongyun. www.lomox.hk
Attach a reminder:
For this framework, individual: it is suggested that the team should not have too much freedom, and some normative constraints should be made according to the characteristics of the team project. Otherwise, the quality and maintenance costs will increase.