01. Learn middleware methods and skills
1. Understand the role of middleware in the project architecture and the underlying implementation of each middleware. 2: you can use some analogy life concept to understand the middleware, 3: use some kind of flow chart or diagram of the brain to comb the role of the middleware in architecture 4: try to use Java technology to realize the middleware from 5: calm down to think of middleware in the project design and the use of reason 6: if you find the corresponding alternative summary plan 7: Try writing a blog post summarizing comparisons and usage scenarios with middleware technologies. 8: Learn to view the source code of middleware and open source projects and blog posts.
02. Learning Objectives
- What is messaging middleware
- What is an agreement
- What is persistence
- Message delivery
- High availability of messages
- Clustering of messages
- Fault tolerance of messages
- Redundancy of messages
What is message-oriented middleware
In actual projects, most enterprise projects adopt the monomer architecture mode in the early stage, as shown in the figure below:
04. Monomer architecture
In enterprise development, most of the early architecture is monomer architecture model of architecture, and the typical characteristics of this architecture: is all of the business and module, the source code, static resource files are placed in an engineering, such as if one of the module upgrade or a small change of iteration to recompile and redeploy the project. The problems of this architecture are as follows: 1: the coupling degree is too high; 2: the cost of operation and maintenance is too high; 3: it is not easy to maintain; 4: the cost of server is too high; 5: the complexity of upgrade architecture will increase, so there will be subsequent distributed architecture system. The following
Distributed architecture
What is a distributed system?
In plain English, a request is processed by multiple services (services or systems) on the server
Unlike a singleton architecture, where a request is initiated and the JVM schedules threads (specifically the Tomcat Thread pool) to allocate threads to process the request until it is released, distributed systems are: a request is executed by multiple systems in collaboration, and the JVM and environment may be independent. If you want to build a bird’s nest or a large building, you must coordinate and distribute all links. This is also a problem to be deployed and considered in the later stage of the project development. The characteristics and problems of distributed architecture system are as follows:
Problems 1: high cost of learning and too much technology stack 2: higher cost of operation and maintenance and server 3: higher cost of personnel 4: higher load of the project 5: doubled increase of errors and fault tolerance 6: high cost of server ports and communication 7: Security concerns and factors force you to choose RMI/ MQ-related server-side communication.
Advantages 1: independent service system, less occupied server resources and less occupied hardware costs, to be exact: reasonable allocation of service resources, no waste of server resources 2: independent maintenance and deployment of the system, reduced coupling, pluggability. 3: the choice of system architecture and technology stack can be flexible (instead of simply choosing Java). 4: Flexible deployment will not cause paralysis and service shutdown caused by the deployment of the platform.
06. Architecture of distributed system based on message-oriented middleware
As can be seen from the above figure, the message middleware is: 1) to use reliable message passing mechanism for system and system direct communication; 2) by providing message passing and message queuing mechanism, it can extend inter-process communication in distributed system environment.
07. Application scenarios of message middleware
1: cross-system data transmission 2: high-concurrent traffic peak clipping 3: data distribution and asynchronous processing 4: big data analysis and transmission 5: distributed transactions For example, when you have a data to be migrated or too many concurrent requests, for example, you have 10W concurrent requests to place orders, we can place these orders before they are stored in the database. We can stack order requests into message queues to make them robustly stored and executed.
Common message-oriented middleware
ActiveMQ, RabbitMQ, Kafka, RocketMQ, etc.
09. How to understand the nature and design of message middleware
It is a technical service that accepts data, receives requests, stores data, sends data and other functions.
MQ message queues: Responsible for receiving, storing, and delivering data, so performance is too high for common services and technologies.
Who produces, stores, and consumes messages?
MQ are easy to design your idea and nature, is a production of the news production, find a place to store information, and consumer spending, but how the design process message 1: production of how the data is passed to the MQ 2: MQ middleware how to store data to 3: how does the message distributed to the consumer side 4: abnormal during production. 5: How to ensure reliable consumption of consumers 6: if the message is not lost, that is, to carry out persistent processing. The above can be divided into five parts: 1: message protocol 2: message persistence mechanism 3: message distribution mechanism 4: message high availability design 5: message high reliability design
10. What is messaging protocol
Protocol: a set of agreements that computers follow. Only by following the same conventions can computers communicate with each other properly and effectively. The protocol has three characteristics: 1. Syntax: the structure of data should be consistent; 2. Semantics: the information to be sent, the action to be completed, and the corresponding action. 3: Sequence (synchronization) : description of how to ensure the effective order of events. For example, HTTP or TCP is a common protocol. HTTP is used as an example.
The HTTP protocol has three elements: 1: Syntax: HTTP defines the format of request packets and corresponding packets. 2: semantics: operations initiated by the client are called requests (such as Get/Post). 3: timing: each request corresponds to one response.
Both Http and TCP are not suitable for message queue protocols for the following reasons: 1. The request header and response header are very complex, which is not conducive to high-performance transmission and affects the transmission speed. 2. 3: The main reason is that Http is a short link, and the response breaks down after every interaction and request. It is not conducive to the stable data acceptance of middleware. Because message-oriented middleware is constantly retrieving message content effectively over time.
More common MQ message queue protocols are used: OpenWire, AMQP, MQTT, Kafka, OpenMessage.
12, summary
In fact, choosing single architecture or distributed architecture is a stage of project development. At any stage, choosing the appropriate architecture mode should not be pursued blindly. The consequences and problems caused in the end need to pay for themselves. But learning and exploring new technologies as a developer is something that every developer should keep thinking about. When we are unable to change the society and the world, in order to live and survive, we must cater to the needs of enterprises and the market, give full play to your value and talent, create value and realize self.