CN-122001868-A - Cross-platform link library communication method, device, equipment and medium based on optimized WebAPI
Abstract
The application discloses a cross-platform link library communication method, device, equipment and medium based on an optimized WebAPI, and relates to the technical field of computer communication. And the cross-platform link library performs serialization processing on parameters of the data request and transmits the parameters to the data interface layer. And the data interface layer packages the data request after parameter serialization into a binary request through the gRPC client and the lightweight SignalR client according to the application scene and transmits the binary request to the intelligent integrated data platform. The intelligent integrated data platform accesses a plurality of databases of the storage layer according to the binary request, encapsulates the obtained result into binary response data, and transmits the binary response data back to the data interface layer through a communication protocol. The data interface layer deserializes the binary response data into response data and transmits the response data to the client application program, and the high-efficiency interface communication with low delay, high throughput and less resource occupation is realized in a multi-language environment.
Inventors
- YU XIAOLONG
- LV DAJUN
- LIU YUQIN
- WANG ZHAOFENG
- QIN FEI
- Sun Boshuo
- LI DONGLIANG
- SUN ZHIPENG
- JIANG HAN
Assignees
- 国能智深控制技术有限公司
Dates
- Publication Date
- 20260508
- Application Date
- 20260203
Claims (10)
- 1. A cross-platform link library communication method based on an optimized WebAPI, comprising: the client application program calls a cross-platform link library to initiate a data request; The cross-platform link library performs parameter serialization on the data request, and transmits the data request subjected to parameter serialization to a data interface layer; The data interface layer encapsulates the data request after parameter serialization into a binary request through a gRPC client and a lightweight SignalR client according to an application scene corresponding to the data request after parameter serialization, and transmits the binary request to an intelligent integrated data platform; The intelligent integrated data platform concurrently accesses a plurality of databases in a storage layer according to the binary request, packages the results obtained by the concurrent access into binary response data, and transmits the binary response data to the data interface layer through the communication protocol; The data interface layer deserializes the binary response data into response data, and transmits the response data to the client application program through the cross-platform link library.
- 2. The method of claim 1, wherein the client application invoking the cross-platform link library initiates a data request comprising: the client application program generates the data request according to service logic; The client application program selects a matched target link library from the cross-platform link library according to the running environment of the client application program, wherein the client application program is any one of a Windows platform C++ client application program, a Linux platform C++ client application program, a Windows platform C# client application program and a Java client application program, the cross-platform link library is generated by C# Native AOT compiling, the target link library is any one of a C++ DLL link library suitable for a Windows platform, a C++ SO link library suitable for a Linux platform, a C# DLL link library suitable for a Windows platform and a JAR package suitable for a Java environment, and the JAR package suitable for the Java environment is obtained by bridging and packaging the C++ DLL link library suitable for the Windows platform and the C++ SO link library suitable for the Linux platform; the client application initiates the data request by invoking an interface of the target link library.
- 3. The method according to claim 1, wherein the data interface layer encapsulates the data request after parameter serialization into a binary request through gRPC clients and lightweight SignalR clients according to an application scenario corresponding to the data request after parameter serialization, and transmits the binary request to an intelligent integrated data platform, and the method comprises: The data interface layer detects an application scene corresponding to the data request after the parameter serialization is determined; if the application scene corresponding to the data request after the parameter serialization is detected and determined to be a data subscription scene, the data interface layer acquires user authentication information through the gRPC client and transmits the user authentication information to the lightweight SignalR client; The lightweight SignalR client initiates a WebSocket connection request to a SignalR server of the intelligent integrated data platform based on the user authentication information, wherein the WebSocket connection request carries the user authentication information; the SignalR server verifies the user authentication information; if verification is successful, the SignalR server establishes WebSocket connection with the lightweight SignalR client; The lightweight SignalR client sends a SignalR handshake message to the SignalR server to carry out connection protocol adaptation, marks a WebSocket connection instance after the connection protocol adaptation as an available state, and adds the marked WebSocket connection instance into a WebSocket connection pool; The data interface layer transmits the data request after parameter serialization to the lightweight SignalR client; the lightweight SignalR client side invokes a WebSocket connection instance marked as an available state from the WebSocket connection pool; The lightweight SignalR client detects the heartbeat state of the WebSocket connection instance marked as the available state; If the heartbeat state is detected, determining that the WebSocket connection instance marked as the available state is in an active state, and the lightweight SignalR client packages the data request after parameter serialization into the binary request; and the lightweight SignalR client transmits the binary request to the SignalR server through the WebSocket connection instance marked as the available state by a WebSocket communication protocol.
- 4. A method according to claim 3, wherein after the data interface layer detects an application scenario corresponding to the data request after the parameter serialization is determined, the method further comprises: If the application scene corresponding to the data request after the parameter serialization is detected and determined to be a target read-write scene, the data interface layer acquires user authentication information through the gRPC client and verifies the user authentication information, wherein the target read-write scene is a real-time data read-write scene, a historical data read-write scene, a statistical data read scene and a measuring point attribute read scene; If verification is successful, the gRPC client packages the data request after parameter serialization into the binary request, and transmits the binary request to the intelligent integrated data platform through gRPC communication protocol.
- 5. A method according to claim 3, characterized in that the method further comprises: the lightweight SignalR client continuously detects the transmission state in the process that the SignalR server and the lightweight SignalR client establish WebSocket connection; If the detection determines that the WebSocket connection is disconnected, the lightweight SignalR client initiates a WebSocket reconnection request, wherein the WebSocket reconnection request carries the user authentication information; When the WebSocket reconnection is successful, the lightweight SignalR client packages the data request after parameter serialization again, marks a new WebSocket connection instance as an available state, and adds the new WebSocket connection instance into the WebSocket connection pool; When the WebSocket reconnection fails, the new WebSocket connection instance is marked as a connection exception.
- 6. The method of claim 1, wherein the intelligent integrated data platform concurrently accesses a plurality of databases in a storage layer according to the binary request, encapsulates results of the concurrent access into binary response data, and comprises: The intelligent integrated data platform analyzes the data processing type identifier carried in the binary request, and determines at least one data processing task, wherein the data processing task is any one of a real-time data read-write task, a historical data read-write task, a statistical data read task and a measuring point attribute read task; the task scheduler of the intelligent integrated data platform reads the CPU core number of the current running environment and configures the maximum concurrent processing thread number to be the same as the CPU core number; The task scheduler distributes the at least one data processing task to a plurality of working threads with the same number as the CPU cores for parallel processing, wherein if the data processing task is a real-time data read-write task, the working threads access a memory cache pool to execute data read-write operation, and when the read-write data amount in the memory cache pool reaches a preset cache threshold, the real-time database in the storage layer is accessed through a batch submission strategy; if the data processing task is a historical data read-write task or a statistical data read-write task, the working thread acquires target data from a local multi-level cache by adopting a multi-level cache strategy, and concurrently accesses a historical database or a statistical database in the storage layer in an asynchronous I/O mode when the target data is not acquired; And the task scheduler receives the processing results fed back by the plurality of working threads, takes the processing results fed back by the plurality of working threads as the results obtained by the concurrent access, and packages the results obtained by the concurrent access into binary response data.
- 7. The method according to claim 1, wherein the method further comprises: The method comprises the steps that a test layer loads and analyzes a YAML test case file, wherein the YAML test case file comprises a link library path, a test language environment and at least one test subtask, the test language environment is any one of C++, C#, and Java, the test subtask comprises a test interface, a test parameter and a test mode, and the test modes are serial or parallel; The test layer classifies the at least one test subtask according to the test mode of each test subtask to obtain a serial task set and a parallel task set; For the serial task set, the test layer sequentially executes each test subtask in the serial task set according to the execution sequence of the test subtasks in the YAML test case file; For the parallel task set, the test layer concurrently executes at least one test subtask included in the parallel task set, wherein the test layer initiates an interface request to the cross-platform link library through the communication protocol in the process of executing each test subtask, and records the task name, the execution result and the task execution duration of each test subtask after the interface request is executed; And the test layer takes the task name, the execution result and the task execution duration of each test subtask as a structured test report.
- 8. A cross-platform link library communication device based on an optimized WebAPI, which is applied to the cross-platform link library communication method based on the optimized WebAPI as claimed in claim 1, and is characterized by comprising the following steps: The initiation module is used for calling the cross-platform link library by the client application program to initiate a data request; The processing module is used for carrying out parameter serialization on the data request by the cross-platform link library and transmitting the data request after the parameter serialization to a data interface layer; The packaging module is used for packaging the data request subjected to parameter serialization into a binary request through a gRPC client and a lightweight SignalR client according to an application scene corresponding to the data request subjected to parameter serialization by the data interface layer, and transmitting the binary request to an intelligent integrated data platform; The access module is used for enabling the intelligent integrated data platform to access a plurality of databases in the storage layer in parallel according to the binary request, packaging the results obtained by the concurrent access into binary response data, and transmitting the binary response data to the data interface layer through the communication protocol; and the transmission module is used for inversely sequencing the binary response data into response data by the data interface layer and transmitting the response data to the client application program through the cross-platform link library.
- 9. An apparatus comprising a memory and a processor, the memory storing a computer program, characterized in that the processor implements the steps of the method of any one of claims 1 to 7 when the computer program is executed.
- 10. A medium having stored thereon a computer program, which when executed by a processor performs the steps of the method according to any of claims 1 to 7.
Description
Cross-platform link library communication method, device, equipment and medium based on optimized WebAPI Technical Field The application relates to the technical field of computer communication, in particular to a cross-platform link library communication method, device, equipment and medium based on an optimized WebAPI. Background Along with the increasing complexity of enterprise informatization architecture, multi-language (such as C++, java and C#) collaboration and hybrid platform (such as Windows and Linux) deployment become normal, frequent, low-delay and high-throughput data interaction is needed between systems, and higher requirements are put on the performance and cross-platform capability of a communication framework. In the related technology, the data butt joint between an external system and a data platform is mainly realized by depending on a Web API, the data transmission is carried out by adopting an HTTP protocol in the REST style, the interaction is completed by initiating an HTTP request and analyzing a response message, the cross-language call is realized by adapting an HTTP client based on different languages, and the test process is realized by depending on a Web interface to initiate an HTTP request verification function and performance. The applicant realizes that the HTTP protocol has redundant message format and multi-layer serialization overhead, which results in slow response, high resource occupation, incapability of meeting the frequent, low-delay and high-throughput data interaction demands, the HTTP client adaptation logic of different languages is not uniform, interface encapsulation and parameter compatibility are insufficient, the system integration complexity of a hybrid architecture project is increased, the cross-platform and multi-language adaptation is poor, the test mode relying on HTTP requests is easily interfered by a network layer, cannot be close to a real operation environment, the actual performance of an interface is difficult to accurately verify, the test accuracy and efficiency are low, a reliable connection management mechanism is also lacked, the problems of disconnection, data loss and the like are easily caused under the high-concurrency or network instability scene, the real-time performance and stability are insufficient, and the resource occupation of a server side is large, so that the requirements of industrial control, real-time monitoring and the like on harsh performance are difficult to meet. Disclosure of Invention In view of this, the present application provides a method, apparatus, device and medium for cross-platform link library communication based on optimized WebAPI, which mainly aims to solve the problem that the HTTP protocol cannot meet the real-time data interaction requirements of modern applications for high performance, high stability and easy integration due to the inherent redundancy overhead, difficult cross-language adaptation, inaccurate test and unreliable connection. According to a first aspect of the present application, there is provided a cross-platform link library communication method based on an optimized WebAPI, the method comprising: the client application program calls a cross-platform link library to initiate a data request; The cross-platform link library performs parameter serialization on the data request, and transmits the data request subjected to parameter serialization to a data interface layer; The data interface layer encapsulates the data request after parameter serialization into a binary request through a gRPC client and a lightweight SignalR client according to an application scene corresponding to the data request after parameter serialization, and transmits the binary request to an intelligent integrated data platform; The intelligent integrated data platform concurrently accesses a plurality of databases in a storage layer according to the binary request, packages the results obtained by the concurrent access into binary response data, and transmits the binary response data to the data interface layer through the communication protocol; The data interface layer deserializes the binary response data into response data, and transmits the response data to the client application program through the cross-platform link library. According to a second aspect of the present application, there is provided a cross-platform linked library communication device based on an optimized WebAPI, the device comprising: The initiation module is used for calling the cross-platform link library by the client application program to initiate a data request; The processing module is used for carrying out parameter serialization on the data request by the cross-platform link library and transmitting the data request after the parameter serialization to a data interface layer; The packaging module is used for packaging the data request subjected to parameter serialization into a binary request through a gRPC client and a