Cross-domain data communication method, apparatus, device, and medium

By constructing a distributed worker cluster and distributed caching architecture for cross-domain scenarios, and utilizing P2P connections and standardized communication protocols, the problem of low efficiency in cross-domain data synchronization was solved, enabling collaborative work and data consistency among workers from multiple domains, and improving the efficiency of cross-domain data communication.

CN120583103BActive Publication Date: 2026-02-24ZHONGDIAN DATA IND CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510858892.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-06-25
Publication Date
2026-02-24
Estimated Expiration
2045-06-25

AI Technical Summary

Technical Problem

Cross-domain data synchronization suffers from low efficiency and serious resource waste. Existing cross-domain communication solutions have failed to effectively solve the problems of cache inconsistency and low efficiency in cross-domain communication.

Method used

To build a distributed worker cluster in a cross-domain scenario, a distributed caching architecture with local caching and global indexing is adopted. P2P connection between workers is realized through cross-domain MessageChannel, and data consistency is ensured by using standardized communication protocols and data version numbers.

Benefits of technology

It enables collaborative work of workers from multiple domains, reduces data transfer overhead, improves cross-domain data communication efficiency, reduces network traffic consumption and communication latency, and ensures real-time synchronization and version security of cross-domain data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120583103B_ABST
    Figure CN120583103B_ABST
Patent Text Reader

Abstract

The present disclosure relates to a cross-domain data communication method, device, equipment and medium, the method comprising: a target thread sends a first data request to a first worker in a distributed worker cluster; wherein the first data request includes a first data identifier; the distributed worker cluster includes a plurality of workers with different domain names; the first worker queries whether the first data identifier exists in a local first cache; if not, a second worker that caches the first data is determined based on a global index; wherein the first data is the data corresponding to the first data identifier; the first worker queries the response data corresponding to the first data identifier from the second worker across domains; wherein the response data includes the first data; and the first worker returns the first data to the target thread. The present disclosure can improve the cross-domain data communication efficiency and the cache consistency of data synchronization.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of data communication technology, and in particular to a cross-domain data communication method, apparatus, device and medium. Background Technology

[0002] In modern web development, cross-domain data synchronization is one of the core challenges faced by front-end applications. With the popularization of microservice architecture and distributed systems, front-end applications often need to interact with back-end services on multiple different domains (such as user centers, payment systems, recommendation engines, etc.). However, the browser's same-origin policy restricts the direct sharing of cross-domain data, resulting in low data synchronization efficiency and serious resource waste. Summary of the Invention

[0003] To address the aforementioned technical problems, this disclosure provides a cross-domain data communication method, apparatus, device, and medium.

[0004] According to one aspect of this disclosure, a cross-domain data communication method is provided, the method comprising:

[0005] The target thread sends a first data request to the first worker in the distributed worker cluster; wherein the first data request includes a first data identifier; the distributed worker cluster includes multiple workers with different domain names;

[0006] The first worker queries the local first cache to check if the first data identifier exists;

[0007] If it does not exist, the second Worker with the first data cached is determined based on the global index; wherein, the first data is the data corresponding to the first data identifier;

[0008] The response data corresponding to the first data identifier is queried across domains from the second worker through the first worker; wherein, the response data includes: the first data;

[0009] The first data is returned to the target thread through the first worker.

[0010] According to another aspect of this disclosure, an electronic device is also provided, the electronic device comprising:

[0011] processor;

[0012] Memory used to store the processor's executable instructions;

[0013] The processor is configured to read the executable instructions from the memory and execute the instructions to implement the above method.

[0014] According to another aspect of this disclosure, a computer-readable storage medium is also provided, the storage medium storing a computer program for performing the above-described method.

[0015] The technical solution provided in this disclosure has the following advantages compared with the prior art:

[0016] The technical solution provided in this disclosure includes: a target thread sending a first data request to a first worker in a distributed worker cluster; wherein the first data request includes a first data identifier; the distributed worker cluster includes multiple workers with different domain names; querying the local first cache of the first worker to see if the first data identifier exists; if it does not exist, determining the second worker that caches the first data based on a global index; wherein the first data is the data corresponding to the first data identifier; querying the response data corresponding to the first data identifier from the second worker across domains through the first worker; wherein the response data includes the first data; and returning the first data to the target thread through the first worker.

