Method, system, terminal device and storage medium for constructing a reactive-based observer design pattern
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CHINA CITIC BANK CO LTD
- Filing Date
- 2022-12-05
- Publication Date
- 2026-08-07
AI Technical Summary
因而实际的处理效率不高,且不利于后续的维护
[0029]本发明的有益效果:本发明在分布式消息中间件推送模式中,基于反应式观察者设计模型,可以很简单的达到消息监听器异步无阻塞,被观察者不需要根据被观察者不同的处理能力去调整推送策略,它大大增强了开发分布式应用的能力,特别是下游服务处理能力不同的场景,使得编程模型变得更简单,使开发人员开发效率变得更高的同时,使推送和消费逻辑在不同的线程中,提高了系统的处理能力和IO吞吐,通过使用更少的线程处理更多的事务,提高了资源利用率,同时使代码的可读性变得更高,也利于后期的维护。
Smart Images

Figure CN115934059B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer systems, and more specifically, to a method, system, terminal device, and storage medium for constructing a reactive observer design pattern. Background Technology
[0002] The observer design pattern defines a one-to-many dependency relationship between objects, where when the state of one object changes, all objects that depend on it are notified and automatically updated.
[0003] Reactive programming is an asynchronous programming paradigm oriented towards data flow and change propagation. It can easily express static or dynamic data flow in programming languages, and the relevant computational model will automatically propagate the changed values through the data flow.
[0004] When using the observer design pattern, changes to the monitored data are pushed to the observers. However, observers have varying processing capabilities. A common solution is for the receiving end to adjust its resources to adapt to the observed data changes. Another approach is for the observed data to only notify the observer of the event, while the observer retrieves the actual data through other means. Therefore, this method is inefficient and hinders subsequent maintenance. Summary of the Invention
[0005] This invention provides a method, system, terminal device, and storage medium for constructing a reactive observer design pattern.
[0006] A method for constructing a reactive observer design pattern includes the following steps: declaration phase, subscription phase, subscription callback phase, request phase, and response phase.
[0007] The declaration phase is used not only to declare the request and response flow of the application itself, but also to declare the chained processing of requests and responses for remote method calls.
[0008] The subscription phase is when the caller establishes a subscription relationship with the downstream service, which facilitates callback processing after data flow occurs.
[0009] The subscription callback phase is a way to indicate the subscription action, letting each subscriber know and prepare to start listening for events;
[0010] During the request phase, once the final subscriber is ready to listen, it will call the request method to inform the producer of the data processing capabilities of the observer. Based on the reactive pattern, the request thread is released after the request is sent, and the response processing thread is awakened again when the producer pushes data.
[0011] The response phase will perform reactive data processing by calling the subscriber's onNext method.
[0012] Furthermore, the reactive observer pattern for interactive data processing includes the following steps:
[0013] Step S21: The subscriber program initiates a client subscription declaration using the reactive pattern. This declaration does not initiate any actual call execution.
[0014] Step S22: The observer stub performs chained processing and encapsulation declaration on the response data. The processing chain includes, but is not limited to, decryption, decompression, deserialization, and filtering. Each processing chain is based on a reactive approach. A reactive chain means that each link in the chain is triggered to execute the processing logic only when data flows through it. At this stage, no actual call execution is initiated; it is still the logic assembly stage.
[0015] Step S23, the subscription function callback phase, refers to the phase in which the subscriber's onSubscribe method is called sequentially. This phase informs each observer that the observation method has been triggered, and the observer is ready to process data reception.
[0016] Step S24: Send a request. After each observer is ready to process the data, it actually sends a subscription request and informs the producer of its own processing capacity, hoping that the producer will push data according to the subscriber's processing capacity.
[0017] Step S25: The request processing link receives the subscriber's request, adds it to the observer list, records the observer's processing capability, and waits for the event to occur.
[0018] Step S26: After the event occurs, the data is pushed out in batches according to the observer's processing capacity.
[0019] Step S27: Determine whether the data for this event has been successfully pushed. If not, repeat step 26.
[0020] Step S28: After receiving the returned result data, the observer begins response chain processing.
[0021] Step S29: The reactive return chain is completed, the final result is returned, and the monitoring of the observed events continues.
[0022] Furthermore: A system for constructing a reactive observer design pattern, comprising a declaration module, a subscription module, a request module, and a response module;
[0023] The declaration module is used not only to handle the application's own request and response flow declarations, but also to handle the chained processing declarations of remote method call requests and responses.
[0024] The subscription module is used to connect the caller with the downstream service provider, and to handle callbacks for the data stream.
[0025] The request module calls the request method to inform the producer of the data processing capabilities of the observer;
[0026] The response module is used to call methods of the subscription module to perform reactive data processing.
[0027] Furthermore, the terminal device may include a processor, a storage medium, and a bus. The storage medium stores machine-readable instructions that can be executed by the processor. When the terminal device is running, the processor communicates with the storage medium via the bus, and the processor executes the machine-readable instructions to perform the steps of the deep learning model training method as described in the foregoing embodiments.
[0028] Further: a storage medium storing a computer program, which, when executed by a processor, performs the steps of the method described above.
[0029] The beneficial effects of this invention are as follows: In the distributed message middleware push mode, this invention, based on the reactive observer design model, can easily achieve asynchronous and non-blocking message listeners. The observed entities do not need to adjust the push strategy according to their different processing capabilities, which greatly enhances the ability to develop distributed applications, especially in scenarios where downstream services have different processing capabilities. This simplifies the programming model, increases developer efficiency, and improves system processing power and I / O throughput by placing push and consumption logic in different threads. Using fewer threads to handle more transactions improves resource utilization, enhances code readability, and facilitates later maintenance. Attached Figure Description
[0030] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as a limitation on the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0031] Figure 1 A flowchart illustrating the method of the present invention is shown;
[0032] Figure 2 A schematic diagram of the device of the present invention is shown;
[0033] Figure 3 A schematic diagram of the composition of the terminal device of the present invention is shown; Detailed Implementation
[0034] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the following will be combined with the present invention.
[0035] The accompanying drawings in the embodiments of the present invention provide a clear and complete description of the technical solutions in the embodiments of the present invention. It should be understood that the drawings in this invention are for illustrative and descriptive purposes only and are not intended to limit the scope of protection of the present invention. Furthermore, it should be understood that the schematic drawings are not drawn to scale. The flowcharts used in this invention illustrate operations implemented according to some embodiments of the present invention. It should be understood that the operations in the flowcharts may not be implemented in sequence, and steps without logical contextual relationships may be reversed in order.
[0036] Alternatively, they can be implemented simultaneously. Furthermore, those skilled in the art, guided by the content of this invention, can add one or more other operations to flowchart diagram 0, or remove one or more operations from the flowchart diagram.
[0037] Furthermore, the embodiments described herein are merely some, not all, of the embodiments of the present invention. The components of the embodiments of the present invention described and illustrated herein can generally be arranged and designed in various different configurations. Therefore, the following description of embodiments of the invention provided in the accompanying drawings...
[0038] The detailed description of the examples is not intended to limit the scope of the claimed invention, but merely to illustrate selected embodiments of the invention. Based on the embodiments of the invention, those skilled in the art will understand without making a creative inference.
[0039] All other embodiments obtained under the premise of labor are within the scope of protection of this invention.
[0040] It should be noted that the term "comprising" will be used in the embodiments of the present invention to indicate the presence of a feature subsequently declared, but does not preclude the addition of other features. It should also be noted that similar reference numerals...
[0041] The letters and in the following figures represent similar items; therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures. In the description of this invention,
[0042] It should also be noted that the terms "first," "second," and "third" are used only to distinguish descriptions and should not be interpreted as indicating or implying relative importance.
[0043] Figure 1 A flowchart illustrating the steps of the method of the present invention is shown.
[0044] This invention provides a method for constructing a reactive observer design pattern, the specific steps of which include a declaration phase, a subscription phase, a subscription callback phase, a request phase, and a response phase;
[0045] The declaration phase is used not only to declare the request and response flow of the application itself, but also to declare the chained processing of requests and responses for remote method calls.
[0046] The subscription phase is when the caller establishes a subscription relationship with the downstream service, which facilitates callback processing after data flow occurs.
[0047] The subscription callback phase is a way to indicate the subscription action, letting each subscriber know and prepare to start listening for events;
[0048] During the request phase, once the final subscriber is ready to listen, it will call the request method to inform the producer of the data processing capabilities of the observer. Based on the reactive pattern, the request thread is released after the request is sent, and the response processing thread is awakened again when the producer pushes data.
[0049] The response phase will perform reactive data processing by calling the subscriber's onNext method.
[0050] The reactive observer pattern's approach to data interaction processing includes the following steps:
[0051] Step S21: The subscriber program initiates a client subscription declaration using the reactive pattern. This declaration does not initiate any actual call execution.
[0052] Step S22: The observer stub performs chained processing and encapsulation declaration on the response data. The processing chain includes, but is not limited to, decryption, decompression, deserialization, and filtering. Each processing chain is based on a reactive approach. A reactive chain means that each link in the chain is triggered to execute the processing logic only when data flows through it. At this stage, no actual call execution is initiated; it is still the logic assembly stage.
[0053] Step S23, the subscription function callback phase, refers to the phase in which the subscriber's onSubscribe method is called sequentially. This phase informs each observer that the observation method has been triggered, and the observer is ready to process data reception.
[0054] Step S24: Send a request. After each observer is ready to process the data, it actually sends a subscription request and informs the producer of its own processing capacity, hoping that the producer will push data according to the subscriber's processing capacity.
[0055] Step S25: The request processing link receives the subscriber's request, adds it to the observer list, records the observer's processing capability, and waits for the event to occur.
[0056] Step S26: After the event occurs, the data is pushed out in batches according to the observer's processing capacity.
[0057] Step S27: Determine whether the data for this event has been successfully pushed. If not, repeat step 26.
[0058] Step S28: After receiving the returned result data, the observer begins response chain processing.
[0059] Step S29: The reactive return chain is completed, the final result is returned, and the monitoring of the observed events continues.
[0060] like Figure 2 As shown, the present invention provides a system for constructing a reactive observer design pattern, which includes a declaration module, a subscription module, a request module, and a response module;
[0061] The declaration module is used not only to handle the application's own request and response flow declarations, but also to handle the chained processing declarations of remote method call requests and responses.
[0062] The subscription module is used to connect the caller with the downstream service provider, and to handle callbacks for the data stream.
[0063] The request module calls the request method to inform the producer of the data processing capabilities of the observer;
[0064] The response module is used to call methods of the subscription module to perform reactive data processing.
[0065] like Figure 3 As shown, the terminal device 6 may include: a processor 601, a storage medium 602, and a bus 603. The storage medium 602 stores machine-readable instructions executable by the processor 601.
[0066] During runtime, processor 601 communicates with storage medium 602 via bus 603. Processor 6015 executes machine-readable instructions to train the deep learning model as described in the foregoing embodiments.
[0067] The steps for practicing the method are as follows. The specific implementation and technical effects are similar, so they will not be repeated here.
[0068] For ease of explanation, only one processor is described in the terminal device described above. However, it should be noted that in some embodiments, the terminal device of the present invention may also include multiple processors, therefore the present invention...
[0069] The steps described in the document, which are executed by one processor, can also be executed jointly by multiple processors or individually.
[0070] The above are merely specific embodiments of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A method for constructing a reactive observer design pattern, characterized in that, The specific steps include the declaration phase, the subscription phase, the subscription callback phase, the request phase, and the response phase; The declaration phase is used not only to declare the request and response flow of the application itself, but also to declare the chained processing of requests and responses for remote method calls. During the request phase, once the final subscriber is ready to listen, it will call the request method to inform the producer of the data processing capabilities of the observer. Based on the reactive pattern, the request thread is released after the request is sent, and the response processing thread is awakened again when the producer pushes data. The reactive observer pattern's approach to data interaction processing includes the following steps: Step S21: The subscriber program initiates a client subscription declaration using the reactive pattern. This declaration does not initiate any actual call execution. Step S22: The observer stub performs chained processing and encapsulation declaration on the response data. The chained processing includes decryption, decompression, deserialization, and filtering. The chained processing is reactive. Each link in the chained processing is executed by the data stream through the trigger thread. This step is the logic assembly stage and does not initiate actual call execution. Step S23, the subscription function callback phase refers to the phase in which the subscriber's onSubscribe method is called sequentially; Step S24: Send a request. After each observer is ready to process the data, it actually sends a subscription request and informs the producer to push data according to the subscriber's processing capacity. Step S25: The request processing link receives the subscriber's request, adds it to the observer list, records the observer's processing capacity, and waits for the event to occur. Step S26: After the event occurs, the data is pushed in batches according to the observer's processing capacity. Step S27: Determine whether the data for this event has been pushed completely. If not, repeat step 26. Step S28: After receiving the returned result data, the observer begins response chain processing; Step S29: The reactive return chain is completed, the final result is returned, and the monitoring of the observed events continues.
2. The method according to claim 1, characterized in that, The subscription phase is when the caller establishes a subscription relationship with the downstream service.
3. The method according to claim 1, characterized in that, The subscription callback phase is a way to indicate the subscription action, letting each subscriber know and prepare to start listening for events.
4. The method according to claim 1, characterized in that, The response phase will perform reactive data processing by calling the subscriber's onNext method.
5. A system for constructing a reactive observer design pattern, characterized in that, The method is used to implement the method as described in any one of claims 1 to 4, and includes a declaration module, a subscription module, a request module, and a response module; The declaration module is used not only to handle the application's own request and response flow declarations, but also to handle the chained processing declarations of remote method call requests and responses. The subscription module is used to connect the caller with the downstream service provider, and to handle callbacks for the data stream. The request module calls the request method to inform the producer of the data processing capabilities of the observer; The response module is used to call methods of the subscription module to perform reactive data processing.
6. A terminal device, characterized in that, include: The device includes a processor, a storage medium, and a bus, wherein the storage medium stores machine-readable instructions executable by the processor, and when the terminal device is running, the processor communicates with the storage medium via the bus, and the processor executes the machine-readable instructions to perform the steps of the method as described in any one of claims 1 to 4.
7. A storage medium, characterized in that, The storage medium stores a computer program, which, when executed by a processor, performs the steps of the method as described in any one of claims 1 to 4.