Message distribution system and method based on publishing and subscribing mechanism

By adopting a publish-subscribe mechanism in the React framework, the message distribution system solves the bloated problem of data processing and conditional events in component-based development, achieves performance optimization and maintainability improvement, and ensures the synchronization and operation results of UI rendering. consistency.

CN118784635APending Publication Date: 2024-10-15安徽福晴医疗装备有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411119257.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-15
Publication Date
2024-10-15

AI Technical Summary

Technical Problem

As the complexity of component-based development increases, data processing and conditional event triggering in the React framework become bloated and difficult to maintain, resulting in unnecessary performance consumption and UI rendering out of synchronization.

Method used

Adopt a message distribution system based on the publish and subscribe mechanism, receive and store server data through the data status management module, determine the subscription mode according to the data type, subscribe when the component is mounted, cancel the subscription when uninstalling, and disperse the WebSocket message notification listening event logic , Reduce the execution of unnecessary code.

Benefits of technology

It effectively reduces performance waste, improves the maintainability and error troubleshooting capabilities of components, ensures the consistency of operation results for notification UI components of the same type, and avoids the trouble of data transfer.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118784635A_ABST
    Figure CN118784635A_ABST
Patent Text Reader

Abstract

The invention discloses a message distribution system and method based on a publishing and subscribing mechanism, and the system comprises a data state management module which is used for receiving and storing a plurality of groups of to-be-distributed data sent by a server, carrying out the path analysis of the plurality of groups of to-be-distributed data one by one, and carrying out the one-to-one corresponding bidirectional binding of the plurality of groups of to-be-distributed data and corresponding business components; the plurality of service components are used for receiving corresponding to-be-distributed data and determining a subscription mode according to the type of the to-be-distributed data, when the type of the to-be-distributed data is specifically a non-notification type, a component mounting subscription signal is generated, and the type of the to-be-distributed data comprises the non-notification type and the notification type; and the plurality of service components are also used for feeding back component states to the WebSocket communication and event subscription module in real time. According to the message distribution system and method based on the publishing and subscribing mechanism, the performance waste of running unnecessary codes is reduced, and the maintainability of the module is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a message distribution system and method based on a publish-subscribe mechanism. Background Art

[0002] With the rapid development of Web technology, various frameworks are emerging one after another. Among them, React is a relatively mature framework with a large user group. It realizes component-based development of the Web, improves development efficiency and reduces maintenance costs. React is a framework that drives views with data. It can be divided into three modules: data, UI components, and events. Users trigger operation events through UI components, event operations change data, and data changes re-render the UI. Message notifications often use WebSocket communication technology to trigger event conditions through data to change views, but with the increase in the complexity of component-based development, data processing and conditional event triggering will become bloated and difficult to maintain. At the same time, when the component is uninstalled, the data processing logic and conditional events will still be executed, which will lead to unnecessary performance consumption, page jams and difficulty in operation, UI rendering asynchrony and other unpredictable problems. Summary of the invention

[0003] In order to solve the technical problems existing in the background technology, the present invention proposes a message distribution system and method based on a publish-subscribe mechanism.

[0004] The present invention proposes a message distribution system based on a publish-subscribe mechanism, comprising:

[0005] The data status management module is used to receive and store multiple groups of data to be distributed sent by the storage client, and after performing path resolution on the multiple groups of data to be distributed one by one, the multiple groups of data to be distributed are bidirectionally bound to the corresponding business components one by one;

[0006] A plurality of business components are used to receive corresponding data to be distributed, and determine a subscription mode according to the type of the data to be distributed, and generate a component mounting subscription signal when the type of the data to be distributed is specifically a non-notification type, and the type of the data to be distributed includes a non-notification type and a notification type;

[0007] Multiple business components are also used to feed back component status to the WebSocket communication and event subscription module in real time;

[0008] The WebSocket communication and event subscription module is used to receive component mounting subscription signals and component status corresponding to business components, and perform subscription operations based on component mounting subscription signals, component status corresponding to business components and preset subscription strategies.

[0009] Preferably, the types of the business components include notification type business components and non-notification type business components; and the step of bidirectionally binding the multiple groups of data to be distributed with the corresponding business components in a one-to-one correspondence specifically includes:

[0010] When the type of the data to be distributed is a notification type, the corresponding data to be distributed is bidirectionally bound to the notification type business component one by one;

[0011] When the type of the data to be distributed is a non-notification type, the corresponding data to be distributed is bidirectionally bound to the non-notification type business component one by one.

[0012] Preferably, the subscription mode includes continuous subscription and usage subscription; the subscription mode is determined according to the type of data to be distributed, specifically including:

[0013] When the type of data to be distributed is specifically a non-notification type, the subscription mode specifically uses subscription. The business component generates a component mounting subscription signal to introduce the WebSocket communication and event subscription module. When the component is mounted, the WebSocket communication and event subscription module subscribes to events through React's useEffect method.

[0014] Preferably, the data status management module is also used to query the notification operation mode corresponding to the data to be distributed from the configuration table according to the type of data to be distributed, and transmit the notification operation mode to the corresponding business component; the configuration table is pre-configured with a one-to-one mapping relationship between the type of data to be distributed and the notification operation mode.

[0015] Preferably, the component status includes normal use and uninstallation; the preset subscription strategy specifically includes:

[0016] When a component mount subscription signal is received and the component status corresponding to the business component is normal use, when the business component is mounted, the subscription event is performed through the useEffect method of React;

[0017] When the component status corresponding to the business component is specifically uninstalled, the WebSocket communication and event subscription module cancels the event subscription through the return value of useEffect.

[0018] Preferably, it also includes: a notification UI component module, which is used to match subscription events for the data to be distributed after subscription analysis, and call the subscription event to generate a corresponding ReactNode node. After obtaining the ReactNode node, the ReactNode node is placed in the corresponding position of the React framework, and rendered to the page through the React framework.

[0019] The present invention proposes a message distribution method based on a publish-subscribe mechanism, comprising the following steps:

[0020] Receive and store multiple groups of data to be distributed sent by the storage client, and after performing path resolution on the multiple groups of data to be distributed one by one, bind the multiple groups of data to be distributed with the corresponding business components in a one-to-one and bidirectional manner;

[0021] Receive corresponding data to be distributed, and determine a subscription mode according to the type of the data to be distributed, and generate a component mounting subscription signal when the type of the data to be distributed is specifically a non-notification type, and the type of the data to be distributed includes a non-notification type and a notification type;

[0022] Receive the component mount subscription signal and the component status corresponding to the business component, and perform the subscription operation according to the component mount subscription signal, the component status corresponding to the business component and the preset subscription strategy.

[0023] Preferably, it also includes matching subscription events for the data to be distributed after subscription analysis, calling the subscription event to generate a corresponding ReactNode node, placing the ReactNode node at a corresponding position of the React framework after obtaining the ReactNode node, and rendering it to the page through the React framework.

[0024] In the present invention, the proposed message distribution system and method based on the publish-subscribe mechanism disperses the business logic of the WebSocket message notification monitoring event in different business components, monitors and executes after the component is mounted, and cancels the monitoring after uninstallation, which greatly reduces the performance waste of running unnecessary code. According to the notification message type and data, the notified UI components are centrally classified by module and type, which is more conducive to error troubleshooting and subsequent addition, and improves the maintainability of the module; different types of message notification UI components are passed through the WebSocket monitoring event to return the executed method in the form of ReactNode for rendering, ensuring that the UI components of the same type of notification have the same operation results and avoiding the trouble of returning and transmitting data. BRIEF DESCRIPTION OF THE DRAWINGS

[0025] Figure 1 A schematic diagram of the system architecture of a message distribution system based on a publish-subscribe mechanism proposed by the present invention;

[0026] Figure 2 A schematic diagram of the module association structure of a message distribution system based on a publish-subscribe mechanism proposed by the present invention;

[0027] Figure 3 The present invention provides a structural diagram of the workflow of a message distribution method based on a publish-subscribe mechanism. DETAILED DESCRIPTION

[0028] Reference Figure 1-3The present invention proposes a message distribution system based on a publish-subscribe mechanism, comprising:

[0029] The data status management module is used to receive and store multiple groups of data to be distributed sent by the service client, and after performing path resolution on the multiple groups of data to be distributed one by one, the multiple groups of data to be distributed are bidirectionally bound to the corresponding business components one by one.

[0030] In this embodiment, the types of business components include notification type business components and non-notification type business components; multiple groups of data to be distributed are bidirectionally bound to corresponding business components one by one, specifically including:

[0031] When the type of the data to be distributed is a notification type, the corresponding data to be distributed is bidirectionally bound to the notification type business component one by one;

[0032] When the type of the data to be distributed is a non-notification type, the corresponding data to be distributed is bidirectionally bound to the non-notification type business component one by one.

[0033] In this embodiment, the data status management module is also used to query the notification operation mode corresponding to the data to be distributed from the configuration table according to the type of data to be distributed, and transmit the notification operation mode to the corresponding business component; the configuration table is pre-configured with a one-to-one mapping relationship between the type of data to be distributed and the notification operation mode.