[0017] This technical solution constructs a distributed worker cluster for cross-domain scenarios and a distributed caching architecture including local caching and global indexes. Based on this, it enables collaborative work of workers from multiple domains. After the first worker receives the first data request, if the relevant data is not found in the local first cache, then based on the first data identifier, workers from different domains, and the global index, the first worker can query the response data corresponding to the first data identifier from a second worker with a different domain. That is, cross-domain data communication is directly performed between workers with different domains without any data transfer links or overhead. This enables efficient cross-domain data communication, reduces network traffic consumption and communication latency, and improves the efficiency of cross-domain data communication. Attached Figure Description

[0018] The accompanying drawings, which are incorporated in and form a part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure.

[0019] To more clearly illustrate the technical solutions in the embodiments of this disclosure or the prior art, the accompanying drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0020] Figure 1 This is a flowchart of the cross-domain data communication method described in the embodiments of this disclosure;

[0021] Figure 2 This is a schematic diagram of the initialization process described in an embodiment of this disclosure;

[0022] Figure 3 This is a flowchart of the cross-domain data synchronization method described in the embodiments of this disclosure;

[0023] Figure 4 This is a schematic diagram of the cross-domain data communication device described in an embodiment of this disclosure;

[0024] Figure 5 This is a schematic diagram of the structure of the electronic device described in an embodiment of this disclosure. Detailed Implementation

[0025] To better understand the above-mentioned objectives, features, and advantages of this disclosure, the solutions disclosed herein will be further described below. It should be noted that, unless otherwise specified, the embodiments and features described herein can be combined with each other.

[0026] Numerous specific details are set forth in the following description in order to provide a full understanding of this disclosure, but this disclosure may also be implemented in other ways different from those described herein; obviously, the embodiments in the specification are only some, and not all, of the embodiments of this disclosure.

[0027] Currently, cross-domain data synchronization suffers from low efficiency and serious resource waste.

[0028] To address the aforementioned issues, cross-domain solutions such as CORS and JSONP can be used to resolve permission problems in cross-domain communication, but they do not achieve efficient data synchronization and cache management. While client-side caching technologies (such as LocalStorage, SessionStorage, and IndexedDB) can store data, they have the following drawbacks:

[0029] Single-threaded blocking: Cache operations share the same thread as the main thread, which can easily cause page lag when processing large amounts of data;

[0030] Cross-domain isolation: Caches from different domains cannot be shared directly and must be relayed through the main thread, increasing communication overhead;

[0031] Lack of consistency: The lack of a cache synchronization mechanism in a distributed environment leads to asynchronous data updates in multi-window and multi-tab scenarios.

[0032] In this context, this disclosure considers that Web Worker technology allows scripts to execute in background threads, processing tasks in parallel with the main thread, thus providing a possible solution to the aforementioned single-threaded blocking problem. However, most Web Worker-based solutions are limited to computational acceleration within a single domain and have not developed distributed caching strategies for cross-domain scenarios, making it difficult to meet the cross-domain data synchronization needs of complex front-end applications.

[0033] For example, in some Web Worker-based single-domain caching optimization schemes, a Web Worker thread is typically created under a single domain to independently handle read and write operations of the local cache (such as IndexedDB); the main thread communicates with the Web Worker through MessageChannel to pass cache operation instructions (such as GET, SET, DELETE); and then the multi-threading feature of Web Worker is used to reduce the blocking of the main thread.

[0034] However, this solution is only applicable to single-domain scenarios and does not involve distributed synchronization of cross-domain data. It still cannot solve the problems of inconsistent caching and low efficiency of cross-domain communication under multiple domains.

[0035] Research and analysis revealed that the high synchronization cost caused by cross-domain cache isolation is due to the fact that Web Worker instances from different domains cannot communicate directly. Cross-domain data needs to be relayed through the main thread, forming an indirect communication link of "main thread-Worker A-main thread-Worker B", which increases latency and memory overhead.

[0036] The difficulty in maintaining cache consistency stems from the lack of a distributed coordination mechanism. Update operations on the same cross-domain data by multiple Web Worker instances may cause version conflicts (such as dirty reads and outdated data). Traditional single-threaded lock mechanisms cannot work effectively in a distributed environment.

