[go: up one dir, main page]

CN118394548B - A micro-frontend cross-application information sharing method and micro-frontend architecture system - Google Patents

A micro-frontend cross-application information sharing method and micro-frontend architecture system Download PDF

Info

Publication number
CN118394548B
CN118394548B CN202410851557.XA CN202410851557A CN118394548B CN 118394548 B CN118394548 B CN 118394548B CN 202410851557 A CN202410851557 A CN 202410851557A CN 118394548 B CN118394548 B CN 118394548B
Authority
CN
China
Prior art keywords
target value
sub
application
observer
pool
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202410851557.XA
Other languages
Chinese (zh)
Other versions
CN118394548A (en
Inventor
范霄
朱龙
唐力
赵建华
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Hundsun Technologies Inc
Original Assignee
Hundsun Technologies Inc
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Hundsun Technologies Inc filed Critical Hundsun Technologies Inc
Priority to CN202410851557.XA priority Critical patent/CN118394548B/en
Publication of CN118394548A publication Critical patent/CN118394548A/en
Application granted granted Critical
Publication of CN118394548B publication Critical patent/CN118394548B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/541Interprogram communication via adapters, e.g. between incompatible applications
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/545Interprogram communication where tasks reside in different layers, e.g. user- and kernel-space

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The application provides a micro-front-end cross-application information sharing method and a micro-front-end architecture, which are related to monitoring registration through a decoupling base module. The communication of subsequent data is triggered by determining whether the observer pool is zero. And when the target value changes, the change value is only transmitted to the corresponding sub-application and the base module in the target value issuing relation pool by utilizing the target value issuing relation pool. And a more flexible data communication mode is provided while the efficiency of data transmission is ensured.

Description

一种微前端跨应用信息共享方法与微前端架构系统A micro-frontend cross-application information sharing method and micro-frontend architecture system

技术领域Technical Field

本申请涉及微前端技术,具体而言,涉及一种微前端跨应用信息共享方法与微前端架构系统。The present application relates to micro-frontend technology, and more specifically, to a micro-frontend cross-application information sharing method and a micro-frontend architecture system.

背景技术Background Art

随着网站、web app功能复杂度越来越高,微服务作为被广泛应用于服务端的技术范式,已被广泛地扩展到前端领域,即微前端。在微前端的实现方式中,微应用容器化方案往往采用专门的微前端框架,例如,single-spa、qiankun等,来进行多个微应用的生命周期管理与调度。As websites and web apps become more and more complex, microservices, as a technical paradigm widely used on the server side, have been widely extended to the front-end field, namely micro-frontends. In the implementation of micro-frontends, micro-application containerization solutions often use specialized micro-frontend frameworks, such as single-spa, qiankun, etc., to manage and schedule the lifecycle of multiple micro-applications.

而在一些复杂的应用场景下,例如存在主子应用、跨子应用的场景时,往往需要保证不同子应用之间数据状态的快速、准确地传递及下发。In some complex application scenarios, such as scenarios with main-sub-applications or cross-sub-applications, it is often necessary to ensure the fast and accurate transmission and distribution of data status between different sub-applications.

在现有技术中,往往需要利用微前端自带的监听机制来实现。对于上述场景,子应用通常内嵌在基座应用中,而在具体的数据状态的传递流程中,子应用之间的信息传递,都需要基于基座应用的情况与需求而定。即对于主子应用、跨子应用等场景,信息的传递与基座应用具有较强的耦合关系,从而导致其处理流程效率较低。In the existing technology, it is often necessary to use the monitoring mechanism of the micro front-end to achieve this. For the above scenarios, sub-applications are usually embedded in the base application, and in the specific data status transmission process, the information transmission between sub-applications needs to be based on the situation and needs of the base application. That is, for scenarios such as master-sub-application and cross-sub-application, the transmission of information has a strong coupling relationship with the base application, resulting in low efficiency of its processing process.

发明内容Summary of the invention

本申请的目的在于提供一种微前端跨应用信息共享方法与微前端架构系统,其用于提高跨应用场景的数据通信效率。The purpose of this application is to provide a micro-frontend cross-application information sharing method and a micro-frontend architecture system, which are used to improve the efficiency of data communication across application scenarios.

为了实现上述目的,本申请实施例采用的技术方案如下:In order to achieve the above purpose, the technical solution adopted in the embodiment of the present application is as follows:

第一方面,本申请实施例提供一种微前端跨应用信息共享方法,所述方法应用于微前端架构系统,所述微前端架构系统包括:数据中心、基座模块与多个子应用,所述方法包括:In a first aspect, an embodiment of the present application provides a micro-frontend cross-application information sharing method, the method is applied to a micro-frontend architecture system, the micro-frontend architecture system includes: a data center, a base module and multiple sub-applications, the method includes:

数据中心中的事件中心确认观察者池中是否存在观察者;所述观察者为由所述基座模块或任意一个所述子应用注册生成的;The event center in the data center confirms whether there is an observer in the observer pool; the observer is registered and generated by the base module or any one of the sub-applications;

若存在所述观察者,则通过全局监听事件对目标值进行监听;If the observer exists, the target value is monitored through the global monitoring event;

若所述目标值发生变化,则根据目标值下发关系池向对应的目标子应用或基座模块发送所述目标值的变化值。If the target value changes, the target value change value is sent to the corresponding target sub-application or base module according to the target value sending relationship pool.

可选地,在所述数据中心中的事件中心确认观察者池中是否存在观察者的步骤之前,还包括:Optionally, before the step of the event center in the data center confirming whether there is an observer in the observer pool, the step further includes:

所述事件中心接收基座模块或任意一个子应用发送的绑定请求;The event center receives a binding request sent by the base module or any sub-application;

所述事件中心根据所述绑定请求为对应的基座模块或任意一个子应用在所述观察者池中建立对应的观察者;The event center establishes a corresponding observer in the observer pool for the corresponding base module or any sub-application according to the binding request;

所述事件中心判断所述全局监听事件是否已建立;The event center determines whether the global monitoring event has been established;

若否,则所述事件中心建立所述全局监听事件。If not, the event center establishes the global listening event.

可选地,所述针对目标值进行事件监听的步骤,包括:Optionally, the step of monitoring events for the target value includes:

所述事件中心接收已注册子应用的更新数据状态消息;所述更新数据状态消息包含所述目标值与指定标识信息;所述指定标识信息为当所述目标值发生变化时,可获得所述变化值的子应用或基座模块的标识信息;The event center receives an update data status message of a registered sub-application; the update data status message includes the target value and specified identification information; the specified identification information is the identification information of the sub-application or base module that can obtain the changed value when the target value changes;

所述事件中心将所述目标值在全局状态池中进行维护;The event center maintains the target value in a global state pool;

所述事件中心通过过滤器维护所述目标值对应的指定标识信息,以建立所述目标值下发关系池;The event center maintains the designated identification information corresponding to the target value through a filter to establish a target value delivery relationship pool;

所述数据中心对所述全局状态池中的所述目标值进行事件监听。The data center monitors events of the target value in the global state pool.

可选地,所述若所述目标值发生变化,则根据目标值下发关系池向对应的目标子应用发送所述目标值的变化值的步骤,包括:Optionally, if the target value changes, the step of sending the change value of the target value to the corresponding target sub-application according to the target value distribution relationship pool includes:

所述事件中心监听到所述目标值发生变化时,获得所述目标值的变化值;When the event center monitors a change in the target value, it obtains a change value of the target value;

所述事件中心通过所述过滤器维护的所述目标值下发关系池,确认所述变化值对应的指定标识信息;The event center sends the target value to the relationship pool maintained by the filter to confirm the specified identification information corresponding to the change value;

所述事件中心将所述变化值发送至所述指定标识信息对应的子应用和/或所述基座模块。The event center sends the change value to the sub-application and/or the base module corresponding to the designated identification information.

可选地,还包括:Optionally, it also includes:

所述数据中心接收任一子应用或所述基座模块发送的数据获取消息;所述数据获取消息包含所述目标值的获取指示;The data center receives a data acquisition message sent by any sub-application or the base module; the data acquisition message includes an acquisition instruction of the target value;

所述数据中心向所述子应用所述基座模块发送的所述目标值。The data center sends the target value to the sub-application base module.

可选地,还包括:Optionally, it also includes:

当所述全局监听事件被销毁时,所述事件中心删除对应的全部观察者;When the global monitoring event is destroyed, the event center deletes all corresponding observers;

当任一子应用销毁时,所述事件中心删除所述观察者池中对应的观察者。When any sub-application is destroyed, the event center deletes the corresponding observer in the observer pool.

第二方面,本申请实施例提供一种微前端架构系统,所述微前端架构系统包括:数据中心、基座模块与多个子应用;In a second aspect, an embodiment of the present application provides a micro front-end architecture system, the micro front-end architecture system comprising: a data center, a base module and a plurality of sub-applications;

所述数据中心中的事件中心,用于确认观察者池中是否存在观察者;所述观察者为由所述基座模块或任意一个所述子应用注册生成的;若存在所述观察者,则通过全局监听事件对目标值进行监听;若所述目标值发生变化,则根据目标值下发关系池向对应的目标子应用或基座模块发送所述目标值的变化值。The event center in the data center is used to confirm whether there is an observer in the observer pool; the observer is registered and generated by the base module or any one of the sub-applications; if the observer exists, the target value is monitored through the global monitoring event; if the target value changes, the change value of the target value is sent to the corresponding target sub-application or base module through the relationship pool according to the target value.

第三方面,本申请实施例提供一种电子设备,包括:In a third aspect, an embodiment of the present application provides an electronic device, including:

存储器,用于存储一个或多个程序;A memory for storing one or more programs;

处理器;processor;

当所述一个或多个程序被所述处理器执行时,实现如上述第一个方面中任一项所述的方法。When the one or more programs are executed by the processor, the method as described in any one of the first aspects above is implemented.

第四方面,本申请实施例提供一种计算机可读存储介质,其上存储有计算机程序,该计算机程序被处理器执行时实现如上述第一个方面中任一项所述的方法。In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements a method as described in any one of the above-mentioned first aspects.

第五方面,本申请实施例提供一种程序产品,所述程序产品被处理器执行时,实现如上述第一个方面中任一项所述的方法。In a fifth aspect, an embodiment of the present application provides a program product, which, when executed by a processor, implements a method as described in any one of the above-mentioned first aspects.

相对于现有技术,本申请实施例所提供的一种微前端跨应用信息共享方法与微前端架构系统,不对基座模块是否发起监听的注册进行约束。仅仅通过判断观察者池是否为零,来触发后续数据的通信。进而由于利用了目标值下发关系池,可以使得目标值变化时,变化值仅向对应的子应用、基座模块进行传输。在保证数据传输的效率的同时,提供了更加灵活的数据通信方式。Compared with the prior art, the micro-frontend cross-application information sharing method and micro-frontend architecture system provided by the embodiment of the present application do not restrict whether the base module initiates the monitoring registration. The communication of subsequent data is triggered only by judging whether the observer pool is zero. Furthermore, due to the use of the target value distribution relationship pool, when the target value changes, the changed value is only transmitted to the corresponding sub-application and base module. While ensuring the efficiency of data transmission, a more flexible data communication method is provided.

为使本申请的上述目的、特征和优点能更明显易懂,下文特举较佳实施例,并配合所附附图,作详细说明如下。In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, preferred embodiments are specifically cited below and described in detail with reference to the attached drawings.

附图说明BRIEF DESCRIPTION OF THE DRAWINGS

为了更清楚地说明本申请实施例的技术方案,下面将对实施例中所需要使用的附图作简单地介绍,应当理解,以下附图仅示出了本申请的某些实施例,因此不应被看作是对范围的限定,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其它相关的附图。In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.

图1为一种跨子应用数据交互的场景示意图;FIG1 is a schematic diagram of a scenario of cross-sub-application data interaction;

图2为另一种跨子应用数据交互的场景示意图;FIG2 is a schematic diagram of another scenario of cross-sub-application data interaction;

图3为一种微应用架构示意图;FIG3 is a schematic diagram of a micro-application architecture;

图4为本发明实施例提供的一种微前端架构系统示意图;FIG4 is a schematic diagram of a micro-frontend architecture system provided by an embodiment of the present invention;

图5为本发明实施例提供的一种微前端跨应用信息共享方法的流程示意图;FIG5 is a schematic diagram of a flow chart of a micro-frontend cross-application information sharing method provided by an embodiment of the present invention;

图6为本发明实施例提供的另一种微前端跨应用信息共享方法的流程示意图;FIG6 is a schematic diagram of a flow chart of another micro-frontend cross-application information sharing method provided by an embodiment of the present invention;

图7为本发明实施例提供的另一种微前端架构系统示意图;FIG7 is a schematic diagram of another micro-frontend architecture system provided by an embodiment of the present invention;

图8为本发明实施例提供的另一种微前端跨应用信息共享方法的流程示意图;FIG8 is a schematic diagram of a flow chart of another micro-frontend cross-application information sharing method provided by an embodiment of the present invention;

图9为本发明实施例提供的另一种微前端架构系统示意图;FIG9 is a schematic diagram of another micro-frontend architecture system provided by an embodiment of the present invention;

图10为本发明实施例提供的一种电子设备的结构示意图。FIG. 10 is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention.

具体实施方式DETAILED DESCRIPTION

为使本申请实施例的目的、技术方案和优点更加清楚,下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本申请一部分实施例,而不是全部的实施例。通常在此处附图中描述和示出的本申请实施例的组件可以以各种不同的配置来布置和设计。In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all the embodiments. The components of the embodiments of the present application described and shown in the drawings here can be arranged and designed in various different configurations.

因此,以下对在附图中提供的本申请的实施例的详细描述并非旨在限制要求保护的本申请的范围,而是仅仅表示本申请的选定实施例。基于本申请中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。Therefore, the following detailed description of the embodiments of the present application provided in the accompanying drawings is not intended to limit the scope of the present application for which protection is sought, but merely represents selected embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without creative work are within the scope of protection of the present application.

应注意到:相似的标号和字母在下面的附图中表示类似项,因此,一旦某一项在一个附图中被定义,则在随后的附图中不需要对其进行进一步定义和解释。同时,在本申请的描述中,术语“第一”、“第二”等仅用于区分描述,而不能理解为指示或暗示相对重要性。It should be noted that similar reference numerals and letters represent similar items in the following drawings, so once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings. At the same time, in the description of this application, the terms "first", "second", etc. are only used to distinguish the description and cannot be understood as indicating or implying relative importance.

需要说明的是,在本文中,诸如第一和第二等之类的关系术语仅仅用来将一个实体或者操作与另一个实体或操作区分开来,而不一定要求或者暗示这些实体或操作之间存在任何这种实际的关系或者顺序。而且,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的过程、方法、物品或者设备中还存在另外的相同要素。It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.

图1为一种跨子应用数据交互的场景示意图,参见图1,其中,子应用-1内嵌在基座应用中。当该子应用-1的数据状态发生变化时,需要触发子应用-2的某个具体页面的信息变化。Figure 1 is a schematic diagram of a scenario of cross-sub-application data interaction, referring to Figure 1, where sub-application-1 is embedded in the base application. When the data state of sub-application-1 changes, it is necessary to trigger the information change of a specific page of sub-application-2.

在另一个可能的场景中,图2为另一种跨子应用数据交互的场景示意图,参见图2,其中,子应用-3的页面嵌套了子应用-4。当子应用-4的数据状态变化时,则触发子应用-3的变化。进而子应用-4根据子应用-3的变化以及自身的变化,快速地显隐子应用-4中的区块C。In another possible scenario, FIG2 is a schematic diagram of another scenario of cross-sub-application data interaction. Referring to FIG2, the page of sub-application-3 nests sub-application-4. When the data state of sub-application-4 changes, the change of sub-application-3 is triggered. Then, sub-application-4 quickly displays and hides block C in sub-application-4 according to the change of sub-application-3 and its own change.

显然,参见上文两个示例,对于微前端涉及多个子应用的场景,存在数据在不同子应用之间进行跨应用通信的需求。下面以微应用容器化方案中较为主流的qiankun架构作为示例,对当前跨应用数据通信的方案进行说明。Obviously, referring to the two examples above, for scenarios where the micro-frontend involves multiple sub-applications, there is a need for cross-application data communication between different sub-applications. The following uses the more mainstream qiankun architecture in the micro-application containerization solution as an example to explain the current cross-application data communication solution.

具体的,图3为一种微应用架构示意图,参见图3,该架构包括:“Micro-Base”对应的基座模块、“Micro-APP”对应的子应用-1、“Micro-APP”对应的子应用-2、全局状态池以及事件中心。Specifically, Figure 3 is a schematic diagram of a micro-application architecture. Referring to Figure 3, the architecture includes a base module corresponding to "Micro-Base", a sub-application-1 corresponding to "Micro-APP", a sub-application-2 corresponding to "Micro-APP", a global state pool and an event center.

对于qiankun架构,其通常使用“initGlobalState”来定义全局状态。其方法执行后会反馈一个“MicroAppStateActions实例”,该实例包含三个部分:For the Qiankun architecture, it usually uses "initGlobalState" to define the global state. After the method is executed, it will feedback a "MicroAppStateActions instance", which contains three parts:

1、“onGlobalStateChange”:设置全局状态池(GlobalState)-设置新的目标值时,该架构内部将执行“浅检查”,如过检查到该全局状态池发生变化,则触发通知,通知到事件中心中的所有观察者函数,例如图3所示观察者S、观察者A、观察者B等。1. "onGlobalStateChange": Set the global state pool (GlobalState) - When setting a new target value, the architecture will perform a "shallow check" internally. If the global state pool is found to have changed, a notification will be triggered to all observer functions in the event center, such as observer S, observer A, observer B, etc. as shown in Figure 3.

2、“setGlobalState”:注册观察者函数-响应全局状态池的变化,在全局状态池发生变化时,触发该观察者函数。2. "setGlobalState": Register an observer function - respond to changes in the global state pool. When the global state pool changes, the observer function is triggered.

3、“offGlobalStateChange”:取消观察者函数-该实例不在响应全局状态池的变化。3. "offGlobalStateChange": cancel the observer function - the instance no longer responds to changes in the global state pool.

下面结合图3所示示例,对上述跨子应用的数据通信流程进行说明:The following is an example of FIG3 showing the cross-sub-application data communication process:

步骤1、基座模块注册并绑定监听函数“initGlobalState”;Step 1. The base module registers and binds the monitoring function "initGlobalState";

步骤2、基座模块设立观察者S,进而事件中心维护对应的观察者S;Step 2: The base module sets up observer S, and the event center maintains the corresponding observer S;

步骤3、子应用1、子应用2分别利用“onGlobalStateChange”绑定基座模块已建立的监听函数,并分别设置观察者A与观察者B;进而事件中心维护对应的观察者A与观察者B;Step 3, sub-application 1 and sub-application 2 use "onGlobalStateChange" to bind the monitoring function established by the base module, and set observer A and observer B respectively; then the event center maintains the corresponding observer A and observer B;

步骤4、当子应用或基座模块更新数据的更新指令时,发送“action”通过“setGlobalState”对全局状态池中的数据进行更新;Step 4: When the sub-application or base module issues an update instruction for data, send "action" to update the data in the global state pool through "setGlobalState";

步骤5、当全局状态池中变化后,各个子应用或基座模块,利用事件中心的观察者将更新数据返回给各自子应用或基座模块上。Step 5: When the global state pool changes, each sub-application or base module uses the observer of the event center to return the updated data to its own sub-application or base module.

其中,对于基座模块、子应用-1以及子应用-2,其分别利用“onGlobalStateChange”监测全局状态池中的数据变化,进而通过观察者S、观察者A与观察者B获得更新数据。Among them, for the base module, sub-application-1 and sub-application-2, they respectively use "onGlobalStateChange" to monitor the data changes in the global state pool, and then obtain updated data through observer S, observer A and observer B.

参见基于图3所示示例以及其对应的跨应用的数据通信方案,可以发现:Referring to the example shown in FIG3 and its corresponding cross-application data communication solution, it can be found that:

一、现有技术中,对于全局状态池的监听功能,必须首先基于基座模块发起注册监听函数的流程。对于内嵌在三方基座上的应用,子应用需要根据基座的要求做事件传递调整。因此,在现有技术中跨应用的数据通信与基座模块具有较强的耦合关系,导致数据通信不够灵活。1. In the prior art, for the monitoring function of the global state pool, the process of registering the monitoring function must first be initiated based on the base module. For applications embedded in the third-party base, the sub-application needs to make event delivery adjustments according to the requirements of the base. Therefore, in the prior art, cross-application data communication has a strong coupling relationship with the base module, resulting in insufficient flexibility in data communication.

二、当某一应用发出更新指令后,事件中心中所有观察者都会收到更新数据。然而在实际的应用场景中,更新数据对于某些应用来说,并没有作用和意义,从而造成数据通信的低效,占用了通信资源。Second, when an application issues an update command, all observers in the event center will receive the updated data. However, in actual application scenarios, the updated data has no effect or meaning for some applications, which results in inefficient data communication and occupies communication resources.

三、在现有技术的方案中,各个子应用或基座模块要获得更新后的数据,均需要通过监听等待,被动的获得更新数据。需要在onGlobalStateChange回调中针对GlobalState的回传值做相应的逻辑转换后,转储到对应子应用的vuex/redux上,再结合子应用内部的状态管理机制(vuex/redux)来做对应的显隐逻辑。3. In the existing technical solutions, each sub-application or base module needs to passively obtain updated data by listening and waiting. It is necessary to make corresponding logical conversions for the return value of GlobalState in the onGlobalStateChange callback, and then dump it to the vuex/redux of the corresponding sub-application, and then combine the state management mechanism (vuex/redux) inside the sub-application to perform the corresponding display and hiding logic.

为了解决上述技术方案中因基于全局状态池的监听仅能通过基座模块发起,进而造成灵活度较差的问题。In order to solve the problem in the above technical solution that the monitoring based on the global state pool can only be initiated through the base module, resulting in poor flexibility.

现有技术也提出了一种利用通信类来提高交互自由度的机制,其核心思想在于:利用不同的通信类,将原有一个全局状态池拆分为多个池,进而不同的应用可以订阅不同的通信类,来相对独立、自由的进行跨应用的数据通信。The existing technology also proposes a mechanism to improve the freedom of interaction by using communication classes. The core idea is to use different communication classes to split the original global state pool into multiple pools, so that different applications can subscribe to different communication classes to conduct cross-application data communication relatively independently and freely.

然而上述方式依然存在问题:However, the above method still has problems:

一、其通信机制是以构建不同的命名空间的通信类来实现全局状态池的拆分,本质上其属于事件驱动机制。当应用场景较为复杂时,事件命名一旦发生重复,则会导致不同应用中的事件出现干扰与错误。First, its communication mechanism is to build communication classes in different namespaces to split the global state pool. In essence, it is an event-driven mechanism. When the application scenario is more complex, once the event naming is repeated, it will cause interference and errors in events in different applications.

二、为了保证应用能被约束在同一通信类中,通常会利用“EventHub.emit”与“EventHub.on”进行事件监听的匹配,即某一应用发起一次“EventHub.emit”,则属于该通信类的其他每个应用均要对应发起匹配的“EventHub .on”,来保证更新数据的有效传输。然而这种方式意味着,每一次数据的更新,在一个通信类中对应着多次“EventHub.emit”的发起,通信效率较低。Second, in order to ensure that applications can be constrained in the same communication class, "EventHub.emit" and "EventHub.on" are usually used to match event monitoring, that is, when an application initiates an "EventHub.emit", each other application belonging to the communication class must initiate a matching "EventHub .on" to ensure the effective transmission of updated data. However, this method means that each data update corresponds to multiple "EventHub.emit" initiations in a communication class, and the communication efficiency is low.

三、每一个通信类都要分别对应不同的事件监听,事件的分发与订阅是异步的。对于复杂场景,多个事件的管理复杂度较高。多个通信类对应的是微应用架构下多个应用的复杂的依赖关系,进一步导致应用、事件之间关系不明确。并且当大量的事件监听以及其触发的通信流程,会产生性能问题。可以想见,该机制对于整个方案的实现成本、问题排查、设备的算力要求都会造成不必要的影响。3. Each communication class must correspond to different event listeners, and the distribution and subscription of events are asynchronous. For complex scenarios, the management complexity of multiple events is high. Multiple communication classes correspond to the complex dependencies of multiple applications under the micro-application architecture, which further leads to unclear relationships between applications and events. And when there are a large number of event listeners and the communication processes triggered by them, performance problems will arise. It can be imagined that this mechanism will have unnecessary impact on the implementation cost, troubleshooting, and computing power requirements of the entire solution.

四、当应用销毁时,事件并不会被主动移除。而每个事件可能绑定了多个通信类,均需要手动调用相关移除事件移除,否则会导致内存溢出。4. When the application is destroyed, the event will not be removed automatically. Each event may be bound to multiple communication classes, and you need to manually call the relevant removal event to remove it, otherwise it will cause memory overflow.

五、由于不存在全局状态池。数据被存储在特定通信类对应的池内,在需要进行数据获取时,无形提高了数据获取的门槛,降低了数据流通的效率。5. Since there is no global state pool, data is stored in the pool corresponding to a specific communication class. When data acquisition is needed, the threshold for data acquisition is raised invisibly, and the efficiency of data circulation is reduced.

为了解决上述现有技术所造成的问题,本发明实施例提供了一种不同的实现机制:通过对微前端的监听机制进行改造,脱离基座模块宿主的约束,可以在不同基座模块下灵活使用。In order to solve the problems caused by the above-mentioned prior art, an embodiment of the present invention provides a different implementation mechanism: by modifying the monitoring mechanism of the micro front end, it is freed from the constraints of the base module host and can be flexibly used under different base modules.

可选地,图4为本发明实施例提供的一种微前端架构系统示意图,参见该图4,该实现方式中的微前端架构系统,构建了一个新的“数据中心”,该数据中心包含:事件中心与全局状态池。所有的子应用和基座模块的数据交互、操作均通过该数据中心进行响应。Optionally, FIG4 is a schematic diagram of a micro-frontend architecture system provided by an embodiment of the present invention. Referring to FIG4, the micro-frontend architecture system in this implementation method builds a new "data center", which includes: an event center and a global state pool. All data interactions and operations of sub-applications and base modules are responded to through the data center.

继续参见图4,该示例中以一个基座模块与两个子应用,即子应用-1与子应用-2进行说明。Continuing to refer to FIG. 4 , this example is illustrated with one base module and two sub-applications, namely, sub-application-1 and sub-application-2.

在图4的基础上,图5为本发明实施例提供的一种微前端跨应用信息共享方法的流程示意图,参见图5,该方法包括:Based on FIG. 4 , FIG. 5 is a flow chart of a micro-frontend cross-application information sharing method provided by an embodiment of the present invention. Referring to FIG. 5 , the method includes:

步骤100、数据中心中的事件中心确认观察者池中是否存在观察者。Step 100: The event center in the data center confirms whether there is an observer in the observer pool.

其中,观察者为由基座模块或任意一个子应用注册生成的。Among them, the observer is registered and generated by the base module or any sub-application.

步骤101、若存在观察者,则通过全局监听事件对目标值进行监听。Step 101: If an observer exists, the target value is monitored through a global monitoring event.

具体的,当存在观察者时,则该观察者对应的子应用通过该观察者对目标值进行监听。例如图4所示子应用-2,若数据中心中存在观察者,且该观察者为观察者B,则此时子应用-2通过观察者B对全局状态池中的目标值进行事件监听。Specifically, when there is an observer, the sub-application corresponding to the observer monitors the target value through the observer. For example, in the sub-application-2 shown in FIG4 , if there is an observer in the data center, and the observer is observer B, then at this time, sub-application-2 monitors the event of the target value in the global state pool through observer B.

步骤102、若目标值发生变化,则根据目标值下发关系池向对应的目标子应用和/或基座模块发送目标值的变化值。Step 102: If the target value changes, the target value change value is sent to the corresponding target sub-application and/or base module according to the target value distribution relationship pool.

具体的,对于本方案来说,在事件中心中可以维护目标值下发关系池,该目标值下发关系池用于指示特定某个目标值对应的子应用或基座模块。意即,在本方案中,可以通过定义特定目标值需要定向的发送给哪些子应用或基座模块,来实现目标值的变化值只发送给具有对应需求的子应用与基座模块,从而提高数据通信的效率。Specifically, for this solution, a target value sending relationship pool can be maintained in the event center, and the target value sending relationship pool is used to indicate the sub-application or base module corresponding to a specific target value. That is, in this solution, by defining which sub-applications or base modules a specific target value needs to be sent to, the change value of the target value can be sent only to the sub-applications and base modules with corresponding requirements, thereby improving the efficiency of data communication.

本发明实施例提供的微前端跨应用信息共享方法,不对基座模块是否发起监听的注册进行约束。仅仅通过判断观察者池是否为零,来触发后续数据的通信。进而由于利用了目标值下发关系池,可以使得目标值变化时,变化值仅向对应的子应用、基座模块进行传输。在保证数据传输的效率的同时,提供了更加灵活的数据通信方式。The micro-frontend cross-application information sharing method provided by the embodiment of the present invention does not restrict whether the base module initiates the monitoring registration. The communication of subsequent data is triggered only by judging whether the observer pool is zero. Furthermore, since the target value is sent to the relationship pool, when the target value changes, the changed value is only transmitted to the corresponding sub-application and base module. While ensuring the efficiency of data transmission, a more flexible data communication method is provided.

同时,因为避免使用不同的通信类对全局状态池进行拆分,其实现成本较低,方案维护的复杂度低于使用通信类在不同命名空间进行数据通信的方案。At the same time, because it avoids splitting the global state pool using different communication classes, its implementation cost is lower and the complexity of solution maintenance is lower than the solution of using communication classes to communicate data in different namespaces.

可选地,该数据中心可以以npm安装包的形式实现。各子应用、基座模块可以通过加载该npm安装包来进行使用。可以像使用组件一样灵活的安装和使用该数据中心。Optionally, the data center can be implemented in the form of an npm installation package. Each sub-application and base module can be used by loading the npm installation package. The data center can be installed and used as flexibly as a component.

可选地,由于本发明实施例提供的一个核心思路在于:将观察者、全局监听事件的初始化、建立从必须由基座模块发起这一条件中剥离出来,下面提供一种可能的实现方式,对如何构建观察者与全局监听事件进行示例性说明。具体的,图5的基础上,图6为本发明实施例提供的另一种微前端跨应用信息共享方法的流程示意图,参见图6,在步骤100之前,还包括:Optionally, since a core idea provided by an embodiment of the present invention is to separate the initialization and establishment of observers and global listening events from the condition that they must be initiated by the base module, a possible implementation method is provided below to illustrate how to construct observers and global listening events. Specifically, based on FIG5, FIG6 is a flow chart of another micro-frontend cross-application information sharing method provided by an embodiment of the present invention. Referring to FIG6, before step 100, it also includes:

步骤103、事件中心接收基座模块或任意一个子应用发送的绑定请求。Step 103: The event center receives a binding request sent by the base module or any sub-application.

具体的,该绑定请求可以由基座模块或子应用通过“onGlobalStateChange”发起,然而该“onGlobalStateChange”与现有技术不同的点在于:其发起的绑定请求还包含用于表征基座模块或子应用的标识信息。以便在后续目标值的下发过程中,利用标识信息实现信息的定向发送。Specifically, the binding request can be initiated by the base module or sub-application through "onGlobalStateChange", but the difference between "onGlobalStateChange" and the prior art is that the binding request initiated by it also contains identification information for characterizing the base module or sub-application, so that in the subsequent process of sending the target value, the identification information can be used to achieve targeted information sending.

另外,由于本方案无论是基座模块还是子应用,都可以直接发起建立观察者的流程。而无需像现有技术一样,必须由基座模块通过“initGlobalState”发起注册监听函数的流程,如发起注册以及监听任务、建立全局监听事件、全局状态池的定义等操作。从而实现跨应用的数据通信与基座模块解耦。In addition, in this solution, both the base module and the sub-application can directly initiate the process of establishing the observer. Unlike the existing technology, the base module does not need to initiate the process of registering the monitoring function through "initGlobalState", such as initiating registration and monitoring tasks, establishing global monitoring events, defining the global state pool, etc., thereby achieving cross-application data communication and decoupling from the base module.

步骤104、事件中心根据该绑定请求为对应的基座模块或任意一个子应用在观察者池中建立对应的观察者。Step 104: The event center establishes a corresponding observer in the observer pool for the corresponding base module or any sub-application according to the binding request.

步骤105、事件中心判断全局监听事件是否已建立。Step 105: The event center determines whether the global monitoring event has been established.

具体的,当观察者池中存在观察者时,即步骤104已完成了观察者的建立时,需要确认数据中心中的全局监听事件是否完成初始化,即是否建立。如果未建立,则执行步骤106。如果已建立,则基于步骤103与步骤104建立的观察者,可以利用已经存在的全局监听事件基于前文图5所示步骤100及后续步骤,进行目标值监听与变化值下发的相关操作。Specifically, when there is an observer in the observer pool, that is, when step 104 has completed the establishment of the observer, it is necessary to confirm whether the global listening event in the data center has completed initialization, that is, whether it has been established. If not established, execute step 106. If established, based on the observer established in steps 103 and 104, the existing global listening event can be used to perform the relevant operations of target value monitoring and change value distribution based on step 100 and subsequent steps shown in Figure 5 above.

步骤106、事件中心建立全局监听事件。Step 106: The event center establishes a global monitoring event.

具体的,对于全局监听事件未建立的情况,例如在第一个观察者建立时,或者全局监听事件未完成初始化时,则需要执行步骤106。Specifically, if the global listening event is not established, for example, when the first observer is established, or the global listening event is not initialized, step 106 needs to be executed.

需要说明的是,参见图6,在步骤106完成全局监听事件的建立之后,有可能出现子应用被销毁、全局监听事件被销毁等情况,进而导致观察者被删除,因此,在针对目标值进行监听时,首先需要判断观察者池中是否存在观察者,即上文步骤100。进而若在当前时刻该观察者池中不存在观察者,则需要返回执行步骤106。It should be noted that, referring to FIG. 6 , after the establishment of the global listening event is completed in step 106, the sub-application may be destroyed, the global listening event may be destroyed, and the observer may be deleted. Therefore, when monitoring the target value, it is first necessary to determine whether there is an observer in the observer pool, that is, the above step 100. If there is no observer in the observer pool at the current moment, it is necessary to return to step 106.

具体的,在图4的基础上,图7为本发明实施例提供的另一种微前端架构系统示意图,其相对于图4,提供了结合“MicroAppStateActions”实例的具体实现方式,与图3所示现有技术相比,结合图7可以发现,本发明实施例中基座模块舍弃了“initGlobalState”。对基座模块或者任意一个子应用来说,其仅需要通过“onGlobalStateChange”来进行观察者的建立。Specifically, based on FIG4, FIG7 is another schematic diagram of a micro-frontend architecture system provided by an embodiment of the present invention, which provides a specific implementation method combined with the "MicroAppStateActions" instance relative to FIG4. Compared with the prior art shown in FIG3, it can be found in combination with FIG7 that the base module in the embodiment of the present invention abandons "initGlobalState". For the base module or any sub-application, it only needs to establish an observer through "onGlobalStateChange".

进而,由事件中心来执行原有“initGlobalState”的逻辑,即完成注册与监听任务,定义全局状态,以及建立全局监听事件。从而对于第三方的基座模块来说,本方案不需要对该基座模块进行过的适配,来实现对应监听方案的注册与发起。在本方案中,由于第三方的基座不承担上述“initGlobalState”的逻辑,其与其他子应用均通过“onGlobalStateChange”完成观察者的建立,从而提高了本方案在不同第三方基座模块上的适用性。Then, the event center executes the original "initGlobalState" logic, that is, completes the registration and monitoring tasks, defines the global state, and establishes global monitoring events. Therefore, for the third-party base module, this solution does not need to adapt the base module to realize the registration and initiation of the corresponding monitoring solution. In this solution, since the third-party base does not bear the above-mentioned "initGlobalState" logic, it and other sub-applications complete the establishment of observers through "onGlobalStateChange", thereby improving the applicability of this solution on different third-party base modules.

具体的,继续参见图7,基座模块通过“onGlobalStateChange”在事件中心建立观察者S;类似地,该子应用-1通过“onGlobalStateChange”在事件中心建立观察者A;该子应用-2通过“onGlobalStateChange”在事件中心建立观察者B。Specifically, referring to FIG. 7 , the base module establishes observer S in the event center through “onGlobalStateChange”; similarly, the sub-application-1 establishes observer A in the event center through “onGlobalStateChange”; and the sub-application-2 establishes observer B in the event center through “onGlobalStateChange”.

可选地,在图5的基础上,图8为本发明实施例提供的另一种微前端跨应用信息共享方法的流程示意图,参见图8,步骤101,包括:Optionally, based on FIG. 5 , FIG. 8 is a flow chart of another micro-frontend cross-application information sharing method provided by an embodiment of the present invention. Referring to FIG. 8 , step 101 includes:

步骤101-1、事件中心接收已注册子应用的更新数据状态消息。Step 101 - 1 : The event center receives an update data status message of a registered sub-application.

其中,该已注册子应用指已经建立观察者的子应用;更新数据状态消息包含目标值与指定标识信息;指定标识信息为当目标值发生变化时,可获得变化值的子应用或基座模块的标识信息。可选地,该已注册子应用也可以为基座模块。The registered sub-application refers to a sub-application that has established an observer; the updated data status message includes a target value and specified identification information; the specified identification information is the identification information of the sub-application or base module that can obtain the changed value when the target value changes. Optionally, the registered sub-application can also be a base module.

步骤101-2、事件中心将目标值在全局状态池中进行维护。Step 101-2: The event center maintains the target value in the global state pool.

步骤101-3、事件中心通过过滤器维护目标值对应的指定标识信息,以建立目标值下发关系池。Step 101 - 3 : The event center maintains the designated identification information corresponding to the target value through the filter to establish a target value delivery relationship pool.

具体的,该目标值下发关系池用于指示某一特定的目标值发生变化时,该变化值可以被分享给哪些子应用和/或基座模块。Specifically, the target value delivery relationship pool is used to indicate which sub-applications and/or base modules the changed value can be shared with when a specific target value changes.

步骤101-4、数据中心对全局状态池中的目标值进行事件监听。Step 101-4: The data center monitors events of the target value in the global state pool.

继续参见图8,步骤102具体包括:Continuing to refer to FIG. 8 , step 102 specifically includes:

步骤102-1、事件中心监听到目标值发生变化时,获得目标值的变化值。Step 102-1: When the event center monitors that the target value changes, the change value of the target value is obtained.

步骤102-2、事件中心通过过滤器维护的目标值下发关系池,确认变化值对应的指定标识信息。Step 102-2: The event center sends the target value maintained by the filter to the relationship pool to confirm the designated identification information corresponding to the change value.

可选地,如果该目标值下发关系池中,特定的目标值并没有指定明确的指定标识信息,则该事件中心可以以广播的形式向全部标识信息对应的基座模块以及子应用发送该变化值。Optionally, if the target value is sent to the relationship pool and a specific target value does not specify clear identification information, the event center can send the change value to all base modules and sub-applications corresponding to the identification information in the form of broadcast.

步骤102-3、事件中心将变化值发送至指定标识信息对应的子应用和/或基座模块。Step 102-3: The event center sends the change value to the sub-application and/or base module corresponding to the specified identification information.

具体的,参见图7,以子应用-1为例,在当子应用-1通过“onGlobalStateChange”完成观察者A的建立之后,可以基于“SetGlobalState”向数据中心发起更新数据状态消息,该消息可以包括:目标值与指定标识信息。例如,该目标值为“A=1”,该指定标识信息为子应用-2的标识信息“002”。对应前文步骤101-2,则数据中心中的事件中心会通过过滤器维护该目标值对应的指定标识信息。并且数据中心对全局状态池中已经维护目标值进行事件监听。具体的,可以利用事件中心中的观察者来实现上述事件监听。Specifically, referring to Figure 7, taking sub-application-1 as an example, after sub-application-1 completes the establishment of observer A through "onGlobalStateChange", it can initiate a data status update message to the data center based on "SetGlobalState", which may include: target value and specified identification information. For example, the target value is "A=1", and the specified identification information is the identification information "002" of sub-application-2. Corresponding to the previous step 101-2, the event center in the data center will maintain the specified identification information corresponding to the target value through a filter. And the data center monitors events for the target value that has been maintained in the global state pool. Specifically, the above event monitoring can be implemented using the observer in the event center.

可选地,参见前文,该目标值下发关系池可以分别通过:“onGlobalStateChange”来获得观察者与标识信息的对应关系,进而再基于“SetGlobalState”获得目标值与指定标识信息的对应关系。从而构成“观察者-指定标识信息-目标值”的完整对应关系,其作用在于:当A发生变化时,事件中心中的过滤器首先确定该目标值的变化需要返回给哪些子应用或基座模块。在本示例中,由于目标值“A=1”与指定标识信息“002”对应,则此时,当目标值变化时,过滤器确定该目标值下发关系池中的子应用-2具有对应关系,进而子应用-2对应的观察者B会将变化值从全局状态池中获得,并返回该变化值,即更新状态。Optionally, referring to the foregoing, the target value sending relationship pool can obtain the correspondence between the observer and the identification information through "onGlobalStateChange", and then obtain the correspondence between the target value and the specified identification information based on "SetGlobalState". Thus, a complete correspondence of "observer-specified identification information-target value" is formed, and its function is: when A changes, the filter in the event center first determines which sub-applications or base modules the change of the target value needs to be returned to. In this example, since the target value "A=1" corresponds to the specified identification information "002", at this time, when the target value changes, the filter determines that the sub-application-2 in the target value sending relationship pool has a corresponding relationship, and then the observer B corresponding to the sub-application-2 will obtain the change value from the global state pool and return the change value, that is, update the state.

需要说明的是,上文仅以子应用-2的标识信息与目标值“A=1”具有指定关系作为示例。显然,其也可以与其他子应用或基座模块具备类似的指定关系,从而在目标值发生变化时,将变化值通过目标值下发关系池,灵活地返回给对应的一个或多个子应用、子应用与基座模块的组合、或仅基座模块。It should be noted that the above only takes the identification information of sub-application-2 and the target value "A=1" as an example of having a specified relationship. Obviously, it can also have a similar specified relationship with other sub-applications or base modules, so that when the target value changes, the changed value is sent to the target value relationship pool and flexibly returned to the corresponding one or more sub-applications, the combination of sub-applications and base modules, or only the base module.

另外,需要说明的是,在上述图5及图8所示的示例中,当在步骤100判断观察者池中不存在观察者时,可以采用图6所示的机制,返回执行步骤106建立“全局监听事件”的步骤。In addition, it should be noted that in the examples shown in Figures 5 and 8 above, when it is determined in step 100 that there is no observer in the observer pool, the mechanism shown in Figure 6 can be used to return to step 106 to establish a "global listening event".

综上所述,对于本发明实施例来说,由于在每个子应用利用“SetGlobalState”反馈更新数据状态消息,在明确目标值的同时,反馈指定标识信息。从而将全局状态池中的目标值灵活地与全部或部分子应用、基座模块建立对应关系。使得当该目标值发生变化时,数据的交互可以是全局的,也可以是局部的。在保证数据通信的效率的同时,提高了数据通信的灵活性。In summary, for the embodiment of the present invention, since the data status message is updated by using "SetGlobalState" feedback in each sub-application, the specified identification information is fed back while clarifying the target value. Thus, the target value in the global state pool is flexibly associated with all or part of the sub-applications and base modules. When the target value changes, the data interaction can be global or local. While ensuring the efficiency of data communication, the flexibility of data communication is improved.

可选的,对于现有技术来说,无论是基于基座模块发起的全局状态下的数据广播式的跨应用数据通信方案,还是将全局状态池进行拆分,以通信类来进行数据通信。其数据通信的方式均为被动的,意即只有在数据发生变化时,应用通过监听被动的获取数据的变化值。然而在微应用的实际场景中,对于一些应用,对于全局状态池中的某些数据,如果能够主动的获取该数据,则能够提高数据通信的效率以及灵活性。下面,本发明实施例提供一种可能的实现方式,来实现对于全局状态池中数据的灵活获取,具体的,该方法包括:Optionally, for the prior art, whether it is a cross-application data communication scheme based on data broadcasting in the global state initiated by the base module, or splitting the global state pool to perform data communication in a communication class. Its data communication method is passive, that is, only when the data changes, the application passively obtains the change value of the data by listening. However, in the actual scenario of micro-applications, for some applications, for certain data in the global state pool, if the data can be actively obtained, the efficiency and flexibility of data communication can be improved. Below, an embodiment of the present invention provides a possible implementation method to achieve flexible acquisition of data in the global state pool. Specifically, the method includes:

数据中心接收任一子应用或基座模块发送的数据获取消息。The data center receives a data acquisition message sent by any sub-application or base module.

具体的,该数据获取消息包含目标值的获取指示。Specifically, the data acquisition message includes an acquisition instruction of the target value.

进而,数据中心向子应用或基座模块发送目标值。In turn, the data center sends the target value to the sub-application or base module.

具体的,在图7的基础上,图9为本发明实施例提供的另一种微前端架构系统示意图。参见图9,相对于图7,本发明实施例引入一个新的子应用-3,其可以具备与子应用-1或子应用-2类似的功能,例如利用“onGlobalStateChange”来建立观察者,监听数据变化;利用“SetGlobalState”来指定目标值与指定标识信息等。Specifically, based on Figure 7, Figure 9 is another schematic diagram of a micro-frontend architecture system provided by an embodiment of the present invention. Referring to Figure 9, relative to Figure 7, the embodiment of the present invention introduces a new sub-application-3, which can have similar functions to sub-application-1 or sub-application-2, such as using "onGlobalStateChange" to establish an observer to monitor data changes; using "SetGlobalState" to specify target values and specify identification information, etc.

在本发明实施例中,该子应用-3还可以利用“GetGlobalState”来实现数据获取的功能,即利用“GetGlobalState”向全局状态池发去数据获取消息。对应的,该全局状态池可以通过“暴露Getter”的方法,将数据暴露给子应用-3。In the embodiment of the present invention, the sub-application-3 can also use "GetGlobalState" to implement the data acquisition function, that is, use "GetGlobalState" to send a data acquisition message to the global state pool. Correspondingly, the global state pool can expose the data to the sub-application-3 through the "expose Getter" method.

需要说明的是,图9所示的子应用-3为完成相关观察者建立的已注册子应用。在另一种可能的实现方式中,某一子应用也可以在未进行观察者相关建立流程的情况下,直接通过上述数据获取消息来获取全局状态池中通过“暴露Getter”的方法维护的数据。It should be noted that the sub-application-3 shown in Figure 9 is a registered sub-application that has completed the establishment of relevant observers. In another possible implementation, a sub-application can also directly obtain the data maintained by the "exposed Getter" method in the global state pool through the above data acquisition message without performing the observer-related establishment process.

另外,相对于利用通信类将全局状态池进行拆分的方式,其数据即使能够进行共享,也仅仅能够在同一个通信类对应的子数据池中实现,无法在全局进行数据的主动获取。而在本申请上述示例中,全局状态池的数据可以被任意一子应用或基座模块获得,数据通信效率明显提高。In addition, compared with the method of splitting the global state pool by using the communication class, even if the data can be shared, it can only be realized in the sub-data pool corresponding to the same communication class, and it is impossible to actively obtain data globally. In the above example of this application, the data of the global state pool can be obtained by any sub-application or base module, and the data communication efficiency is significantly improved.

在另一种可能的实现方式中,上述示例中数据中心观察者池中维护的观察者,可以随着对应子应用的销毁而被删除。以便保证观察者与子应用、基座模块之间灵活、准确地对应关系。具体的,其存在如下情况:In another possible implementation, the observers maintained in the data center observer pool in the above example can be deleted when the corresponding sub-application is destroyed. This ensures a flexible and accurate correspondence between observers and sub-applications and base modules. Specifically, the following situations exist:

情况一、当全局监听事件被销毁时,则事件中心删除对应的全部观察者。Case 1: When the global monitoring event is destroyed, the event center deletes all corresponding observers.

具体的,可以在每一次全局监听事件对应目标值下发的时候,可先进行一次“hasEventListener”的判断,以确认该全局监听事件是否被销毁。另外,参见前文,在观察者池为空,且未建立新的观察者时,也可以对该全局监听事件进行销毁,此时由于不存在观察者,其并不会涉及相关观察者的删除行为。Specifically, each time the target value corresponding to the global listening event is issued, a "hasEventListener" judgment can be performed to confirm whether the global listening event is destroyed. In addition, as mentioned above, when the observer pool is empty and no new observer is established, the global listening event can also be destroyed. At this time, since there is no observer, it does not involve the deletion of related observers.

情况二、当某一特定的子应用被销毁时,则事件中心删除该子应用对应的观察者。Case 2: When a specific sub-application is destroyed, the event center deletes the observer corresponding to the sub-application.

具体的,该子应用被销毁时,对应的观察者状态为“失活状态”,该事件中心可以基于确认观察者的状态,来对处于“失活状态”的观察者进行删除。Specifically, when the sub-application is destroyed, the corresponding observer state is "inactive state", and the event center can delete the observer in the "inactive state" based on the confirmed observer state.

由于在本方案中,不需要设立不同通信类,而是基于一个全局的监听事件进行数据变化的监听。从而避免了基于事件驱动的数据通信方式中,应用销毁时需要针对不同通信类,手动将对应事件监听移除,保证了数据通信的通讯效率,同时降低了实现成本。In this solution, there is no need to set up different communication classes, but data changes are monitored based on a global monitoring event. This avoids the need to manually remove the corresponding event monitoring for different communication classes when the application is destroyed in the event-driven data communication method, ensuring the communication efficiency of data communication and reducing the implementation cost.

可选地,参见上文本发明实施例还提供一种微前端架构系统,参见前文图4、图7以及图9所示,该微前端架构系统包括:数据中心、基座模块与多个子应用。Optionally, referring to the above embodiment of the present invention, a micro-front-end architecture system is also provided, referring to the above Figures 4, 7 and 9, the micro-front-end architecture system includes: a data center, a base module and multiple sub-applications.

数据中心中的事件中心,用于确认观察者池中是否存在观察者;观察者为由基座模块或任意一个子应用注册生成的;若存在观察者,则通过全局监听事件对目标值进行监听;若目标值发生变化,则根据目标值下发关系池向对应的目标子应用或基座模块发送目标值的变化值。The event center in the data center is used to confirm whether there is an observer in the observer pool; the observer is registered and generated by the base module or any sub-application; if there is an observer, the target value is monitored through the global monitoring event; if the target value changes, the target value change value is sent to the corresponding target sub-application or base module according to the target value distribution relationship pool.

该微前端架构系统可以用于执行上述示例中各个流程步骤,以实现对应的技术效果。The micro-frontend architecture system can be used to execute each process step in the above example to achieve the corresponding technical effects.

本发明实施例还提供一种电子设备,其可以执行本发明实施例上述全部示例的步骤,以实现对应的技术效果。具体的,图10为本发明实施例提供的一种电子设备的结构示意图,参见图10,该电子设备20,包括:存储器201、处理器200;The embodiment of the present invention further provides an electronic device, which can execute all the steps of the above examples of the embodiment of the present invention to achieve the corresponding technical effects. Specifically, FIG10 is a schematic diagram of the structure of an electronic device provided by the embodiment of the present invention. Referring to FIG10, the electronic device 20 includes: a memory 201, a processor 200;

存储器201,用于存储一个或多个程序;Memory 201, used to store one or more programs;

处理器200;Processor 200;

当一个或多个程序被处理器执行时,当该电子设备20用于执行上述各个方法示例所示的步骤时,其可以实现各个步骤及对应技术效果。When one or more programs are executed by the processor, when the electronic device 20 is used to execute the steps shown in the above-mentioned method examples, it can achieve each step and corresponding technical effects.

在本申请所提供的实施例中,应该理解到,所揭露的装置和方法,也可以通过其它的方式实现。以上所描述的装置实施例仅仅是示意性的,例如,附图中的流程图和框图显示了根据本申请的多个实施例的装置、方法和程序产品的可能实现的体系架构、功能和操作。在这点上,流程图或框图中的每个方框可以代表一个模块、程序段或代码的一部分,模块、程序段或代码的一部分包含一个或多个用于实现规定的逻辑功能的可执行指令。也应当注意,在有些作为替换的实现方式中,方框中所标注的功能也可以以不同于附图中所标注的顺序发生。例如,两个连续的方框实际上可以基本并行地执行,它们有时也可以按相反的顺序执行,这依所涉及的功能而定。也要注意的是,框图和/或流程图中的每个方框、以及框图和/或流程图中的方框的组合,可以用执行规定的功能或动作的专用的基于硬件的系统来实现,或者可以用专用硬件与计算机指令的组合来实现。In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are merely schematic. For example, the flowcharts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the devices, methods and program products according to the multiple embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of the code, and a part of the module, program segment or code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and/or flowchart, and the combination of boxes in the block diagram and/or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.

另外,在本申请各个实施例中的各功能模块可以集成在一起形成一个独立的部分,也可以是各个模块单独存在,也可以两个或两个以上模块集成形成一个独立的部分。In addition, the functional modules in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.

功能如果以软件功能模块的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的部分可以以软件产品的形式体现出来,该程序产品存储在一个计算机可读存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本申请各个实施例方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、磁碟或者光盘等各种可以存储程序代码的介质。If the function is implemented in the form of a software function module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application can essentially or in other words, the part that contributes to the prior art or the part of the technical solution can be embodied in the form of a software product. The program product is stored in a computer-readable storage medium, including a number of instructions for a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.

以上仅为本申请的优选实施例而已,并不用于限制本申请,对于本领域的技术人员来说,本申请可以有各种更改和变化。凡在本申请的精神和原则之内,所作的任何修改、等同替换、改进等,均应包含在本申请的保护范围之内。The above are only preferred embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.

对于本领域技术人员而言,显然本申请不限于上述示范性实施例的细节,而且在不背离本申请的精神或基本特征的情况下,能够以其它的具体形式实现本申请。因此,无论从哪一点来看,均应将实施例看作是示范性的,而且是非限制性的,本申请的范围由所附权利要求而不是上述说明限定,因此旨在将落在权利要求的等同要件的含义和范围内的所有变化囊括在本申请内。不应将权利要求中的任何附图标记视为限制所涉及的权利要求。It will be apparent to those skilled in the art that the present application is not limited to the details of the exemplary embodiments described above, and that the present application can be implemented in other specific forms without departing from the spirit or essential features of the present application. Therefore, the embodiments should be considered exemplary and non-limiting in all respects, and the scope of the present application is defined by the appended claims rather than the above description, and it is intended that all changes falling within the meaning and scope of the equivalent elements of the claims be included in the present application. Any reference numeral in a claim should not be considered as limiting the claim to which it relates.

Claims (9)

1. The micro-front-end cross-application information sharing method is characterized by being applied to a micro-front-end architecture system, and the micro-front-end architecture system comprises: a data center, a base module, and a plurality of sub-applications, the method comprising:
An event center in the data center confirms whether an observer exists in the observer pool; the observer is generated by the base module or any one of the sub-applications registration;
If the observer exists, the event center receives an update data status message of the registered sub-application; the update data status message contains a target value and specified identification information; the appointed identification information is identification information of a sub-application or a base module which can obtain the change value when the target value changes;
The event center maintains the target value in a global state pool;
the event center maintains the appointed identification information corresponding to the target value through a filter so as to establish a target value issuing relation pool;
The data center monitors the target value in the global state pool for events;
If the target value changes, sending a change value of the target value to a corresponding target sub-application or base module according to the target value issuing relation pool; the target value issuing relation pool is used for indicating the sub-application or the base module corresponding to the target value.
2. The method of claim 1, further comprising, prior to the step of the event center in the data center confirming whether an observer exists in the observer pool:
the event center receives a binding request sent by a base module or any one of the sub-applications;
the event center establishes a corresponding observer in the observer pool for a corresponding base module or any sub-application according to the binding request;
the event center judges whether the global monitoring event is established or not;
If not, the event center establishes the global monitoring event.
3. The method of claim 1, wherein the step of sending the changed value of the target value to the corresponding target sub-application according to the target value issuing relationship pool if the target value is changed comprises:
When the event center monitors that the target value changes, a change value of the target value is obtained;
The event center issues a relation pool through the target value maintained by the filter, and confirms the appointed identification information corresponding to the change value;
and the event center sends the change value to the sub-application and/or the base module corresponding to the appointed identification information.
4. The method as recited in claim 1, further comprising:
The data center receives a data acquisition message sent by any sub-application or the base module; the data acquisition message contains an acquisition indication of the target value;
The data center applies the target value sent by the base module to the sub-application.
5. The method as recited in claim 1, further comprising:
when the global monitoring event is destroyed, the event center deletes all corresponding observers;
when any sub-application is destroyed, the event center deletes the corresponding observer in the observer pool.
6. A micro front end architecture system, the micro front end architecture system comprising: the system comprises a data center, a base module and a plurality of sub-applications;
An event center in the data center for confirming whether an observer exists in the observer pool; the observer is generated by the base module or any one of the sub-applications registration; if the observer exists, the event center receives an update data status message of the registered sub-application; the update data status message contains a target value and specified identification information; the appointed identification information is identification information of a sub-application or a base module which can obtain the change value when the target value changes; the event center maintains the target value in a global state pool; the event center maintains the appointed identification information corresponding to the target value through a filter so as to establish a target value issuing relation pool; the data center monitors the target value in the global state pool for events; if the target value changes, sending a change value of the target value to a corresponding target sub-application or base module according to a target value issuing relation pool; the target value issuing relation pool is used for indicating the sub-application or the base module corresponding to the target value.
7. An electronic device, comprising:
A memory for storing one or more programs;
A processor;
the method of any of claims 1-5 is implemented when the one or more programs are executed by the processor.
8. A computer readable storage medium, on which a computer program is stored, which computer program, when being executed by a processor, implements the method according to any of claims 1-5.
9. A program product, characterized in that it implements the method according to any of claims 1-5 when being executed by a processor.
CN202410851557.XA 2024-06-28 2024-06-28 A micro-frontend cross-application information sharing method and micro-frontend architecture system Active CN118394548B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202410851557.XA CN118394548B (en) 2024-06-28 2024-06-28 A micro-frontend cross-application information sharing method and micro-frontend architecture system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202410851557.XA CN118394548B (en) 2024-06-28 2024-06-28 A micro-frontend cross-application information sharing method and micro-frontend architecture system

Publications (2)

Publication Number Publication Date
CN118394548A CN118394548A (en) 2024-07-26
CN118394548B true CN118394548B (en) 2024-10-29

Family

ID=91999690

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202410851557.XA Active CN118394548B (en) 2024-06-28 2024-06-28 A micro-frontend cross-application information sharing method and micro-frontend architecture system

Country Status (1)

Country Link
CN (1) CN118394548B (en)

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116992182A (en) * 2023-08-07 2023-11-03 中国航空工业集团公司雷华电子技术研究所 Dynamic registration and anomaly monitoring method for sub-application based on micro front end

Family Cites Families (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112363857B (en) * 2021-01-12 2021-04-02 恒生电子股份有限公司 Application system, synchronization method, storage medium and device of micro front-end architecture
US20240056438A1 (en) * 2021-05-17 2024-02-15 Matrics2, Inc. Using globally-unique numbers for all secure unique transactions, authentications, verifications, and messaging identities
CN114327687B (en) * 2022-03-09 2022-05-20 恒生电子股份有限公司 Method, device and equipment for constructing sub-application in micro front-end mode and storage medium
CN115390897B (en) * 2022-08-22 2023-06-20 再惠(上海)网络科技有限公司 Micro front end management method, micro front end management device, electronic equipment and storage medium
CN115827105A (en) * 2022-12-22 2023-03-21 南威软件股份有限公司 Micro front end architecture based method for dynamically loading main and sub applications
CN117170902A (en) * 2023-08-31 2023-12-05 杭州数梦工场科技有限公司 Cross-application communication method, device, equipment and storage medium based on class
CN117632545A (en) * 2023-12-06 2024-03-01 中电金信数字科技集团有限公司 Data sharing method and device of business system and electronic equipment

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116992182A (en) * 2023-08-07 2023-11-03 中国航空工业集团公司雷华电子技术研究所 Dynamic registration and anomaly monitoring method for sub-application based on micro front end

Also Published As

Publication number Publication date
CN118394548A (en) 2024-07-26

Similar Documents

Publication Publication Date Title
CN107729139B (en) Method and device for concurrently acquiring resources
CN108449410B (en) Message management method, system and related device in cloud platform
EP3226493B1 (en) Method, device, and system for discovering the relationship of applied topology
US10454795B1 (en) Intermediate batch service for serverless computing environment metrics
CN103024022A (en) Controlling and management system and method of virtual machine application service
CN104899093B (en) Data processing method, device and system
US20240370297A1 (en) Resource scheduling system and method
CN105516086A (en) Service processing method and apparatus
CN110659104B (en) Service monitoring method and related equipment
WO2017049912A1 (en) Service processing method adopted by jslee container and system utilizing same
CN111464589A (en) Intelligent contract processing method, computer equipment and storage medium
CN114201197A (en) Firmware upgrade method, device, electronic device and readable storage medium
CN109194589B (en) MDC (media data center) implementation method and device
CN112596931B (en) Cross-process communication method and device, electronic equipment and storage medium
CN110730197B (en) Service discovery method and system
CN113010280B (en) Processing method, system, device, equipment and medium for distributed task
CN115268949A (en) Mirror preheating method, device, equipment and storage medium
CN118394548B (en) A micro-frontend cross-application information sharing method and micro-frontend architecture system
JP2018514829A (en) Multi-account login and communication method, apparatus, and mobile terminal
CN114153573A (en) Multitasking method based on single thread pool and related device
CN118916278A (en) Management method, device, equipment and storage medium for shared construction space
CN112202605A (en) Service configuration method, device, equipment and storage medium
CN110943975B (en) Service registration method, device, computer equipment and storage medium
CN114968636A (en) Fault processing method and device
CN113269605B (en) Order processing method, apparatus, device and computer readable medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant