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

By building a cache architecture of distributed Worker clusters and global indexes, the efficiency and consistency of cross-domain data communication is achieved, the problem of low cross-domain data synchronization efficiency is solved, and network traffic and latency is reduced.

CN120583103AActive Publication Date: 2025-09-02ZHONGDIAN DATA IND CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

Cross-domain data synchronization has low efficiency and serious resource waste. The existing cross-domain communication solutions have failed to effectively solve the problems of cache inconsistency and low cross-domain communication efficiency.

Method used

Build a distributed Worker cluster in cross-domain scenarios, adopt a distributed cache architecture with local cache and global index, realize P2P connection between Workers through cross-domain MessageChannel, and use standardized communication protocols and data version numbers to ensure data consistency, so as to realize the collaborative work of multi-domain Workers.

Benefits of technology

It realizes the efficiency of cross-domain data communication, reduces network traffic consumption and communication delay, improves cross-domain data synchronization efficiency, avoids data transit links, and ensures data consistency and version security.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120583103A_ABST
    Figure CN120583103A_ABST
Patent Text Reader

Abstract

The invention relates to a cross-domain data communication method and device, equipment and a medium. The method comprises the steps that a target thread sends a first data request to a first Worker in a distributed Worker cluster; wherein the first data request comprises a first data identifier; the distributed Worker cluster comprises a plurality of Workers with different domain names; querying whether a first data identifier exists in a local first cache or not through a first Worker; if not, determining a second Worker in which the first data is cached based on the global index; wherein the first data is data corresponding to the first data identifier; querying response data corresponding to the first data identifier from a second Worker in a cross-domain manner through the first Worker; wherein the response data comprises first data; and returning the first data to the target thread through the first Worker. According to the invention, the cross-domain data communication efficiency and the cache consistency of data synchronization can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

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

[0002] In modern web development, cross-domain data synchronization is a core challenge for front-end applications. With the prevalence of microservice architectures and distributed systems, front-end applications often need to interact with back-end services (such as user centers, payment systems, and recommendation engines) hosted on multiple domains. However, the browser's same-origin policy restricts direct cross-domain data sharing, resulting in inefficient data synchronization and significant resource waste. Summary of the Invention

[0003] In order to solve the above technical problems, the present disclosure provides a cross-domain data communication method, apparatus, device and medium.

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

[0005] The 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; and the distributed worker cluster includes a plurality of workers with different domain names;

[0006] querying, through the first Worker, whether the first data identifier exists in the local first cache;

[0007] If not, determining a second Worker that has cached the first data based on the global index; wherein the first data is data corresponding to the first data identifier;

[0008] Cross-domain querying, through the first Worker, from the second Worker for response data corresponding to the first data identifier; 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 the present disclosure, an electronic device is provided, comprising:

[0011] processor;

[0012] a memory for storing instructions executable by the processor;

[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 the present disclosure, a computer-readable storage medium is provided, wherein the storage medium stores a computer program, and the computer program is used to execute the above method.

[0015] The technical solution provided by the embodiments of the present disclosure has the following advantages over the prior art:

[0016] The technical solution provided by the embodiment of the present disclosure includes: 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 multiple workers with different domain names; querying whether the first data identifier exists in a local first cache through the first worker; if not, determining a second worker that has cached the first data based on a global index; wherein the first data is data corresponding to the first data identifier; cross-domain querying response data corresponding to the first data identifier from the second worker 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 in a cross-domain scenario and a distributed cache architecture including local cache and global index, based on which the collaborative work of multi-domain workers can be realized; after the first Worker receives the first data request, if the local first cache does not have relevant data, then based on the first data identifier, workers with different domain names and global index, the first Worker can cross-domain query the response data corresponding to the first data identifier from the second Worker with a different domain name, that is, cross-domain data communication is directly carried out between workers with different domain names, without data transfer links and data transfer overhead, so that cross-domain data communication can be carried out efficiently, network traffic consumption and communication delay are reduced, and the efficiency of cross-domain data communication is improved. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0019] In order to more clearly illustrate the embodiments of the present disclosure or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0020] Figure 1 This is a flow chart of the cross-domain data communication method according to an embodiment of the present disclosure;

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

[0022] Figure 3 This is a flowchart of the cross-domain data synchronization method according to an embodiment of the present disclosure;

[0023] Figure 4 This is a schematic diagram of the structure of the cross-domain data communication device according to an embodiment of the present disclosure;

[0024] Figure 5 This is a schematic diagram of the structure of the electronic device described in an embodiment of the present disclosure. DETAILED DESCRIPTION

[0025] In order to more clearly understand the above-mentioned objectives, features and advantages of the present disclosure, the scheme of the present disclosure will be further described below. It should be noted that the embodiments of the present disclosure and the features therein can be combined with each other in the absence of conflict.

[0026] In the following description, many specific details are set forth to facilitate a full understanding of the present disclosure, but the present disclosure may also be implemented in other ways different from those described herein; it is obvious that the embodiments in the specification are only part of the embodiments of the present disclosure, rather than all of the embodiments.

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

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

[0029] Single-thread blocking: Cache operations share the same thread as the main thread, and large-scale data processing can easily cause page lag.

[0030] Cross-domain isolation: Caches on different domain names cannot be shared directly and must be transferred through the main thread, increasing communication overhead.

[0031] Lack of consistency: There is a lack of cache synchronization mechanism in a distributed environment, and data updates are not synchronized in multi-window and multi-tab scenarios.

[0032] In this context, the present disclosure considers Web Worker technology, which allows scripts to be executed in background threads, processing tasks in parallel with the main thread, providing a potential solution to the aforementioned single-thread blocking problem. However, Web Worker-based solutions are mostly limited to computing acceleration within a single domain name, lacking a distributed caching strategy for cross-domain scenarios, making it difficult to meet the cross-domain data synchronization requirements of complex front-end applications.

[0033] For example, in some single-domain cache optimization solutions based on Web Workers, a WebWorker thread is generally 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 the MessageChannel to pass cache operation instructions (such as GET, SET, DELETE); and then the multi-threaded features of the Web Worker are used to reduce main thread blocking.

[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 cache inconsistency and low cross-domain communication efficiency under multiple domain names.

[0035] After research and analysis, we found that the reason why cross-domain cache isolation leads to high synchronization costs is that Web Worker instances with different domain names cannot communicate directly. Cross-domain data needs to be transferred 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 is due to 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), and traditional single-threaded locking mechanisms cannot work effectively in a distributed environment.

[0037] The reason for low resource utilization is that single-domain Web Workers do not form cluster collaboration. In complex cross-domain scenarios, a separate Web Worker must be created for each domain, resulting in thread resource waste and load imbalance.

[0038] Therefore, in order to address at least one of the problems of cache inconsistency and low cross-domain communication efficiency in cross-domain data synchronization, the embodiments of the present disclosure provide a cross-domain data communication method, apparatus, device, and medium. The purpose of this solution is to: build a distributed cache system in a cross-domain scenario to achieve collaborative work of multi-domain Web Worker clusters; design an efficient cross-domain communication protocol and cache synchronization strategy to reduce data transfer overhead; introduce a distributed consistency algorithm to ensure real-time synchronization and version security of cross-domain cache data. For ease of understanding, the embodiments of the present disclosure are described in detail 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 using software and / or hardware, such as an electronic device and a server.

[0040] Reference Figure 1 , a 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 a 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] A Worker (a Web Worker) is created for each domain name through the target thread, and cross-domain communication is configured for the Workers of each domain name. The Workers of each domain name are registered through the target thread. Each Worker establishes a P2P connection through the MessageChannel to form a distributed Worker cluster.

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

[0045] In a specific embodiment, the main thread may create a Worker instance (specifically, new worker()) for each domain name based on the Web Worker API (Application Programming Interface).

[0046] Among them, Web Worker is a JavaScript technology that allows code to run in a background thread to avoid blocking the main thread, thereby improving web page performance and user experience. It provides multi-threading capabilities for JavaScript, which is suitable for processing computationally intensive tasks or high-latency operations. Based on this, the first Worker involved in this embodiment can be multiple, and each first Worker executes its own cross-domain data communication process. Therefore, in the implementation process of the cross-domain data communication method of this embodiment, Web Worker multi-threading processing can avoid blocking the main thread, improve the stability of the page frame rate, and better achieve performance and resource optimization.

[0047] A Worker is created for each domain name through the main thread, so that each domain name corresponds to a Worker (such as worker-domainA.js, worker-domainB.js). The Worker is responsible for handling cache reading and writing and cross-domain communication for this domain name.

[0048] After the main thread creates a Worker for each domain, it injects cross-domain communication configuration into each domain's Worker. This configuration may include whitelist configuration and Worker construction parameters. The whitelist configuration is implemented using the "Access-Control-Allow-Origin:domainA,domainB..." function, indicating that the whitelist of domains allowed to communicate includes domainA and domainB. The Worker construction parameters are implemented using the "ftype:'module',credentials:omit"}" function.

[0049] The main thread uses the navigator.serviceWorker.register() function to register the global service for each domain's Worker. After successful Worker registration, each Worker can establish a peer-to-peer (P2P) lending connection through a MessageChannel, forming a distributed Worker cluster. This allows for persistent connections across domains to be established through multiple Workers within the distributed Worker cluster. The MessageChannel can be extended based on the postMessage API.

[0050] This P2P connection differs from traditional client-server architectures in that it allows endpoints to interact directly, eliminating the need for central nodes to forward data. The cross-domain P2P communication mechanism, based on the postMessage extension, enables direct data transfer between Workers in different domains, implementing a cross-domain Web Worker communication protocol.

[0051] The above embodiment establishes a P2P connection between workers through a cross-domain MessageChannel, which can avoid blocking the main thread, improve page responsiveness, and achieve distributed cache synchronization using a standardized message protocol that includes data version numbers. Subsequent embodiments will further describe the standardized message protocol and distributed cache.

[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: building a distributed cache architecture including a local cache and a global index.

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

[0054] Global indexes are used to store cross-domain data description information based on a map structure. This information includes, but is not limited to, the 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 with a domain name.

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

[0056] The distributed cache architecture in this embodiment adopts a hierarchical storage structure of local cache and global index, which can store cross-domain data in multiple workers in a dispersed manner, balancing the needs of data localization processing and global synchronization.

[0057] In one embodiment, cross-domain communication requires pre-defined standardized communication protocols. 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 (e.g., the main 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, payload, and data version number;

[0059] In the distributed Worker cluster, a first Worker corresponding to the recipient domain name included in the first data request is determined; and the first data request is sent to the first Worker.

[0060] Specifically, the above standardized communication protocol can refer to the following code:

[0061] {

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

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

[0064] "sourceDomain": "Sender's domain name",

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

[0066] "data":"payload",

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

[0068] }

[0069] In the above standardized communication protocols, type is used to describe the message type. SYNC indicates data synchronization, QUERY indicates data query, UPDATE indicates data update, and DELETE indicates data deletion. Version is used to describe the data version number. Specifically, the data version number can be generated using a semantic data version number, a timestamp, or an incremental counter.

[0070] The standardized communication protocol in this embodiment includes a control field "version" of the data version number, and the data version number field can support distributed consistency verification.

[0071] S104: Query, through the first Worker, whether the local first cache contains the first data identifier.

[0072] In this embodiment, after the main thread sends a first data request to the first worker in the distributed worker cluster, based on the aforementioned distributed cache architecture including local cache 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 directly obtained from the first cache; if the first data identifier does not exist in the first cache, a cross-domain data communication process can be carried out based on the global index.

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

[0074] S106: If so, return the first data corresponding to the first data identifier in the first cache to the target thread.

[0075] If Worker A queries the first local cache for a first data identifier, the first data uniquely identified by the first data identifier can be directly obtained from the first cache. Then, it is determined whether the activation time of the data version number of the first data 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 the local first cache queried by Worker A is relatively new and has not expired, and then the first data is returned to the main thread. On the contrary, if it is not newer than, it means that the first data in the local first cache queried by Worker A has expired. In this case, the subsequent step S108 is executed to perform 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 not, determine a second Worker that has cached the first data based on the global index, where the first data is data corresponding to the first data identifier.

[0078] If Worker A queries the local first cache and finds that the first data identifier does not exist, a cross-domain data communication process is performed based on the global index. In this embodiment, a second Worker that has the first data cached is first determined based on the global index.

[0079] Determining the second Worker that caches the first data based on the global index may include:

[0080] A first Worker is used to query a global index for a target domain name to which a first data identifier belongs; wherein the global index includes at least: a data identifier and a domain name stored based on a Map structure; and a Worker corresponding to the target domain name in a distributed Worker cluster is determined to be a second Worker that has cached the first data.

[0081] Specifically, the global index uses a Map structure to store the following data description information for cross-domain data: 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 Map structure in the global index.

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

[0083] After 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 , cross-domain querying response data corresponding to the first data identifier from the second worker through the first worker; wherein the response data includes: first data corresponding to the first data identifier.

[0085] In this embodiment, in the cross-domain data communication process based on the global index, after the second Worker is determined, the following specific embodiments can be referred to to query the response data corresponding to the first data identifier from the second Worker through the first Worker across domains.

[0086] This embodiment includes: a first worker sends a second data request including a first data identifier to a second worker through a cross-domain communication channel; and receives response data returned by the second worker in response to the second data request. It can be understood that, with reference 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 via 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 used in JavaScript to communicate 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 searches the local first cache for the first data corresponding to the first data identifier 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 current latest version number of the first data.

[0089] In the above embodiment, based on the distributed cache architecture including a global index, the first Worker queries the response data corresponding to the first data identifier from the second Worker across domains, and can directly complete data synchronization through P2P communication between Workers, eliminating the main thread transfer link in the existing technology, reducing repeated data transmission, reducing network traffic consumption, reducing communication delays, and improving cross-domain data synchronization efficiency.

[0090] S112: Return the first data 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] The first data and the first data version number corresponding to the first data identifier are updated in the first cache of the first Worker; and the first data version number corresponding to the first data identifier is updated in the global index.

[0094] This embodiment is based on a distributed cache architecture of local cache and global index. When data is updated based on the data version number, it can achieve synchronous update of cross-domain data in the 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, referring to the following content:

[0096] When a third worker in a distributed worker cluster updates the second data and its second data version number in a local third cache, a fourth worker in the distributed worker cluster that subscribes to the second data identifier is determined; wherein the second data identifier is an 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, the 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 the local fourth cache. The third worker is any worker in the distributed worker cluster that has data updated.

[0097] In this embodiment, the fourth worker may determine 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, including:

[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 updating the second data and the second data version number in the local cache of the fourth Worker, and sending 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 the local third cache and generates a new data version number for the second data, which is the second data version number. The third worker broadcasts the update event to the fourth worker in the distributed worker cluster that subscribes to 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 activation time of the updated second data version number and the current data version number in the local fourth cache of the fourth Worker.

[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 means that the data corresponding to the second data identifier in the fourth cache of the fourth worker has expired and needs to be synchronized with the data updated by the third worker. In this case, the second data and its 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 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 local to the fourth Worker is relatively updated, and the data updated by the third Worker is relatively old, and no data update is required to avoid outdated updates; in this case, the fourth Worker ignores the update event.

[0106] The above embodiment updates data based on the comparison of data version numbers, which can better resolve conflicts in concurrent cross-domain data updates, ensure the orderliness of data updates, avoid dirty reads and outdated data updates, and achieve consistency maintenance of cross-domain data.

[0107] In addition, it can be seen that in the above process of updating cross-domain data, the synchronization of front-end cache data can be achieved without relying on the back-end interface, which reduces the coupling with the back-end service.

[0108] It can be understood that Web Workers can provide multithreading capabilities for JavaScript, suitable for processing computationally intensive tasks or high-latency operations. Based on this, in a distributed Worker cluster, there can be multiple third workers involved in cross-domain data updates, each of which executes its own cross-domain data synchronization update process. Therefore, in this embodiment, Web Worker multithreading can avoid main thread blocking, improve page frame rate stability, and effectively achieve performance and resource optimization.

[0109] In the above embodiments, the main thread is used as the target thread for the relevant description. 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 method described in the above embodiments is executed by the Service Worker.

[0110] A Service Worker is an independent thread running behind the browser that allows developers to intercept and handle network requests, enabling features such as cache management, offline support, and push notifications. It is registered through the navigator.serviceWorker.register method and can intercept and handle network requests through the fetch event.

[0111] When attempting to use Service Workers as a global proxy, Service Workers can intercept cross-origin requests and centralize cache management. However, Service Workers run in the browser's backend, limiting their multi-threaded collaboration with Web Workers and making it difficult to implement fine-grained domain-level cache sharding. This makes them suitable for simple cross-origin scenarios but unsuitable 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 by the embodiment of the present disclosure includes: 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 multiple workers with different domain names; querying whether the first data identifier exists in the local first cache through the first worker; if so, returning the first data corresponding to the first data identifier in the local cache to the target thread; if not, determining the second worker that has cached the first data based on the global index; cross-domain querying 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; returning the first data to the target thread through the first worker.

[0114] This technical solution constructs a distributed Worker cluster in a cross-domain scenario and a distributed cache architecture including local cache and global index, based on which the collaborative work of multi-domain name Workers can be realized; after the first Worker receives the first data request, with the support of the local cache, it can efficiently return the first data corresponding to the first data identifier in the local cache to the target thread. If there is no relevant data in the local cache, then based on the first data identifier, Workers with different domain names and the global index, the first Worker can cross-domain query the response data corresponding to the first data identifier from the second Worker with a different domain name, that is, cross-domain data communication is directly carried out between Workers with different domain names, without data transfer links and data transfer overhead, so that cross-domain data communication can be carried out efficiently, network traffic consumption and communication delays can be reduced, and the efficiency of cross-domain data communication can be improved.

[0115] Figure 4 This is a schematic diagram of the structure of a cross-domain data communication device provided by an embodiment of the present disclosure. The device can be used to implement the above-mentioned cross-domain data communication method. The device can be implemented using software and / or hardware, such as an electronic device and a server. Figure 4 , a cross-domain data communication device provided in this embodiment may include the following modules.

[0116] The request sending module 210 is configured to send a first data request by a target thread to a first worker in a distributed worker cluster; wherein the first data request includes a first data identifier; and the distributed worker cluster includes a plurality of workers with different domain names.

[0117] A local query module 220, configured to query, through the first Worker, whether the first data identifier exists in the local first cache;

[0118] A cross-domain worker determination module 230 is configured to determine, if a second worker does not exist, a second worker that has cached the first data based on a global index; wherein the first data is data corresponding to the first data identifier;

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

[0120] The second data returning module 250 is configured 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 effects as those of the aforementioned method embodiment. For the sake of brief description, for matters not mentioned in the device embodiment, reference may be made to the corresponding contents in the aforementioned method embodiment.

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

[0123] The processor 301 may be a central processing unit (CPU) or other forms of processing units having data processing capabilities 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, and the computer program product may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. The volatile memory may, for example, include random access memory (RAM) and / or cache memory (cache), etc. The non-volatile memory may, for example, include read-only memory (ROM), a hard disk, a flash memory, etc. One or more computer program instructions may be stored on the computer-readable storage medium, and the processor 301 may run the program instructions to implement the cross-domain data communication method of the embodiment of the present disclosure described above and / or other desired functions. Various contents such as input signals, signal components, noise components, etc. may also be stored in the computer-readable storage medium.

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

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

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

[0128] Of course, to simplify, Figure 5 Only some of the components related to the present disclosure in the electronic device 300 are shown, and components such as a bus, an input / output interface, etc. are omitted. In addition, the electronic device 300 may further include any other appropriate components according to specific application scenarios.

[0129] Furthermore, this embodiment also provides a computer-readable storage medium, which stores a computer program, and the computer program is used to execute the above-mentioned cross-domain data communication method.

[0130] The embodiments of the present disclosure provide a computer program product of 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 previous method embodiments. For specific implementation, please refer to the method embodiments and will not be repeated here.

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

[0132] The foregoing description is intended only to provide specific embodiments of the present disclosure, intended to enable those skilled in the art to understand and implement the present disclosure. 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 the present disclosure. Therefore, the present disclosure is not intended to be limited to the embodiments described herein, but rather to be construed in the broadest manner consistent with the principles and novel features disclosed herein.

Claims

1. A cross-domain data communication method, characterized in that: The method comprises: The 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; and the distributed worker cluster includes a plurality of workers with different domain names; querying, through the first Worker, whether the first data identifier exists in the local first cache; If not, determining a second Worker that has cached the first data based on the global index; wherein the first data is data corresponding to the first data identifier; Cross-domain querying, through the first Worker, from the second Worker for response data corresponding to the first data identifier; 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 determining, based on the global index, the second Worker that caches the first data includes: Querying a global index for a target domain name to which the first data identifier belongs through the first Worker; wherein the global index at least includes: a data identifier and a domain name stored in 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.

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

4. The method according to claim 1, wherein The response data further includes: a first data version number; after cross-domain querying the response data corresponding to the first data identifier from the second worker through the first worker, the method further includes: Updating the first data and the first data version number corresponding to the first data identifier in the first cache of the first Worker; The first data version number corresponding to the first data identifier is updated in the global index.

5. The method according to claim 1, characterized in that The method further comprises: When a third worker in the distributed worker cluster updates the second data and its second data version number in the local third cache, determining a fourth worker in the distributed worker cluster that subscribes to the second data identifier; wherein the second data identifier is an identifier of the second data; Broadcasting an update event to the fourth Worker; wherein the update event is used to notify the fourth Worker to update data; After receiving the update event through the fourth Worker, it is determined 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, 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, determining the current data version number corresponding to the second data identifier in the local fourth cache; Comparing 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, updating the second data and the second data version number in the fourth cache of the fourth Worker, and sending a data update notification 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, 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: Create a Worker for each domain name through the target thread, and configure cross-domain communication for the Worker of each domain name; Register the Worker of each domain name through the target thread; Each Worker is connected to a peer-to-peer (P2P) connection via 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 cache architecture including local cache and global index; 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 of cross-domain data based on a Map structure, and the data description information includes: data identification, domain name, data version number and access rights.

9. The method according to claim 1, characterized in that The target thread sends a first data request to a 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, payload and data version number; In the distributed Worker cluster, determining a first Worker corresponding to the recipient domain name included in the first data request; Send the first data request to the first Worker.

10. The method according to claim 1, characterized in that After querying, through the first Worker, whether the local first cache contains the first data identifier, the method further includes: If the first data identifier exists in the first cache when queried by the first Worker, 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 comprises: processor; a memory for storing instructions executable by the processor; The processor is configured to read the executable instructions from the memory and execute the instructions to implement the method according to any one of claims 1 to 10.

12. A computer-readable storage medium, characterized in that The computer-readable storage medium stores instructions, and when the instructions are executed on a terminal device, the terminal device implements the method according to any one of claims 1 to 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

  • Browser cross-domain information interaction method, device and equipment based on front end

    CN116962380A

  • Cross-domain calculation implementation method and system based on multiple data centers

    CN118283042A