[0037] The reason for low resource utilization is that single-domain Web Workers do not form a cluster collaboration. In complex cross-domain scenarios, Web Workers need to be created separately for each domain, resulting in wasted thread resources and unbalanced load.

[0038] Therefore, to address at least one of the problems of cache inconsistency and low efficiency in cross-domain data synchronization, embodiments of this disclosure provide a cross-domain data communication method, apparatus, device, and medium. The purpose of this solution is to: construct a distributed caching system in cross-domain scenarios to achieve collaborative work of multi-domain Web Worker clusters; design efficient cross-domain communication protocols and cache synchronization strategies to reduce data transfer overhead; and introduce a distributed consistency algorithm to ensure real-time synchronization and version security of cross-domain cached data. For ease of understanding, embodiments of this disclosure are described below.

[0039] Figure 1 This is a flowchart of a cross-domain data communication method provided in an embodiment of the present disclosure. The method can be executed by a cross-domain data communication device, which can be implemented in software and / or hardware, such as electronic devices and servers.

[0040] Reference Figure 1 The cross-domain data communication method provided in this embodiment may include the following steps.

[0041] S102, the target thread sends a first data request to the first worker in the distributed worker cluster; wherein, the first data request includes a first data identifier; the distributed worker cluster includes multiple workers with different domain names, and the first worker is any worker in the distributed worker cluster that receives the first data request.

[0042] Before the target thread sends the first data request to the first worker in the distributed worker cluster, this embodiment first provides a method for constructing a distributed worker cluster, referring to... Figure 2 The method may include:

[0043] The target thread creates a Worker (a Web Worker) for each domain and configures cross-domain communication for the Workers of each domain; the target thread registers the Workers for each domain; and the Workers establish a P2P connection through MessageChannel to form a distributed Worker cluster.

[0044] In some embodiments, the target thread can be the main thread or a Service Worker. This disclosure will be further described using the main thread as an example.

[0045] In a specific implementation, the main thread can create a Worker instance for each domain (such as new worker()) based on the Web Worker API (Application Programming Interface).

[0046] Web Worker is a JavaScript technology that allows code to run in a background thread, avoiding blocking the main thread and thus improving webpage performance and user experience. It provides multithreading capabilities for JavaScript, making it suitable for handling computationally intensive tasks or high-latency operations. Therefore, this embodiment involves multiple first Workers, each executing its own cross-domain data communication process. Thus, in the implementation of the cross-domain data communication method in this embodiment, Web Worker multithreading avoids main thread blocking, improves page frame rate stability, and effectively optimizes performance and resources.

[0047] The main thread creates a Worker for each domain, so that each domain corresponds to a Worker (such as worker-domainA.js, worker-domainB.js). The Worker is responsible for handling cache read and write and cross-domain communication for its own domain.

[0048] After the main thread creates a Worker for each domain, it injects cross-domain communication configuration into the Worker for each domain. This cross-domain communication configuration can include, for example, whitelist configuration and Worker construction parameters. Specifically, the whitelist configuration is done using the function "Access-Control-Allow-Origin:domainA,domainB...", which specifies the domains allowed for communication, including domains A and B. The Worker construction parameters are obtained using the function "ftype:'module',credentials:omit"}".

[0049] The main thread uses the `navigator.serviceWorker.register()` function to register global services for Workers on each domain. After successful registration, Workers can establish P2P (Peer-to-Peer lending) connections through MessageChannel, forming a distributed Worker cluster. This allows for persistent cross-domain connections between multiple Workers within the distributed cluster. MessageChannel can be extended based on the postMessage API.

[0050] The aforementioned P2P connection differs from the traditional client-server architecture. P2P connections allow direct interaction between endpoints without the need for a central node to forward data. Based on the postMessage extension, the cross-domain P2P communication mechanism enables direct data transmission between workers from different domains, realizing a cross-domain Web Worker communication protocol.

[0051] The above embodiments establish P2P connections between Workers through cross-domain MessageChannels, which avoids blocking the main thread, improves page response performance, and utilizes a standardized message protocol containing data version numbers to achieve distributed cache synchronization. Subsequent embodiments will describe the standardized message protocol and distributed caching in more detail.

[0052] In one embodiment, before the target thread sends the first data request to the first worker in the distributed worker cluster, the cross-domain data communication method may further include: constructing a distributed caching architecture that includes local caching and global indexes.

