Management method and device based on TCP long connection communication, equipment and medium
By caching TCP long connection configuration information during application initialization and updating the status periodically, the problem of insufficient TCP link state awareness is solved, achieving the effect of second-level management and zero transaction loss.
Patent Information
- Application Number
- CN202310640713.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-31
- Publication Date
- 2025-11-21
- Estimated Expiration
- 2043-05-31
AI Technical Summary
Existing technology cannot detect the TCP link status, resulting in a delay of about 30 seconds and transaction impact when switching client applications, making it impossible to achieve automatic detection and management.
By reading and caching the TCP long connection configuration information in the database during application initialization, and triggering communication management instructions according to a preset monitoring cycle, the state of the TCP long connection is obtained and updated to detect changes in the link state.
It achieves second-level TCP link state awareness and management, reduces latency during application switching, and ensures zero transaction loss and system flexibility and robustness.
Smart Images

Figure CN116633997B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of communication technology, and in particular to management methods, apparatus, devices and media based on TCP long connection communication. Background Technology
[0002] As a switching system between channel providers and industry partners, the personalized industry backend system needs to exchange data information based on the message queue (MQ) provided by the industry partner. This is a communication method based on the underlying TCP long connection communication protocol. Because the communication between the channel provider and the industry partner is a single-point TCP long connection, that is, a server application of the industry partner is connected to at least one client application of the channel provider via TCP.
[0003] Current technologies cannot detect TCP link status. For example, during multi-client application switching, when client application A switches to client application B, the offline of client application A on the server and the online of client application B on the server cannot be automatically detected by the client applications. Generally, the client applications need to be stopped and restarted, resulting in a delay of about 30 seconds, affecting transactions, and incurring high switching costs. Currently, there is no management solution based on TCP long-connection communication. Summary of the Invention
[0004] This application provides a management method, apparatus, device, and medium based on TCP long connection communication, which provides a management scheme based on TCP long connection communication that can sense the TCP link status.
[0005] Firstly, this application provides a management method based on TCP long connection communication, the method comprising:
[0006] In response to the application initialization command, the first configuration information of the TCP long connection in the database is read one by one and cached. Based on the cached information, each group of server application and client application to be connected is determined, and a TCP long connection is established between the server application and client application to be connected.
[0007] According to the preset monitoring cycle, a TCP long connection communication management instruction is triggered; in response to the TCP long connection communication management instruction, the second configuration information of the current TCP long connection in the database is obtained, and the status of each group of TCP long connections is updated according to the second configuration information and the currently cached information.
[0008] Secondly, this application provides a management device based on TCP long connection communication, the device comprising:
[0009] The initialization module is used to respond to the application initialization command, read the first configuration information of the TCP long connection in the database one by one, and cache the first configuration information; determine each group of server application and client application to be connected according to the cached information, and establish the TCP long connection of the server application and client application to be connected.
[0010] The communication management module is used to trigger TCP long connection communication management instructions according to a preset monitoring period; in response to the TCP long connection communication management instructions, it obtains the second configuration information of the current TCP long connection in the database, and updates the status of each group of TCP long connections according to the second configuration information and the currently cached information.
[0011] Thirdly, this application provides an electronic device, including a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus;
[0012] Memory, used to store computer programs;
[0013] A processor, when executing a program stored in memory, implements the steps of the method described.
[0014] Fourthly, this application provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of the method described.
[0015] This application provides a management method, apparatus, device, and medium based on TCP long connection communication. The method includes: in response to an application initialization command, reading first configuration information of TCP long connections from a database one by one, and caching the first configuration information; determining each group of server applications and client applications to be connected based on the cached information, and establishing TCP long connections between the server applications and client applications to be connected; triggering a TCP long connection communication management command according to a preset monitoring period; in response to the TCP long connection communication management command, obtaining second configuration information of the current TCP long connections in the database, and updating the status of each group of TCP long connections based on the second configuration information and the currently cached information.
[0016] The above technical solution has the following advantages or beneficial effects:
[0017] In this application, during application initialization, the first configuration information of TCP long connections is read from the database one by one and cached. Based on the cached information, TCP long connections are established for each group of server and client applications to be connected. According to a preset monitoring cycle, a TCP long connection communication management command is triggered. Specifically, the second configuration information of the current TCP long connections in the database is retrieved, and the status of each group of TCP long connections is updated based on the second configuration information and the currently cached information. Because the second configuration information of TCP long connections in the database changes when the link status changes, retrieving the current second configuration information allows for the perception of the real-time TCP link status, and subsequently, the status of each group of TCP long connections is updated based on the second configuration information and the currently cached information. This achieves a management scheme based on TCP long connection communication that can perceive the TCP link status. Attached Figure Description
[0018] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0019] Figure 1 A schematic diagram of the management process based on TCP long connection communication provided for this application;
[0020] Figure 2 A detailed flowchart of management based on TCP long connection communication provided for this application;
[0021] Figure 3 A schematic diagram of the management device structure based on TCP long connection communication provided in this application;
[0022] Figure 4 A schematic diagram of the electronic device structure provided in this application. Detailed Implementation
[0023] To make the objectives and implementation methods of this application clearer, the exemplary implementation methods of this application will be clearly and completely described below with reference to the accompanying drawings of the exemplary embodiments of this application. Obviously, the exemplary embodiments described are only some embodiments of this application, and not all embodiments.
[0024] It should be noted that the brief descriptions of terms in this application are only for the convenience of understanding the embodiments described below, and are not intended to limit the embodiments of this application. Unless otherwise stated, these terms should be understood in their ordinary and common meaning.
[0025] The terms "first," "second," "third," etc., used in the specification, claims, and accompanying drawings of this application are used to distinguish similar or related objects or entities, and do not necessarily imply a specific order or sequence, unless otherwise specified. It should be understood that such terms are interchangeable where appropriate.
[0026] The terms “comprising” and “having”, and any variations thereof, are intended to cover but not exclude inclusion, for example, a product or device that includes a range of components is not necessarily limited to all of the components that are clearly listed, but may include other components that are not clearly listed or that are inherent to such product or device.
[0027] The term "module" refers to any known or subsequently developed hardware, software, firmware, artificial intelligence, fuzzy logic, or combination of hardware and / or software code that is capable of performing the functions associated with that element.
[0028] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.
[0029] For ease of explanation, the above description has been provided in conjunction with specific embodiments. However, the above exemplary discussion is not intended to be exhaustive or to limit the embodiments to the specific forms disclosed above. Various modifications and variations can be obtained based on the above teachings. The selection and description of the above embodiments are for the purpose of better explaining the principles and practical applications, thereby enabling those skilled in the art to better utilize the described embodiments and various different variations of embodiments suitable for specific use considerations.
[0030] Figure 1 The diagram illustrating the management process based on TCP long connection communication provided in this application includes the following steps:
[0031] S101: In response to the application initialization command, read the first configuration information of the TCP long connection in the database one by one, and cache the first configuration information; determine each group of server application and client application to be connected according to the cached information, and establish the TCP long connection of the server application and client application to be connected.
[0032] S102: Trigger a TCP long connection communication management instruction according to a preset monitoring cycle; in response to the TCP long connection communication management instruction, obtain the second configuration information of the current TCP long connection in the database, and update the status of each group of TCP long connections according to the second configuration information and the currently cached information.
[0033] The management method based on TCP long connection communication provided in this application is applied to electronic devices, which may be PCs, tablets, or servers.
[0034] The database stores the initial configuration information for TCP long connections. This initial configuration information includes the configuration parameters for each TCP long connection link, including TCP connection elements such as the TCP connection's IP address and port number, as well as an availability field for the server application and a listening machine code field for the client application. The availability field indicates which server applications are connectable, and the listening machine code field indicates which client applications are connectable.
[0035] After receiving the application initialization command, the electronic device, in response, reads the first configuration information of the TCP long-connection from the database one by one, caches the first configuration information locally, and then determines each group of server and client applications to be connected based on the cached information, and establishes TCP long connections between the server and client applications to be connected. A TCP long connection means that the client initiates a connection to the server, the server accepts the client's connection, and the connection is established. After the client and server complete a request, the connection between the client and server is not actively closed; subsequent read and write operations will continue to use this connection. TCP stands for Transmission Control Protocol.
[0036] The electronic device stores a preset monitoring period, such as monitoring once per second. According to the preset monitoring period, a TCP long connection communication management command is triggered. In response to the command, the device retrieves currently cached information and the second configuration information of the current TCP long connection in the database. When the TCP long connection state changes, the second configuration information of the current TCP long connection in the database changes compared to the first configuration information. Based on the second configuration information and the currently cached information, the state of each group of TCP long connections is updated. This achieves second-level management based on TCP long connection communication.
[0037] In this application, during application initialization, the first configuration information of TCP long connections is read from the database one by one and cached. Based on the cached information, TCP long connections are established for each group of server and client applications to be connected. According to a preset monitoring cycle, a TCP long connection communication management command is triggered. Specifically, the second configuration information of the current TCP long connections in the database is retrieved, and the status of each group of TCP long connections is updated based on the second configuration information and the currently cached information. Because the second configuration information of TCP long connections in the database changes when the link status changes, retrieving the current second configuration information allows for the perception of the real-time TCP link status, and subsequently, the status of each group of TCP long connections is updated based on the second configuration information and the currently cached information. This achieves a management scheme based on TCP long connection communication that can perceive the TCP link status.
[0038] In this application, the step of determining each group of server-side applications and client-side applications to be connected based on cached information, and establishing a long TCP connection for the server-side applications and client-side applications to be connected includes:
[0039] For each link in the cached information, determine whether the server application of the link is in a pending connection state based on the availability field of the server application; determine whether the client application of the link is in a pending connection state based on the listening machine code field of the client application; group the server applications and client applications in the pending connection state in the same link together and establish a TCP long connection.
[0040] For each link in the cached information, the availability of the server application in that link is determined based on the server application's availability field, and the client application's listening machine code field is determined based on the client application's pending connection state. If the server application in that link is available and the client application is in a pending connection state, a long-lived TCP connection is established between the server application and the client application for that link.
[0041] For example, in the server-side application's availability field, 0 represents unavailable and 1 represents available. Therefore, if the server-side application's status is 0, it's unavailable; if it's 1, it's available. Similarly, the presence of client application listener machine codes in the client application's listener machine code field indicates which client applications are in a pending connection state, and those without such codes are not. For instance, client application A's listener machine code is 01, client application B's is 02, and client application C's is 03. If 02 and 03 are present in the listener machine code field, then client application A is not in a pending connection state, while client applications B and C are in a pending connection state. Alternatively, the client application's listener machine code field includes whitelisted and blacklisted listener machine codes. Client applications with whitelisted listener machine codes are in a pending connection state, while those with blacklisted listener machine codes are not.
[0042] For example, if a link includes client application B and server application M, and server application M is available based on the availability field of the server application and the listening machine code field of the client application, and client application B is in a pending connection state, then a long TCP connection between client application B and server application M is established; otherwise, a long TCP connection between client application B and server application M is not established.
[0043] Based on the second configuration information and the currently cached information, the status of each group of TCP long connections is updated, including:
[0044] The second configuration information is matched with the currently cached information. If the match is inconsistent, the updated link is determined based on the second configuration information and the currently cached information, and the status of the TCP long connection of the server application and the client application corresponding to the updated link is updated.
[0045] If the second configuration information and the currently cached information are inconsistent, then the different links in the second configuration information and the currently cached information are identified. Different links include two cases: first, links that exist in the second configuration information but not in the currently cached information, which are newly added links; second, links that do not exist in the second configuration information but exist in the currently cached information, which are deleted links.
[0046] Based on the second configuration information and the currently cached information, the updated link is determined, and the status of the TCP long connection of the server application and client application corresponding to the updated link is updated by: determining the newly added first link based on the second configuration information and the currently cached information; caching the configuration information of the first link; and establishing the TCP long connection of the server application and client application corresponding to the first link based on the cached information.
[0047] For scenario one, after identifying the newly added first link, the configuration information of the first link is cached. Based on the cached information, a persistent TCP connection is established between the server application and the client application corresponding to the first link. Specifically, the availability field of the server application and the listening machine code field of the client application can be used to determine whether the server application corresponding to the first link is available and whether the client application corresponding to the first link is in a pending connection state. If the server application corresponding to the first link is available and the client application corresponding to the first link is in a pending connection state, then a persistent TCP connection is established between the server application and the client application corresponding to the first link. Otherwise, no persistent TCP connection is established, and an alarm message is output.
[0048] Based on the second configuration information and the currently cached information, the updated link is determined, and the status of the TCP long connection of the server application and client application corresponding to the updated link is updated by: determining the second link to be deleted based on the second configuration information and the currently cached information; deleting the configuration information of the second link from the currently cached information; and disconnecting the TCP long connection of the server application and client application corresponding to the second link based on the cached information.
[0049] In scenario two, after determining the second link to be deleted, the configuration information of the second link is directly deleted from the current cache information, and the TCP long connection between the server application and the client application corresponding to the second link is disconnected according to the cached information.
[0050] If the second configuration information matches the currently cached information, the method further includes:
[0051] For each link establishing a TCP long connection, obtain the most recent timestamp and the current timestamp of the transaction processing corresponding to the link; if the time difference between the most recent timestamp and the current timestamp exceeds a preset time difference threshold, output an alarm message.
[0052] For each TCP long connection established, after the connection processes a transaction, the transaction processing timestamp is updated. The most recent timestamp and the current timestamp of the transaction processing for that connection are obtained. If the time difference between the most recent timestamp and the current timestamp does not exceed a preset time difference threshold, it indicates that the connection is processing the transaction normally. If the time difference between the most recent timestamp and the current timestamp exceeds the preset time difference threshold, it indicates that the connection is processing the transaction abnormally, and an alarm message is output.
[0053] To ensure more accurate alarm triggering, if the time difference between the most recent timestamp and the current timestamp exceeds a preset time difference threshold, the alarm message output includes:
[0054] If the time difference between the most recent timestamp and the current timestamp exceeds a preset time difference threshold, a connectivity test is performed on the link. If the test fails, the alarm message is output.
[0055] If the test passes, obtain the number of backlogged transactions corresponding to the link. If the number of backlogged transactions exceeds a preset threshold, output the alarm message. Alternatively, monitor the TCP connection status of the link. If the TCP connection status of the link is abnormal, output the alarm message.
[0056] Scenario 1: When the time difference between the most recent timestamp and the current timestamp exceeds a preset time difference threshold, a connectivity test is first performed on the link. Optionally, the electronic device actively triggers a server application connectivity test message to determine whether the connected server application is functioning correctly. If the test fails, the aforementioned alarm message is directly output.
[0057] Scenario 2: If the test passes, obtain the number of backlogged transactions for the corresponding link. If the number of backlogged transactions does not exceed the preset threshold, it indicates that the link's transaction processing is normal and no alarm is triggered. If the number of backlogged transactions exceeds the preset threshold, it indicates that the link's transaction processing is abnormal and an alarm message is output.
[0058] Scenario 3: If the test passes, monitor the TCP connection status of the link. If the TCP connection status of the link is abnormal, output an alarm message. If the TCP connection status of the link is normal, do not output an alarm message.
[0059] This application relies on specific configuration management of TCP long connections by the application. Through a caching and thread management mechanism provided in this application, it continuously compares the cached and actual configurations, enabling flexible listening of TCP messages based on specific configuration parameters. For operations using TCP long connections to obtain asynchronous messages, it provides a new method for alarming, liveness detection, isolation, and reconnection. Simultaneously, it meets the requirements of multi-center second-level switching and zero transaction loss.
[0060] The management method based on TCP long connection communication provided in this application includes the following steps:
[0061] Define configuration information: The storage medium (such as a database) defines a TCP configuration information management table. In addition to the core elements of TCP connection (IP, PORT), two additional fields are added: the listening machine code and whether it is available. Theoretically, it can support an unlimited number of configurations.
[0062] TCP message listening initialization: The application defines a cache set to store TCP connection information. The key is the primary key of a connection information record, and the value is the cache information in the configuration table. Additionally, three variables are added: a synchronous queue thread reference, an asynchronous queue thread reference, and an activity timestamp. During application initialization, the configuration table information is retrieved, and the availability field for each configuration record is checked. If the application machine code is in the machine code whitelist in the configuration table, a long-lived TCP connection is started, and the started listening thread is submitted to a thread pool with a fixed core thread count. The listening thread information is placed in the thread reference variable, and the activity timestamp is initialized to the current time.
[0063] Intelligent monitoring service: Adds a resident thread to manage TCP listening information. By synchronizing the configuration table and application cache information in seconds, it intelligently senses the status of each TCP listening link and performs corresponding operations, including alarm, liveness detection, isolation, and reconnection.
[0064] Alarms: Call the component interface encapsulating the TCP connection, such as the IBMMQ component's API interface, to obtain the MQ status. Besides "running" (normal operation), other statuses such as "binding" (starting and binding) and "retrying" (abnormal reconnection) will trigger the alarm service to notify system administrators for handling. Obtain the MQ message queue depth and configure a threshold for the number of backlogged messages. An alarm will be triggered if the threshold is exceeded. The threshold for the number of backlogged messages is, for example, 100 or 110 messages.
[0065] Active access detection: When an application receives a message, it updates the activity timestamp variable in the cache to the current time. The management thread compares the cached timestamp with the current timestamp. If the difference exceeds a configured threshold, it proactively triggers a connectivity test message from the industry to determine if the application connection is normal. If the active access detection fails, an alarm is triggered, and a reconnection mechanism is initiated. Configurable thresholds can be, for example, half an hour, one hour, or 1800 seconds, 3000 seconds, 3600 seconds, etc.
[0066] By agreeing on a business test message with the tax service application, such as the business type SYLJA1, representing a connectivity test, if we, as the client, do not receive any message response from the tax service as the server for more than an hour after exceeding a threshold, and the connection is normal without any alarms, we can suspect that the server application is stuck or the process is in a dead state. The management thread will assemble the corresponding business connectivity test message according to the agreement and send it to the tax service. If the server does not respond, that is, does not reply with the SYLJA2 response message of the request message, it means that the liveness probe has failed and the server is considered to be in an unavailable state. The management thread triggers an alarm to prompt our operations and maintenance personnel to notify the tax bureau to check whether its application is normal and to start the isolation retry mechanism. If the tax bureau returns a SYLJA2 response message, it means that the application is normal, the timestamp is updated to the current time, and the next judgment cycle begins. The liveness probe is a probe initiated by the client to the server for a TCP long connection.
[0067] Isolation: The management thread initiates the following TCP listener thread removal operation by comparing whether the available field in the configuration table is unavailable or the machine code of the current application is not in the whitelist: it obtains the corresponding thread information based on the listener thread reference in the cache, sets the interrupt flag for the current thread according to the thread interrupt() method provided by the JAVA API, and triggers an exception for resident threads involving TCP connections. In the method that catches the exception, the TCP connection is closed, and after removing the listener thread reference, the configuration information of the TCP cache is removed from the cache collection.
[0068] Reconnection: The management thread compares the configuration information in the configuration table and the cache to see if they match. This can happen if the IP address and port have changed, or if the application's machine code rules have changed. Alternatively, if the listening thread throws an exception, or if the liveness detection fails, the management thread will proactively remove the TCP configuration information. During the next synchronization, if the configuration information is found to be present in the table but not in the cache, the TCP connection initialization process will be executed accordingly.
[0069] Figure 2 The detailed flowchart for managing TCP long connection communication provided in this application, taking the use of the MQ component based on TCP long connection as an example, mainly includes MQ initialization listening service, management thread service and listening thread service.
[0070] The overall solution is explained below through a specific system implementation process:
[0071] MQ initialization listening process:
[0072] The application defines a cache set to store MQ connection information. The key is the MQ-region code corresponding to the tax, and the value is the cached information from the MQ configuration table. Additionally, three variables are added: a synchronous queue thread reference, an asynchronous queue thread reference, and an activity timestamp. During application initialization, the MQ configuration table information is retrieved, and the availability field for each MQ message is checked. If the application machine code is in the whitelist of machine codes in the configuration table, the MQ connection is started, and the started synchronous and asynchronous listening threads are submitted to a thread pool with a fixed number of core threads. The synchronous thread information is placed in the synchronous queue thread reference variable, and the asynchronous thread information is placed in the asynchronous queue thread reference variable. The activity timestamp is initialized to the current time.
[0073] A normal TCP connection is a one-to-one link. The example of IBMMQ application here is a special case of long-lived TCP connections, where an MQ contains two long-lived TCP connections, representing two links. Internally, the MQ places synchronous business messages (real-time messages) into a synchronous queue, which is one long-lived TCP connection. Asynchronous business messages (such as reconciliation messages, which can be replied to the next day) are placed into an asynchronous queue, which is another long-lived TCP connection. The synchronous queue thread reference and the asynchronous queue thread reference represent references to these two long-lived TCP connections.
[0074] The application defines a cache set to store MQ connection information. The key is the MQ-region code corresponding to the tax, and the value is the cache information in the MQ configuration table. In addition, three variables are added: synchronous queue thread reference, asynchronous queue thread reference, and activity timestamp.
[0075] During application initialization, the application retrieves the MQ configuration table information and compares it with the application's machine code. If the machine code exists in the MQ configuration table, and the MQ status is available, the application reads the MQ connection information (IP, PORT, queue information, etc.) and submits it to the thread pool for processing based on the connection information. The thread pool starts synchronous and asynchronous listening threads. The synchronous listening thread stores the current thread information in the synchronous queue information variable in the cache, and the asynchronous listening thread stores the current thread information in the asynchronous queue information variable in the cache.
[0076] The listening thread is a persistent thread that maintains a long TCP connection. It retrieves messages from the message queue as soon as they exist, updates the activity timestamp in the MQ cache to the current time, submits the message to the business thread pool for processing, and then continues fetching the next message. The listening thread captures all exception information. When an MQ exception occurs, a removal method is added to the captured code segment to actively call the relevant MQ API interface to perform an MQ disconnect operation and remove the corresponding thread information from the cache. If both synchronous and asynchronous listening thread information show exceptions, the MQ cache information is cleared.
[0077] Start the intelligent MQ thread management service and define a separate scheduled task execution thread that executes once every second. The main task of this thread is to compare whether the MQ messages in the database and the cache are consistent. The main information to be compared includes the region code, IP, PORT, availability, etc., and to perform the corresponding operations.
[0078] When the comparison is inconsistent, a new available MQ is added to the database, or the status of an existing MQ changes from unavailable to available, the MQ configuration information is retrieved and the MQ startup process is executed because the MQ does not exist in the cache.
[0079] When a discrepancy occurs (the message doesn't exist in the database but exists in the cache), the MQ removal operation is performed. This involves retrieving the thread information from the cache, executing the `interrupt()` method of the current thread, and marking the thread as interrupted. Due to the characteristic that listening threads on TCP long connections immediately throw an exception upon receiving the interrupt flag, the thread catches the exception internally, actively calls the relevant MQ API interface to perform the MQ disconnection operation, and removes the corresponding thread information from the cache. If both synchronous and asynchronous listening thread information show exceptions, the MQ cache information is cleared.
[0080] When the comparison is successful, the activity timestamp in the cache is compared with the current time. A one-hour threshold is set. If the timeout threshold is exceeded, the connectivity test interface provided by the server is actively called. If the test fails, an alarm service is triggered to notify the operations and maintenance personnel. The queue status and the number of backlogged messages are obtained through the MQAPI. The alarm service is triggered when the queue status is other than running, such as binding or retrying. When the number of backlogged messages exceeds the configured threshold, an alarm is triggered.
[0081] When the comparison is successful and the transaction is normal (i.e., the above-mentioned anomaly is not triggered), the comparison process ends and waits for the next comparison process to be triggered.
[0082] The functions implemented above have the following applications in industry-specific personalized back-end systems:
[0083] Provides normal MQ message listening service to obtain business messages returned by the server.
[0084] When IBMMQ throws normal exception codes such as 2033 or 2059, it proactively removes the MQ cache information and triggers a reconnection mechanism under the monitoring of the MQ management thread to restart the MQ that caused the exception, achieving self-healing within seconds.
[0085] When the server-side application encounters an anomaly while the MQ connection remains normal, the timestamp-based liveness detection mechanism can promptly identify the anomaly and notify the server for handling. The server-side component could be, for example, a server belonging to a relevant department.
[0086] When the application's processing capacity decreases and it is unable to quickly consume the information accumulated in the MQ, or when the MQ status becomes abnormal due to network problems, it can be detected and dealt with in a timely manner.
[0087] Because the server-side MQ is a single point of connection, it is prone to single point of failure due to network issues. The system is configured with a cold standby link. When a network anomaly occurs, the cold standby link is activated. After the operations and maintenance personnel perform IP migration operations, the IP and PORT information in the MQ configuration table are modified immediately, and the MQ management thread service takes effect instantly, enabling the application to have the ability to recover quickly after network failures.
[0088] The industry-specific customized backend system adopts a dual-center distributed multi-active architecture. It only requires configuring multiple listening machine codes in the MQ configuration table and relying on the MQ management thread service to achieve a flexible multi-active listening strategy.
[0089] The dual-center machines are assigned two different sets of machine codes. When it is necessary to switch and restore the center, you only need to modify the MQ configuration table to the listening machine code of the corresponding center. By relying on the MQ management thread service, you can achieve fast switching without restarting the application. It takes effect in seconds and there is zero transaction loss.
[0090] This application achieves second-level transaction switching in a multi-center distributed asynchronous system through intelligent management of TCP long-connection listening threads. It ensures zero transaction loss during center switching, automatic application awareness, and eliminates the need to restart application services, increasing system flexibility. It reduces the risk of single-point failures based on TCP long connections. When a single point of failure occurs due to internal network issues, second-level reconnection is achieved by modifying the corresponding configuration table IP information after server IP migration, automatically isolating the original faulty node, thus increasing system robustness. It provides timely second-level detection, early warning, and reconnection recovery when TCP listening anomalies occur during transactions (such as IBMMQ throwing errors 2033 and 2059). Furthermore, it intelligently detects link abnormalities to determine whether to automatically reconnect when there is a period of no message interaction (such as IBMMQ experiencing probabilistic message retrieval process freezes under high concurrency), increasing system robustness. It is compatible with all systems that use TCP long-connection-based message retrieval methods, such as systems using MQ components, NETTY components, and native SOCKET classes, demonstrating a degree of universality.
[0091] Figure 3 The schematic diagram of the management device structure based on TCP long connection communication provided in this application includes:
[0092] Initialization module 31 is used to respond to application initialization instructions by reading the first configuration information of TCP long connections in the database one by one and caching the first configuration information; determining each group of server applications and client applications to be connected based on the cached information, and establishing TCP long connections between the server applications and client applications to be connected.
[0093] The communication management module 32 is used to trigger TCP long connection communication management instructions according to a preset monitoring period; in response to the TCP long connection communication management instructions, it obtains the second configuration information of the current TCP long connection in the database, and updates the status of each group of TCP long connections according to the second configuration information and the currently cached information.
[0094] The initialization module 31 is specifically used to determine whether the server application of the link is in a pending connection state based on the availability field of the server application for each link in the cached information; to determine whether the client application of the link is in a pending connection state based on the listening machine code field of the client application; and to group the server applications and client applications in the pending connection state in the same link together and establish a TCP long connection.
[0095] The communication management module 32 is specifically used to match the second configuration information with the currently cached information. If the match is inconsistent, it determines the updated link based on the second configuration information and the currently cached information, and updates the status of the TCP long connection of the server application and the client application corresponding to the updated link.
[0096] The communication management module 32 is specifically used to determine the newly added first link based on the second configuration information and the currently cached information; cache the configuration information of the first link; and establish a TCP long connection between the server application and the client application corresponding to the first link based on the cached information.
[0097] The communication management module 32 is specifically used to determine the second link to be deleted based on the second configuration information and the information currently cached; delete the configuration information of the second link from the information currently cached; and disconnect the TCP long connection between the server application and the client application corresponding to the second link based on the cached information.
[0098] The communication management module 32 is also used to obtain the most recent timestamp and the current timestamp of the transaction processing corresponding to each link for establishing a TCP long connection; if the time difference between the most recent timestamp and the current timestamp exceeds a preset time difference threshold, an alarm message is output.
[0099] The communication management module 32 is specifically used to perform a connectivity test on the link if the time difference between the most recent timestamp and the current timestamp exceeds a preset time difference threshold; if the test fails, output the alarm message; if the test passes, obtain the number of backlogged transactions corresponding to the link; if the number of backlogged transactions exceeds a preset number threshold, output the alarm message; or monitor the TCP connection status of the link; if the TCP connection status of the link is abnormal, output the alarm message.
[0100] This application also provides an electronic device, such as Figure 4 As shown, it includes: processor 401, communication interface 402, memory 403 and communication bus 404, wherein processor 401, communication interface 402 and memory 403 communicate with each other through communication bus 404.
[0101] The memory 403 stores a computer program, which, when executed by the processor 401, causes the processor 401 to perform any of the above method steps.
[0102] The communication bus mentioned in the above electronic devices can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus can be divided into address bus, data bus, control bus, etc. For ease of illustration, only one thick line is used to represent it in the diagram, but this does not indicate that there is only one bus or one type of bus.
[0103] Communication interface 402 is used for communication between the above-mentioned electronic device and other devices.
[0104] The memory may include random access memory (RAM) or non-volatile memory (NVM), such as at least one disk storage device. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor.
[0105] The processors mentioned above can be general-purpose processors, including central processing units, network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits, field-programmable gate arrays or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.
[0106] This application also provides a computer-readable storage medium storing a computer program executable by an electronic device, which, when run on the electronic device, causes the electronic device to perform any of the above method steps.
[0107] Although preferred embodiments of this application have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of this application.
[0108] Obviously, those skilled in the art can make various modifications and variations to this application without departing from the spirit and scope of this application. Therefore, if such modifications and variations fall within the scope of the claims of this application and their equivalents, this application also intends to include such modifications and variations.
Claims
1. A management method based on TCP long connection communication, characterized in that, The method includes: In response to the application initialization command, the first configuration information of the TCP long connection in the database is read one by one and cached. Based on the cached information, each group of server application and client application to be connected is determined, and a TCP long connection is established between the server application and client application to be connected. According to the preset monitoring cycle, a TCP long connection communication management instruction is triggered; in response to the TCP long connection communication management instruction, the second configuration information of the current TCP long connection in the database is obtained, and the status of each group of TCP long connections is updated according to the second configuration information and the currently cached information; One of the features is a resident thread that manages TCP listening information. By synchronizing the configuration table and the application's cache information at the second level, it can intelligently sense the status of each TCP listening link and perform corresponding operations, including isolation and reconnection operations. The isolation operation refers to the management thread initiating the following TCP listening thread removal operation by comparing whether the available field in the configuration table is unavailable or the machine code of the current application is not in the whitelist: obtaining the corresponding thread information based on the listening thread reference in the cache, setting the interrupt flag for the current thread, and triggering an exception for resident threads involving TCP connections. In the method that catches the exception, the TCP connection is closed, and after removing the listening thread reference, the configuration information of the TCP cache in the cache set is removed. The reconnection operation refers to the process where the management thread actively triggers the removal of TCP configuration information and initiates the TCP connection initialization process when the configuration information in the configuration table and cache is inconsistent, the machine code rules of the application being monitored change, an exception is actively thrown internally by the monitoring thread, or the liveness detection fails.
2. The method as described in claim 1, characterized in that, The step of determining each group of server-side and client-side applications to be connected based on cached information, and establishing a long TCP connection for the server-side and client-side applications to be connected, includes: For each link in the cached information, determine whether the server application of the link is in a pending connection state based on the availability field of the server application; determine whether the client application of the link is in a pending connection state based on the listening machine code field of the client application; group the server applications and client applications in the pending connection state in the same link together and establish a TCP long connection.
3. The method as described in claim 1, characterized in that, Based on the second configuration information and the currently cached information, the status of each group of TCP long connections is updated, including: The second configuration information is matched with the currently cached information. If the match is inconsistent, the updated link is determined based on the second configuration information and the currently cached information, and the status of the TCP long connection of the server application and the client application corresponding to the updated link is updated.
4. The method as described in claim 3, characterized in that, Based on the second configuration information and the current cached information, the updated link is determined, and the status of the TCP long connection of the server application and client application corresponding to the updated link is updated, including: Based on the second configuration information and the currently cached information, determine the newly added first link; cache the configuration information of the first link; establish a TCP long connection between the server application and the client application corresponding to the first link based on the cached information.
5. The method as described in claim 3, characterized in that, Based on the second configuration information and the current cached information, the updated link is determined, and the status of the TCP long connection of the server application and client application corresponding to the updated link is updated, including: Based on the second configuration information and the currently cached information, determine the second link to be deleted; delete the configuration information of the second link from the currently cached information; disconnect the TCP long connection between the server application and the client application corresponding to the second link based on the cached information.
6. The method as described in claim 3, characterized in that, If the second configuration information matches the currently cached information, the method further includes: For each link establishing a TCP long connection, obtain the most recent timestamp and the current timestamp of the transaction processing corresponding to the link; if the time difference between the most recent timestamp and the current timestamp exceeds a preset time difference threshold, output an alarm message.
7. The method as described in claim 6, characterized in that, If the time difference between the most recent timestamp and the current timestamp exceeds a preset time difference threshold, the output alarm message includes: If the time difference between the most recent timestamp and the current timestamp exceeds a preset time difference threshold, a connectivity test is performed on the link. If the test fails, the alarm message is output. If the test passes, obtain the number of backlogged transactions corresponding to the link. If the number of backlogged transactions exceeds a preset threshold, output the alarm message. Alternatively, monitor the TCP connection status of the link. If the TCP connection status of the link is abnormal, output the alarm message.
8. A management device based on TCP long connection communication, characterized in that, The device includes: The initialization module is used to respond to the application initialization command, read the first configuration information of the TCP long connection in the database one by one, and cache the first configuration information; determine each group of server application and client application to be connected according to the cached information, and establish the TCP long connection of the server application and client application to be connected. The communication management module is used to trigger TCP long connection communication management instructions according to a preset monitoring period; in response to the TCP long connection communication management instructions, it obtains the second configuration information of the current TCP long connection in the database, and updates the status of each group of TCP long connections according to the second configuration information and the currently cached information; One of the features is a resident thread that manages TCP listening information. By synchronizing the configuration table and the application's cache information at the second level, it can intelligently sense the status of each TCP listening link and perform corresponding operations, including isolation and reconnection operations. The isolation operation refers to the management thread initiating the following TCP listening thread removal operation by comparing whether the available field in the configuration table is unavailable or the machine code of the current application is not in the whitelist: obtaining the corresponding thread information based on the listening thread reference in the cache, setting the interrupt flag for the current thread, and triggering an exception for resident threads involving TCP connections. In the method that catches the exception, the TCP connection is closed, and after removing the listening thread reference, the configuration information of the TCP cache in the cache set is removed. The reconnection operation refers to the process where the management thread actively triggers the removal of TCP configuration information and initiates the TCP connection initialization process when the configuration information in the configuration table and cache is inconsistent, the machine code rules of the application being monitored change, an exception is actively thrown internally by the monitoring thread, or the liveness detection fails.
9. The apparatus as claimed in claim 8, characterized in that, The initialization module is specifically used to determine whether the server application of each link in the cached information is in a pending connection state based on the availability field of the server application; and to determine whether the client application of the link is in a pending connection state based on the listening machine code field of the client application; and to group the server applications and client applications in the pending connection state in the same link together and establish a TCP long connection.
10. The apparatus as claimed in claim 8, characterized in that, The communication management module is specifically used to match the second configuration information with the currently cached information. If the match is inconsistent, it determines the updated link based on the second configuration information and the currently cached information, and updates the status of the TCP long connection of the server application and the client application corresponding to the updated link.
11. The apparatus as claimed in claim 10, characterized in that, The communication management module is specifically used to determine the newly added first link based on the second configuration information and the currently cached information; and to cache the configuration information of the first link. Based on the cached information, establish a long TCP connection between the server application and the client application corresponding to the first link.
12. The apparatus as claimed in claim 10, characterized in that, The communication management module is specifically used to determine the second link to be deleted based on the second configuration information and the currently cached information; delete the configuration information of the second link from the currently cached information; and disconnect the TCP long connection between the server application and the client application corresponding to the second link based on the cached information.
13. The apparatus as claimed in claim 10, characterized in that, The communication management module is also used to obtain the most recent timestamp and the current timestamp of the transaction processing corresponding to each link that establishes a TCP long connection; If the time difference between the most recent timestamp and the current timestamp exceeds a preset time difference threshold, an alarm message will be output.
14. The apparatus as claimed in claim 13, characterized in that, The communication management module is specifically used to perform a connectivity test on the link if the time difference between the most recent timestamp and the current timestamp exceeds a preset time difference threshold, and to output the alarm message if the test fails. If the test passes, obtain the number of backlogged transactions corresponding to the link. If the number of backlogged transactions exceeds a preset threshold, output the alarm message. Alternatively, monitor the TCP connection status of the link. If the TCP connection status of the link is abnormal, output the alarm message.
15. An electronic device, characterized in that, It includes a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, when executing a program stored in memory, implements the steps of the method described in any one of claims 1-7.
16. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the method described in any one of claims 1-7.
Citation Information
Patent Citations
Long connection state updating method, service terminal, server and storage medium
CN110572443A
Cache optimization method and system for long link
CN113364830A