[0034] In this embodiment, the state manager based on React API encapsulation stores the data on the server side and uses the hook function of React to implement two-way data binding, and provides operation methods for notifications, such as click events, data consumption and method calls in the notification UI component.

[0035] Multiple business components are used to receive corresponding data to be distributed and determine the subscription mode according to the type of data to be distributed. When the type of data to be distributed is specifically a non-notification type, a component mounting subscription signal is generated. The types of data to be distributed include non-notification type and notification type.

[0036] In this embodiment, the subscription mode includes continuous subscription and usage subscription. The subscription mode is determined according to the type of data to be distributed, specifically including:

[0037] When the type of data to be distributed is specifically a non-notification type, the subscription mode specifically uses subscription. The business component generates a component mounting subscription signal to introduce the WebSocket communication and event subscription module. When the component is mounted, the WebSocket communication and event subscription module subscribes to events through React's useEffect method.

[0038] Multiple business components are also used to feed back component status to the WebSocket communication and event subscription module in real time;

[0039] The WebSocket communication and event subscription module is used to receive component mounting subscription signals and component status corresponding to business components, and perform subscription operations based on component mounting subscription signals, component status corresponding to business components and preset subscription strategies.

[0040] In this embodiment, the component status includes normal use and uninstallation; the preset subscription strategy specifically includes:

[0041] When a component mount subscription signal is received and the component status corresponding to the business component is normal use, when the business component is mounted, the subscription event is performed through the useEffect method of React;

[0042] When the component status corresponding to the business component is specifically uninstalled, the WebSocket communication and event subscription module cancels the event subscription through the return value of useEffect.

[0043] In this embodiment, the WebSocket communication and event subscription module uses WebSocket to communicate with the server and combines the publish-subscribe mode to expand the different monitoring methods of monitoring and executing communication data. The Websocket communication connection is made when the page is initialized; it is introduced and used in the component, and event monitoring is performed when the component is mounted, and the monitoring is canceled when it is uninstalled.

[0044] In this embodiment, it also includes: a notification UI component module, which is used to match subscription events for the data to be distributed after subscription analysis, and call the subscription event to generate a corresponding ReactNode node. After obtaining the ReactNode node, the ReactNode node is placed in the corresponding position of the React framework, and rendered to the page through the React framework.

[0045] In this embodiment, the notification UI component module also provides methods for generating all types of message notification UI components and binding different operation methods. It is divided into different modules according to the types of Websocket notifications and data. It calls and generates ReactNode node objects through subscription events, renders and presents them, and can be operated.

[0046] In this embodiment, the data state management module is responsible for the management of data and state, and uses React's hook function to implement two-way binding of data and provide common operation methods. The WebSocket communication and event subscription module establishes communication with the server during initialization, and listens to received messages through the event subscription mechanism; when a new message is received, different subscription functions are executed according to different message data to generate different types of message notifications. The UI component module generates a ReactNode node bound to an operation method based on different message data. After obtaining the ReactNode node of the message notification, it can be rendered at different locations on the page to ensure that the operation results of the same type of notification components are consistent, avoiding the problem of repeated use of components and repeated parameter transmission. When the business component is used, the Websocket communication and event subscription module is introduced to listen to the message data when the component is mounted. When the component is uninstalled, the hook callback function is used to cancel the listening, which reasonably avoids the performance consumption caused by the execution of unnecessary listening functions.

[0047] In this embodiment, the business logic of WebSocket message notification monitoring events is dispersed in different components based on the publish-subscribe mode. The monitoring is performed after the component is mounted, and the monitoring is canceled after the component is uninstalled, which greatly reduces the performance waste of running unnecessary code. The notified UI components are centrally classified by module and type according to the notification message type and data, which is more conducive to error troubleshooting and subsequent additions, and improves the maintainability of the module; different types of message notification UI components are passed through the WebSocket monitoring event to execute the method in the form of parameters and returned to the ReactNode method for rendering, ensuring that the UI components of the same type of notification have the same operation results and avoiding the trouble of returning and transmitting data.

[0048] Reference Figure 1-3 The present invention proposes a message distribution method based on a publish-subscribe mechanism, comprising the following steps:

[0049] Receive and store multiple groups of data to be distributed sent by the storage client, and after performing path resolution on the multiple groups of data to be distributed one by one, bind the multiple groups of data to be distributed with the corresponding business components in a one-to-one and bidirectional manner;

[0050] Receive the corresponding data to be distributed, and determine the subscription mode according to the type of the data to be distributed. When the type of the data to be distributed is specifically a non-notification type, generate a component mounting subscription signal. The types of the data to be distributed include a non-notification type and a notification type.

[0051] Receive the component mount subscription signal and the component status corresponding to the business component, and perform the subscription operation according to the component mount subscription signal, the component status corresponding to the business component and the preset subscription strategy.

[0052] In this embodiment, it also includes matching subscription events for the data to be distributed after subscription analysis is performed on the data to be distributed, and calling the subscription event to generate a corresponding ReactNode node. After the ReactNode node is obtained, the ReactNode node is placed at a corresponding position of the React framework, and rendered to the page through the React framework.

[0053] The above description is only a preferred specific implementation manner of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can make equivalent replacements or changes according to the technical scheme and inventive concept of the present invention within the technical scope disclosed by the present invention, which should be covered by the protection scope of the present invention.

Claims

1. A message distribution system based on publish-subscribe mechanism, characterized in that: include: The data status management module is used to receive and store multiple groups of data to be distributed sent by the storage client, and after performing path resolution on the multiple groups of data to be distributed one by one, the multiple groups of data to be distributed are bidirectionally bound to the corresponding business components one by one; A plurality of business components are used to receive corresponding data to be distributed, and determine a subscription mode according to the type of the data to be distributed, and generate a component mounting subscription signal when the type of the data to be distributed is specifically a non-notification type, and the type of the data to be distributed includes a non-notification type and a notification type; Multiple business components are also used to feed back component status to the WebSocket communication and event subscription module in real time; The WebSocket communication and event subscription module is used to receive component mounting subscription signals and component status corresponding to business components, and perform subscription operations based on component mounting subscription signals, component status corresponding to business components and preset subscription strategies.

2. The message distribution system based on publish-subscribe mechanism according to claim 1 is characterized in that: The types of the business components include notification type business components and non-notification type business components; and the one-to-one bidirectional binding of the multiple groups of data to be distributed with the corresponding business components specifically includes: When the type of the data to be distributed is a notification type, the corresponding data to be distributed is bidirectionally bound to the notification type business component one by one; When the type of the data to be distributed is a non-notification type, the corresponding data to be distributed is bidirectionally bound to the non-notification type business component one by one.

3. The message distribution system based on publish-subscribe mechanism according to claim 1 is characterized in that: The subscription modes include continuous subscription and usage subscription; Determining the subscription mode according to the type of data to be distributed specifically includes: When the type of data to be distributed is specifically a non-notification type, the subscription mode specifically uses subscription. The business component generates a component mounting subscription signal to introduce the WebSocket communication and event subscription module. When the component is mounted, the WebSocket communication and event subscription module subscribes to events through React's useEffect method.

4. The message distribution system based on publish-subscribe mechanism according to claim 1, characterized in that: The data status management module is also used to query the notification operation mode corresponding to the data to be distributed from the configuration table according to the type of data to be distributed, and transmit the notification operation mode to the corresponding business component; the configuration table is pre-configured with a one-to-one mapping relationship between the type of data to be distributed and the notification operation mode.

5. The message distribution system based on publish-subscribe mechanism according to claim 1 is characterized in that: The component status includes normal use and uninstallation; the preset subscription strategy specifically includes: When a component mount subscription signal is received and the component status corresponding to the business component is normal use, when the business component is mounted, the subscription event is performed through the useEffect method of React; When the component status corresponding to the business component is specifically uninstalled, the WebSocket communication and event subscription module cancels the event subscription through the return value of useEffect.

6. The message distribution system based on publish-subscribe mechanism according to claim 1 is characterized in that: Also includes: The notification UI component module is used to match the subscription event for the data to be distributed after subscription analysis, and call the subscription event to generate the corresponding ReactNode node. After obtaining the ReactNode node, the ReactNode node is placed in the corresponding position of the React framework and rendered to the page through the React framework.

7. A message distribution method based on publish-subscribe mechanism, characterized in that: The following steps are involved: Receive and store multiple groups of data to be distributed sent by the storage client, and after performing path resolution on the multiple groups of data to be distributed one by one, bind the multiple groups of data to be distributed with the corresponding business components in a one-to-one and bidirectional manner; Receive corresponding data to be distributed, and determine a subscription mode according to the type of the data to be distributed, and generate a component mounting subscription signal when the type of the data to be distributed is specifically a non-notification type, and the type of the data to be distributed includes a non-notification type and a notification type; Receive the component mount subscription signal and the component status corresponding to the business component, and perform the subscription operation according to the component mount subscription signal, the component status corresponding to the business component and the preset subscription strategy.

8. The message distribution method based on publish-subscribe mechanism according to claim 7 is characterized in that: It also includes matching subscription events for the data to be distributed after subscription analysis, calling the subscription event to generate a corresponding ReactNode node, placing the ReactNode node at a corresponding position of the React framework after obtaining the ReactNode node, and rendering it to the page through the React framework.