[0053] Local caching is used by each worker to maintain a private cache within its domain; a specific example is IndexedDB. IndexedDB is a browser-side data storage method, a key-value NoSQL database that is object-oriented and has a same-origin policy to ensure security.

[0054] The global index is used to store data description information for cross-domain data based on a Map structure. This data description information includes, but is not limited to: data identifier, domain name, data version number, and access permissions. The data identifier is a globally unique identifier for cross-domain data, such as a UUID or a composite ID including the domain name.

[0055] In global indexes, a Map is a data structure that stores key-value pairs. Its core features are the uniqueness of the keys and efficient lookup performance.

[0056] The distributed caching architecture in this embodiment adopts a hierarchical storage structure of local caching and global indexing, which can distribute cross-domain data across multiple workers, balancing the needs of data localization processing and global synchronization.

[0057] In one embodiment, cross-domain communication requires a predefined standardized communication protocol. Based on this, in this embodiment, the main thread sends a first data request to the first worker in the distributed worker cluster, which may include:

[0058] The target thread (such as the main thread) generates a first data request according to a predefined standardized communication protocol; the fields of the standardized communication protocol include: message type, data identifier, sender domain name, receiver domain name, payload, and data version number, etc.

[0059] In a distributed worker cluster, determine the first worker corresponding to the recipient domain name contained in the first data request; and send the first data request to the first worker.

[0060] Specifically, the standardized communication protocol mentioned above can be referenced in the following code:

[0061] {

[0062] "type":"SYNC"|"QUERY"|"UPDATE"|"DELETE",

[0063] "dataId":"data identifier",

[0064] "sourceDomain":"sender's domain",

[0065] "targetDomain":"recipient domain",

[0066] "data":"payload",

[0067] "version": "Data version number"

[0068] }

[0069] In the aforementioned standardized communication protocol, `type` describes the message type, where `SYNC` indicates data synchronization, `QUERY` indicates data query, `UPDATE` indicates data update, and `DELETE` indicates data deletion. `version` describes the data version number, which can be a semantic version number, a timestamp, or an incrementing counter.

[0070] The standardized communication protocol in this embodiment includes a control field "version" for the data version number, which enables distributed consistency verification.

[0071] S104, query the local first cache through the first worker to see if the first data identifier exists.

[0072] In this embodiment, after the main thread sends the first data request to the first worker in the distributed worker cluster, based on the aforementioned distributed caching architecture including local caching and global index, the first worker first performs a local cache query to check whether the first data identifier exists in the local first cache. If the first data identifier exists in the local first cache, the relevant data can be obtained directly from the first cache; if the first data identifier does not exist in the first cache, a cross-domain data communication process can be performed based on the global index.

[0073] For example, the first Worker is Worker A corresponding to domain A. Worker A receives the first data request from the main thread. This first data request is a cross-domain request, such as a cross-domain data request to retrieve user information from domain B. Based on the standardized communication protocol used by the first data request, it is known that the first data request carries a data identifier field "dataId". The first data identifier is determined based on the specific value of this field. Therefore, Worker A first checks whether the first data identifier exists in its local first cache, and then executes subsequent steps S106 or S108 based on the query result.

[0074] S106, if it exists, return the first data corresponding to the first data identifier in the first cache to the target thread.

[0075] If Worker A finds a first data identifier in its local first cache, it can directly retrieve the first data uniquely identified by that first data identifier from the first cache. Then, it determines whether the activation time of the first data's data version number is newer than or equal to the activation time of the data version number carried in the first data request. If it is newer than or equal to, it means that the first data in Worker A's local first cache is relatively new and has not expired, and the first data is returned to the main thread. Conversely, if it is not newer than, it means that the first data in Worker A's local first cache has expired. In this case, the subsequent step S108 is executed, performing a cross-domain data communication process based on the global index.

[0076] In this embodiment, with the support of the local first cache, the first worker can efficiently return the first data corresponding to the first data identifier in the first cache to the target thread.

[0077] S108, if it does not exist, then determine the second Worker that has the first data cached based on the global index. Here, the first data is the data corresponding to the first data identifier.

[0078] If Worker A's local cache does not contain the first data identifier, then a cross-domain data communication process is initiated based on the global index. In this embodiment, the second Worker with the first data cached is first determined based on the global index.

[0079] The second Worker, which is determined to have the first data cached based on the global index, may include:

[0080] The first worker queries the global index to find the target domain name to which the first data identifier belongs; wherein the global index includes at least the data identifier and the domain name to which it belongs, stored based on a Map structure; the worker corresponding to the target domain name in the distributed worker cluster is determined as the second worker that caches the first data.

[0081] Specifically, the global index stores the following data description information for cross-domain data based on a Map structure: data identifier, domain name, data version number, and access permissions. In this case, Worker A determines the target domain name to which the first data identifier belongs based on the data identifier and domain name stored in the global index using the Map structure.

[0082] Additionally, if no record for the domain name to which the first data identifier belongs is found in the global index, the target domain name can be obtained through DNS pre-configuration. For example, the mapping relationship between domain names and corresponding IP addresses or Worker instances can be pre-configured in the system or application configuration file; when there is no record in the global index, the first Worker can query the above configuration file to find the target domain name that has a mapping relationship with the first Worker.

[0083] Once the target domain name is determined, the second worker corresponding to the target domain name can be determined in the distributed worker cluster.

[0084] S110, query the response data corresponding to the first data identifier from the second worker across domains through the first worker; wherein, the response data includes: the first data corresponding to the first data identifier.

[0085] In this embodiment, after determining the second worker in the cross-domain data communication process based on the global index, the response data corresponding to the first data identifier can be queried from the second worker across domains through the first worker, as described in the following specific embodiment.

[0086] This embodiment includes: a first worker sending a second data request containing a first data identifier to a second worker through a cross-domain communication channel; receiving response data returned by the second worker in response to the second data request; it can be understood that, referring to the first data request, the second data request also includes the first data identifier.

[0087] For example, the first Worker is Worker A corresponding to domain A, and the second Worker is Worker B corresponding to domain B. Worker A sends a second data request to Worker B through a cross-domain MessageChannel. The second data request carries the first data identifier and the latest version number of the first data. MessageChannel is a mechanism in JavaScript used for communication between different execution contexts (such as different Web Workers or different scripts on the same page).

[0088] After receiving the second data request, Worker B queries the first data corresponding to the first data identifier in its local first cache according to the first data identifier included in the second data request, and returns response data to Worker A. The response data may include the first data and the latest version number of the first data.

[0089] In the above embodiments, based on a distributed caching architecture including a global index, the first worker queries the response data corresponding to the first data identifier from the second worker across domains. Data synchronization can be completed directly through P2P communication between workers, eliminating the main thread relay link in the prior art. This reduces duplicate data transmission, lowers network traffic consumption, reduces communication latency, and improves cross-domain data synchronization efficiency.

[0090] S112, the first data is returned to the target thread through the first worker.

[0091] In this embodiment, after receiving the response data, Worker A returns the first data in the response data to the main thread.

[0092] Regarding the first data version number also included in the response data, this embodiment may further include:

[0093] Update the first data and the first data version number corresponding to the first data identifier in the first cache of the first worker; update the first data version number corresponding to the first data identifier in the global index.

[0094] This embodiment is based on a distributed caching architecture of local caching and global index. When updating data based on data version number, it can realize synchronous updates of cross-domain data in local cache and global index, and better maintain the consistency of cross-domain data.

[0095] Reference Figure 3 The cross-domain data communication method provided in this embodiment may also include a cross-domain data update process, as described below:

[0096] When a third worker in the distributed worker cluster updates the second data and its version number in its local third cache, a fourth worker in the distributed worker cluster that subscribes to the second data identifier is identified; where the second data identifier is the identifier of the second data; an update event is broadcast to the fourth worker; where the update event is used to notify the fourth worker to update the data; after receiving the update event, the fourth worker determines whether to update the second data and its version number based on the second data version number and the current data version number in its local fourth cache. The aforementioned third worker can be any worker in the distributed worker cluster that has undergone a data update.

[0097] In this embodiment, the fourth worker determines whether to update the second data and the second data version number based on the second data version number and the current data version number in its local fourth cache. This determination may include:

[0098] After receiving the update event through the fourth worker, determine the current data version number corresponding to the second data identifier in the local fourth cache;

[0099] The fourth worker compares the activation time of the second data version number and the current data version number;

[0100] If the activation time of the second data version number is newer than or equal to the activation time of the current data version number, then update the second data and the second data version number in the local cache of the fourth worker, and send a data update notification to the main thread.

[0101] If the activation time of the second data version number is not newer than the activation time of the current data version number, the update event is ignored.

[0102] Specifically, refer to Figure 3 The third worker updates the second data corresponding to the second data identifier in its local third cache, generating a new data version number for the second data. The third worker then subscribes to the fourth worker in the distributed worker cluster for the broadcast update event of the second data identifier. The fourth worker can be one or more workers in the distributed worker cluster, such as Worker A and Worker C.

[0103] After receiving the update event, the fourth worker compares the updated second data version number with the current data version number in the fourth worker's local fourth cache based on the activation time.

[0104] If the activation time of the second data version number is newer than or equal to the activation time of the current data version number (i.e., the second data version number ≥ the current data version number), it indicates that the data corresponding to the second data identifier in the fourth cache of the fourth worker has expired and needs to be updated synchronously according to the data updated by the third worker. In this case, the fourth worker updates the second data and its second data version number in its fourth cache, and sends a data update notification to the target thread to inform the target thread that the data update has been completed.

[0105] If the activation time of the second data version number is not newer than the activation time of the current data version number (i.e., the second data version number < the current data version number), it means that the data corresponding to the second data identifier in the fourth cache of the fourth worker is relatively new, and the data updated by the third worker is relatively old and does not need to be updated to avoid outdated updates; in this case, the fourth worker ignores the update event.

[0106] The above embodiments update data based on the comparison of data version numbers, which can effectively solve the conflict of concurrent updates of cross-domain data, ensure the orderliness of data updates, avoid dirty reads and outdated data updates, and achieve consistent maintenance of cross-domain data.

[0107] Furthermore, it can be seen that in the process of updating cross-domain data, the synchronization of front-end cached data can be achieved without relying on back-end interfaces, thus reducing the coupling with back-end services.

[0108] It is understandable that Web Workers provide multithreading capabilities for JavaScript, making them suitable for handling computationally intensive tasks or high-latency operations. Based on this, in a distributed Worker cluster, there can be multiple third-party Workers involved in cross-domain data updates, each executing its own cross-domain data synchronization update process. Therefore, in this embodiment, the multithreaded processing of Web Workers avoids main thread blocking, improves page frame rate stability, and effectively optimizes performance and resources.

[0109] In the above embodiments, the descriptions are all based on the main thread as the target thread. In other embodiments, the main thread can be replaced by a Service Worker, that is, the target thread is a Service Worker, and the cross-domain data communication methods described in the above embodiments are executed through the Service Worker.

[0110] A Service Worker is a separate thread that runs behind the browser, allowing developers to intercept and process network requests to implement features such as cache management, offline support, and push notifications. It is registered using the `navigator.serviceWorker.register` method and can intercept and process network requests via the `fetch` event.

[0111] When using Service Worker as a global proxy, Service Worker can intercept cross-domain requests and manage the cache uniformly. However, Service Worker runs in the browser background, which limits its multi-threaded collaboration with Web Worker, and it is difficult to achieve fine-grained domain-level cache sharding. It is suitable for simple cross-domain scenarios, but not for complex distributed environments.

[0112] Based on this, users can flexibly choose the main thread or Service Worker as the target thread according to the actual application scenario.

[0113] In summary, the cross-domain data communication method provided in this disclosure includes: a target thread sending a first data request to a first worker in a distributed worker cluster; wherein the first data request includes a first data identifier; the distributed worker cluster includes multiple workers with different domain names; querying the first worker's local first cache to see if the first data identifier exists; if it exists, returning the first data corresponding to the first data identifier in the local cache to the target thread; if it does not exist, determining the second worker that caches the first data based on a global index; querying the second worker for response data corresponding to the first data identifier across domains through the first worker; wherein the response data includes the first data; and returning the first data to the target thread through the first worker.

[0114] This technical solution constructs a distributed worker cluster for cross-domain scenarios and a distributed caching architecture including local caching and global indexes. Based on this, collaborative work among workers from multiple domains can be achieved. After the first worker receives the first data request, with the support of local caching, it can efficiently return the first data corresponding to the first data identifier in the local cache to the target thread. If the relevant data is not found in the local cache, then based on the first data identifier, workers from different domains, and the global index, the first worker can query the response data corresponding to the first data identifier from a second worker with a different domain. That is, cross-domain data communication is directly performed between workers with different domains, without data transfer links or overhead, thus enabling efficient cross-domain data communication, reducing network traffic consumption and communication latency, and improving the efficiency of cross-domain data communication.

[0115] Figure 4 This is a schematic diagram of a cross-domain data communication device provided in an embodiment of the present disclosure. This device can be used to implement the aforementioned cross-domain data communication method. The device can be implemented using software and / or hardware, specifically electronic devices and servers. (Refer to...) Figure 4 The cross-domain data communication device provided in this embodiment may include the following modules.

[0116] The request sending module 210 is used to send a first data request to the first worker in the distributed worker cluster from the target thread; wherein the first data request includes a first data identifier; the distributed worker cluster includes multiple workers with different domain names;

[0117] The local query module 220 is used to query whether the first data identifier exists in the local first cache through the first Worker;

[0118] The cross-domain Worker determination module 230 is used to determine, in the absence of a Worker, a second Worker that has cached the first data based on a global index; wherein, the first data is the data corresponding to the first data identifier;

[0119] The cross-domain query module 240 is used to query the response data corresponding to the first data identifier from the second worker through the first worker; wherein, the response data includes: the first data;

[0120] The second data return module 250 is used to return the first data to the target thread through the first Worker.

[0121] The device provided in this embodiment has the same implementation principle and technical effect as the aforementioned method embodiment. For the sake of brevity, any parts not mentioned in the device embodiment can be referred to the corresponding content in the aforementioned method embodiment.

[0122] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this disclosure. Figure 5 As shown, the electronic device 300 includes one or more processors 301 and memory 302.

[0123] The processor 301 may be a central processing unit (CPU) or other form of processing unit with data processing and / or instruction execution capabilities, and may control other components in the electronic device 300 to perform desired functions.

[0124] The memory 302 may include one or more computer program products, which may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. The volatile memory may include, for example, random access memory (RAM) and / or cache memory. The non-volatile memory may include, for example, read-only memory (ROM), hard disk, flash memory, etc. One or more computer program instructions may be stored on the computer-readable storage medium, and the processor 301 may execute the program instructions to implement the cross-domain data communication method of the embodiments of this disclosure described above and / or other desired functions. Various contents such as input signals, signal components, and noise components may also be stored in the computer-readable storage medium.

[0125] In one example, the electronic device 300 may also include an input device 303 and an output device 304, which are interconnected via a bus system and / or other forms of connection mechanism (not shown).

[0126] In addition, the input device 303 may also include, for example, a keyboard, a mouse, etc.

[0127] The output device 304 can output various information to the outside, including determined distance information, direction information, etc. The output device 304 may include, for example, a display, a speaker, a printer, and a communication network and its connected remote output devices, etc.

[0128] Of course, for the sake of simplicity, Figure 5 Only some of the components of the electronic device 300 relevant to this disclosure are shown, omitting components such as buses, input / output interfaces, etc. In addition, the electronic device 300 may include any other suitable components depending on the specific application.

[0129] Furthermore, this embodiment also provides a computer-readable storage medium storing a computer program for executing the above-described cross-domain data communication method.

[0130] The present disclosure provides a computer program product for a cross-domain data communication method, apparatus, electronic device, and medium, including a computer-readable storage medium storing program code. The instructions included in the program code can be used to execute the methods described in the preceding method embodiments. For specific implementation details, please refer to the method embodiments, which will not be repeated here.

[0131] It should be noted that, in this document, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0132] The above description is merely a specific embodiment of this disclosure, enabling those skilled in the art to understand or implement it. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this disclosure. Therefore, this disclosure is not to be limited to the embodiments described herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A cross-domain data communication method, characterized in that, The method includes: The target thread sends a first data request to the first worker in the distributed worker cluster; wherein the first data request includes a first data identifier; the distributed worker cluster includes multiple workers with different domain names; The first worker queries the local first cache to check if the first data identifier exists; If it does not exist, the second Worker with the first data cached is determined based on the global index; wherein, the first data is the data corresponding to the first data identifier; The response data corresponding to the first data identifier is queried across domains from the second worker through the first worker; wherein, the response data includes: the first data; The first data is returned to the target thread through the first worker.

2. The method according to claim 1, characterized in that, The step of determining the second Worker that caches the first data based on a global index includes: The first worker queries the global index to find the target domain name to which the first data identifier belongs; wherein, the global index includes at least the data identifier and the domain name to which it belongs, stored based on a Map structure; The Worker corresponding to the target domain name in the distributed Worker cluster is identified as the second Worker that caches the first data.

3. The method according to claim 1, characterized in that, The step of querying the response data corresponding to the first data identifier across domains from the second worker through the first worker includes: The first worker sends a second data request containing the first data identifier to the second worker through a cross-domain communication channel; Receive the response data returned by the second Worker in response to the second data request.

4. The method according to claim 1, characterized in that, The response data further includes: a first data version number; after querying the response data corresponding to the first data identifier across domains from the second Worker through the first Worker, the method further includes: Update the first data corresponding to the first data identifier and the first data version number in the first cache of the first worker; Update the first data version number corresponding to the first data identifier in the global index.

5. The method according to claim 1, characterized in that, The method further includes: When the third worker in the distributed worker cluster updates the second data and its version number in its local third cache, the fourth worker in the distributed worker cluster that subscribes to the second data identifier is determined; wherein, the second data identifier is the identifier of the second data. An update event is broadcast to the fourth Worker; wherein the update event is used to notify the fourth Worker to update the data; After receiving the update event through the fourth worker, it determines whether to update the second data and the second data version number based on the second data version number and the current data version number in the local fourth cache.

6. The method according to claim 5, characterized in that, After receiving the update event through the fourth Worker, the step of determining whether to update the second data and the second data version number based on the second data version number and the current data version number in the local fourth cache includes: After receiving the update event through the fourth worker, the current data version number corresponding to the second data identifier in the local fourth cache is determined; Compare the activation time of the second data version number and the current data version number; If the activation time of the second data version number is newer than or equal to the activation time of the current data version number, then the second data and the second data version number are updated in the fourth cache of the fourth worker, and a data update notification is sent to the target thread; If the activation time of the second data version number is not newer than the activation time of the current data version number, then the update event is ignored.

7. The method according to claim 1, characterized in that, Before the target thread sends the first data request to the first worker in the distributed worker cluster, the method further includes: The target thread creates a Worker for each domain and configures cross-domain communication for the Workers in each domain. Register the Worker for each domain name through the target thread; Each Worker establishes a peer-to-peer (P2P) connection through a MessageChannel to form the distributed Worker cluster.

8. The method according to claim 1, characterized in that, Before the target thread sends the first data request to the first worker in the distributed worker cluster, the method further includes: Build a distributed caching architecture that includes local caching and global indexes; The local cache is used for the private cache within the domain name maintained by each Worker; The global index is used to store data description information for cross-domain data based on a Map structure. The data description information includes: data identifier, domain name, data version number, and access permissions.

9. The method according to claim 1, characterized in that, The target thread sends a first data request to the first worker in the distributed worker cluster, including: The target thread generates a first data request according to a predefined standardized communication protocol; wherein, the fields of the standardized communication protocol include: message type, data identifier, sender domain name, receiver domain name, payload, and data version number; In the distributed Worker cluster, the first Worker corresponding to the recipient domain name included in the first data request is determined; Send the first data request to the first Worker.

10. The method according to claim 1, characterized in that, After querying the local first cache through the first Worker to see if the first data identifier exists, the method further includes: If the first data identifier exists in the first cache through the first worker query, then the first data corresponding to the first data identifier in the first cache is returned to the target thread.

11. An electronic device, characterized in that, The electronic device includes: processor; Memory used to store the processor's executable instructions; The processor is configured to read the executable instructions from the memory and execute the instructions to implement the method described in any one of claims 1-10.

12. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores instructions that, when executed on a terminal device, cause the terminal device to perform the method as described in any one of claims 1-10.

Citation Information

Patent Citations

  • Distributed type searching method of cross-domain semantic Web service

    CN101873335A

  • Cross-domain communication method and device of web application, storage medium and terminal equipment

    CN116866329A