Message batch sending method and device, electronic equipment and readable storage medium
Through the principle of sliding window counter and message packet strategy, batch message packet sending is dynamically adjusted, which solves the problem of inefficient transaction request processing in the existing technology, and realizes the efficient and stable payment services of financial institutions and the stability of small batch payment systems. Docking.
Patent Information
- Application Number
- CN202411013153.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-26
- Publication Date
- 2024-11-29
AI Technical Summary
The existing synchronous memory waiting mechanism and asynchronous timed and quantitative sending mechanism are inefficient when processing large or small transaction requests, resulting in wasted system resources, reduced response speed or delay, affecting the business needs of financial institutions and the efficiency and quality of payment services.
The sliding window counter principle is used to store the message to be transmitted. Combined with the query rate per second and the single packet volume, the message group packet strategy is dynamically determined, and multiple messages to be transmitted are extracted for batch message group packet transmission, ensuring that the system maintains the message peak periods during different message Efficient and stable.
It improves the overall robustness of the system, ensures stable connection with the small batch payment system, meets the business needs of financial institutions, and improves the efficiency and quality of payment services, so as to maintain efficient operation in both peak and trough periods.
Smart Images

Figure CN119052324A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of Internet technology, and in particular to a method, device, electronic device and readable storage medium for batch sending of messages. Background Art
[0002] In recent years, with the continuous development of Internet technology, new payment methods such as electronic payment and mobile payment have emerged. The diversification of payment methods and the personalization of customer needs have become important challenges faced by banks and other financial service providers. In order to meet these diverse payment needs and at the same time improve the efficiency of capital circulation and reduce operating costs, financial institutions have sought technological innovation and optimization. The traditional single transaction processing method is inefficient and costly when processing a large number of small transactions. Therefore, the small batch payment system came into being. The system allows financial institutions to send and receive payment instructions in batches, effectively reducing the processing time and cost of a single transaction and increasing the speed of capital circulation.
[0003] In the related technology, a synchronous memory waiting mechanism can be used to implement batch sending of messages, that is, after receiving the user's transaction request, a message object is maintained inside the system memory to collect and store a certain number of transaction requests. When the message object collects enough transaction requests, they are packaged in batches and sent to a small batch system; or, an asynchronous timed and quantitative sending mechanism can be used to implement batch sending of messages, that is, small single transaction information is stored in a database or put into a message / cache queue in real time, and the asynchronous thread takes out the transaction information from the queue in a timed and quantitative manner for batch packaging and sending.
[0004] In the process of implementing the related technology, the inventors realized that the related technology has at least the following technical problems:
[0005] The synchronous memory waiting mechanism shows high efficiency when processing a large number of transaction requests, but when processing a small number of transaction requests, it may lead to waste of system resources and decreased response speed; the asynchronous timed and quantitative sending mechanism may produce certain delays because transactions are not processed immediately, and when the transaction volume increases sharply, the processing capacity of the asynchronous thread may become a bottleneck, affecting the overall performance, resulting in the inability to stably connect with the small batch payment system, making it difficult to meet the business needs of financial institutions, and the efficiency and quality of payment services are low. Summary of the invention
[0006] In view of this, the present application provides a method, device, electronic device and readable storage medium for batch sending of messages, the main purpose of which is to solve the current problems of being unable to stably connect with small batch payment systems, difficulty in meeting the business needs of financial institutions, and low efficiency and quality of payment services.
[0007] According to the first aspect of the present application, a method for sending batch messages is provided, the method comprising:
[0008] Continuously receiving messages to be transmitted, and storing the received messages to be transmitted based on a cache object, wherein the cache object stores the messages to be transmitted according to a sliding window counter principle;
[0009] Get the current query rate per second and query the current single message packet size;
[0010] Determining a message grouping strategy based on the query rate per second and the single packet volume;
[0011] A plurality of messages to be transmitted are extracted from the cache object according to the message packaging strategy, and a batch message packaging and sending operation is performed on the plurality of messages to be transmitted.
[0012] Optionally, the continuously receiving the message to be transmitted and storing the received message to be transmitted based on the cache object includes:
[0013] Continuously receive messages and store the received messages in the message queue according to the message receiving time;
[0014] Transmitting the messages stored in the message queue to the cache object in sequence;
[0015] Determining the to-be-transmitted message in the received message based on the sliding window counter principle in the cache object;
[0016] Obtaining the message body message of the message to be transmitted, and reading the message volume of the message body message;
[0017] Referring to the message volume, the cache object is used to store the message to be transmitted.
[0018] Optionally, determining the message to be transmitted in the received message based on the sliding window counter principle in the cache object includes:
[0019] For each message received, query the timestamp of the message;
[0020] Determine in the cache object the window time range to which the timestamp indicated by the sliding window counter principle belongs, and read the amount of received messages corresponding to the window time range;
[0021] Obtaining a message volume threshold, and comparing the received message volume with the message volume threshold;
[0022] When the amount of received messages is less than the message amount threshold, taking the messages as the messages to be transmitted;
[0023] When the amount of received messages is equal to the message amount threshold, the message is discarded, and other messages are continued to be received. The amount of received messages corresponding to the window time range to which other timestamps of the other messages belong is compared with the message amount threshold to determine whether to use the other messages as the messages to be transmitted.
[0024] Optionally, referring to the message volume and using the cache object to store the message to be transmitted includes:
[0025] Querying a preset volume threshold, and comparing the message volume with the preset volume threshold;
[0026] When the message volume is less than or equal to the preset volume threshold, storing the message to be transmitted in the cache object;
[0027] When the message volume is greater than the preset volume threshold, the message identifier of the message to be transmitted is obtained, the message identifier is stored in the cache object, and the message body message of the message to be transmitted is stored in a database.
[0028] Optionally, determining the message grouping strategy based on the query rate per second and the single packet volume includes:
[0029] Comparing the query rate per second with the single packet volume;
[0030] When the query rate per second is greater than or equal to the single packet volume, query the maximum single packet volume corresponding to the single message packet, calculate the ratio between the query rate per second and the maximum single packet volume, use the ratio as the package message volume, and generate the message package strategy including the package message volume;
[0031] When the query rate per second is less than the single packet volume, the maximum waiting time is queried, and the message package strategy including the maximum waiting time is generated.
[0032] Optionally, extracting a plurality of messages to be transmitted from the cache object according to the message packaging strategy includes:
[0033] If the message grouping strategy includes the grouped message quantity, extracting to-be-transmitted messages whose number is equal to the grouped message quantity from the cache object as the multiple to-be-transmitted messages;
[0034] If the message grouping strategy includes the maximum waiting time, the cache time of each to-be-transmitted message in the cache object is queried respectively, and the to-be-transmitted messages whose cache time is greater than or equal to the maximum waiting time are taken as the multiple to-be-transmitted messages.
[0035] Optionally, performing a batch message grouping and sending operation on the multiple messages to be transmitted includes:
[0036] Querying the interface requirements set by the message receiver, and performing a package grouping operation on the multiple messages to be transmitted according to the interface requirements to obtain a message package to be sent;
[0037] Generating a message packet identifier for the message packet to be sent;
[0038] Setting the states corresponding to the multiple messages to be transmitted in the message queue to be sent, and marking the multiple messages to be transmitted using the message packet identifier;
[0039] Performing a batch sending operation on the message packets to be sent;
[0040] After the batch sending operation is successfully executed, query the sending status corresponding to each of the to-be-transmitted messages using the message packet identifier;
[0041] In the message queue, the queried sending status is used to update the status corresponding to the corresponding message to be transmitted.
[0042] According to a second aspect of the present application, a device for sending messages in batches is provided, the device comprising:
[0043] A storage module, used for continuously receiving messages to be transmitted, and storing the received messages to be transmitted based on a cache object, wherein the cache object stores the messages to be transmitted according to a sliding window counter principle;
[0044] The acquisition module is used to obtain the current query rate per second and query the single packet volume of the current single message packet;
[0045] A determination module, configured to determine a message grouping strategy based on the query rate per second and the single packet volume;
[0046] The package assembly module is used to extract multiple messages to be transmitted from the cache object according to the message package assembly strategy, and perform batch message package assembly and sending operations on the multiple messages to be transmitted.
[0047] Optionally, the storage module is used to continuously receive messages, store the received messages in a message queue according to the message reception time; transmit the messages stored in the message queue to the cache object in sequence; determine the message to be transmitted in the received message based on the sliding window counter principle in the cache object; obtain the message body message of the message to be transmitted, and read the message volume of the message body message; and use the cache object to store the message to be transmitted with reference to the message volume.
[0048] Optionally, the storage module is used to query the timestamp of each received message; determine the window time range to which the timestamp indicated by the sliding window counter principle belongs in the cache object, and read the amount of received messages corresponding to the window time range; obtain a message amount threshold, and compare the amount of received messages with the message amount threshold; when the amount of received messages is less than the message amount threshold, treat the message as the message to be transmitted; when the amount of received messages is equal to the message amount threshold, discard the message, continue to receive other messages, and compare the amount of received messages corresponding to the window time range to which other timestamps of other messages belong with the message amount threshold to determine whether to treat the other messages as the messages to be transmitted.
[0049] Optionally, the storage module is used to query a preset volume threshold, compare the message volume with the preset volume threshold; when the message volume is less than or equal to the preset volume threshold, store the message to be transmitted in the cache object; when the message volume is greater than the preset volume threshold, obtain the message identifier of the message to be transmitted, store the message identifier in the cache object, and store the message body message of the message to be transmitted in the database.
[0050] Optionally, the determination module is used to compare the query rate per second with the single packet volume; when the query rate per second is greater than or equal to the single packet volume, query the maximum single packet volume corresponding to the single message packet, calculate the ratio between the query rate per second and the maximum single packet volume, use the ratio as the package message volume, and generate the message package strategy including the package message volume; when the query rate per second is less than the single packet volume, query the maximum waiting time, and generate the message package strategy including the maximum waiting time.
[0051] Optionally, the determination module is used to extract, if the message grouping strategy includes the amount of grouped messages, messages to be transmitted whose number is equal to the amount of grouped messages in the cache object as the multiple messages to be transmitted; if the message grouping strategy includes the maximum waiting time, the cache time of each message to be transmitted in the cache object is queried separately, and the messages to be transmitted whose cache time is greater than or equal to the maximum waiting time are taken as the multiple messages to be transmitted.
[0052] Optionally, the packet assembly module is used to query the interface requirements set by the message recipient, perform a packet assembly operation on the multiple messages to be transmitted according to the interface requirements, and obtain a message packet to be sent; generate a message packet identifier for the message packet to be sent; set the status corresponding to the multiple messages to be transmitted as to be sent in the message queue, and use the message packet identifier to mark the multiple messages to be transmitted; perform a batch sending operation on the message packets to be sent; after the batch sending operation is successfully executed, use the message packet identifier to query the sending status corresponding to each of the messages to be transmitted; in the message queue, use the queried sending status to update the status corresponding to the corresponding message to be transmitted.
[0053] According to a third aspect of the present application, an electronic device is provided, comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of any one of the methods described in the first aspect when executing the computer program.
[0054] According to a fourth aspect of the present application, a readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of any one of the methods described in the first aspect are implemented.
[0055] By means of the above technical scheme, the present application provides a method, device, electronic device and readable storage medium for batch sending of messages. The present application continuously receives messages to be transmitted, stores the received messages to be transmitted based on a cache object that stores messages to be transmitted according to the principle of a sliding window counter, obtains the current query rate per second, and queries the single packet volume of the current single message packet, determines the message packaging strategy based on the query rate per second and the single packet volume, extracts multiple messages to be transmitted from the cache object according to the message packaging strategy, performs batch message packaging and sending operations on multiple messages to be transmitted, combines the query rate per second and the single packet volume to realize dynamic packaging operations, and the system can maintain efficient and stable operation regardless of the low or peak of message traffic, enhance the overall robustness of the system, ensure stable docking with the small batch payment system, better meet the business needs of financial institutions, and improve the efficiency and quality of payment services.
[0056] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0057] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the detailed description of the preferred embodiments below. The accompanying drawings are only for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the present application. Also, the same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings:
[0058] Figure 1 A schematic diagram of a method for sending batch messages provided in an embodiment of the present application is shown;
[0059] Figure 2A A schematic diagram of another method for sending messages in batches provided in an embodiment of the present application is shown;
[0060] Figure 2B A schematic diagram of a process flow of a message receiving stage provided by an embodiment of the present application is shown;
[0061] Figure 2C A schematic diagram of a process of asynchronously packaging and sending a response phase provided by an embodiment of the present application is shown;
[0062] Figure 3 A schematic diagram of the structure of a device for sending batch messages provided in an embodiment of the present application is shown;
[0063] Figure 4 A schematic diagram of the device structure of an electronic device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION
[0064] The exemplary embodiments of the present application will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present application are shown in the accompanying drawings, it should be understood that the present application can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided in order to enable a more thorough understanding of the present application and to fully convey the scope of the present application to those skilled in the art.
[0065] The present application embodiment provides a method for sending batch messages, such as Figure 1 As shown, the method includes:
[0066] 101. Continuously receive messages to be transmitted, and store the received messages to be transmitted based on a cache object.
[0067] The embodiments of the present application can be applied to a system, which can be a system that provides users with financial, shopping, local life and other services. The system is equipped with a server, which can be an independent server or a server that provides cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDN), and big data and artificial intelligence platforms, etc., so that the system has the ability to receive messages and send messages in batches.
[0068] In an embodiment of the present application, the system may be an online service system provided by a relevant organization for the convenience of users. The system may provide users with corresponding services, such as order payment services, transfer services, etc. When users need to use services, corresponding instructions will be initiated based on the front-end application provided by the system. In response to these instructions, the system needs to obtain information related to the processing instructions and transmit this information as messages to other corresponding systems for processing. Therefore, the system is also connected to other third-party systems so that the received messages can be distributed to the corresponding third-party systems for processing to meet the needs of the users who initiated the instructions. Therefore, the messages to be transmitted may be instructions, requests, etc. initiated by users at the front end.
[0069] In the embodiment of the present application, the system is taken as a service system of a banking institution for example. In this example, the message to be transmitted may be a payment message received by the system, such as a transfer, repayment, and other payment messages initiated by a user in the banking system. The system needs to transfer the payment messages in batches to a small batch system for processing in order to meet the user's transfer, repayment, and other needs.
[0070] Since the technical solution of the present application is to send messages in batches, a cache object for caching messages can be created. Specifically, a cache service layer can be created and the cache service layer can be used as a cache object. Further, in an optional implementation scheme, the cache object can store the messages to be transmitted according to the sliding window counter principle, that is, the cache object is created with reference to the sliding window counter principle. The sliding window counter is a classic algorithm for controlling data flow. It can dynamically adjust the window size according to the real-time and importance of the data, thereby achieving effective management of the data.
[0071] 102. Obtain the current query rate per second, and query the single packet volume of the current single message packet.
[0072] In order to be able to dynamically group and send messages in batches when facing different message peaks, in an embodiment of the present application, before grouping the messages, the current query rate per second is obtained, and the single packet volume of the current single message packet is queried.
[0073] Among them, the single packet volume is the message packet size of a single message packet when the message is packaged; the current query rate per second is the current QPS (Query Per Second) of the server. QPS is a standard for measuring the amount of traffic processed by the server carried by the system within a specified time. It specifically refers to the number of times the server completes processing requests per second, that is, the process from issuing a request to the server completing the processing and successfully returning the result. QPS can reflect the server's processing power and system performance. Therefore, in order to understand the current performance of the server, so as to dynamically adjust the message packet size when packaging messages according to the performance, this application will obtain the current query rate per second, and query the single packet volume of the current single message packet, and determine whether the single packet volume of the message packet can be appropriately adjusted based on the size relationship between the query rate per second and the single packet volume, thereby improving the packaging efficiency and achieving flexible packaging in different message peaks.
[0074] 103. Determine the message grouping strategy based on the query rate per second and the size of a single packet.
[0075] In the embodiment of the present application, after obtaining the query rate per second and the volume of a single packet, in order to realize dynamic package grouping operation according to the performance of the server in different message peak segments, it is necessary to determine the message package grouping strategy based on the query rate per second and the volume of a single packet. Among them, determining the message package grouping strategy based on the query rate per second and the volume of a single packet is essentially an intelligent calculation of the performance of the server and the number of messages that currently need to be sent. This calculation method can combine and send messages within an effective time during periods of low message traffic, thereby avoiding message delays that may occur during off-peak periods; and during periods of peak message traffic, this calculation method also performs well, and can quickly batch process and package a large number of messages to cope with the pressure on system performance during peak periods.
[0076] Among them, the message packaging strategy is used to indicate how to generate a message package, that is, to indicate how to perform the packaging operation on the transmitted message. Specifically, it can limit the number of packaged messages or limit the waiting time for the message to perform the packaging operation. This application does not limit the specific content of the message packaging strategy.
[0077] 104. Extract multiple messages to be transmitted from the cache object according to the message packaging strategy, and perform a batch message packaging and sending operation on the multiple messages to be transmitted.
[0078] In the embodiment of the present application, after the message package strategy is determined, since the message package strategy indicates how to generate a message package, multiple messages to be transmitted can be directly extracted from the cache object according to the message package strategy, and batch message package sending operations can be performed on the multiple messages to be transmitted. The technical solution of the present application combines the query rate per second and the volume of a single package to realize dynamic package operation, which not only optimizes the efficiency of message processing, but also enhances the overall robustness of the system, ensuring that the system can provide coherent and reliable services under different workloads.
[0079] The method provided in the embodiment of the present application continuously receives messages to be transmitted, stores the received messages to be transmitted based on a cache object that stores the messages to be transmitted according to the principle of a sliding window counter, obtains the current query rate per second, and queries the single packet volume of the current single message packet, determines the message packaging strategy based on the query rate per second and the single packet volume, extracts multiple messages to be transmitted from the cache object according to the message packaging strategy, performs batch message packaging and sending operations on the multiple messages to be transmitted, combines the query rate per second and the single packet volume to realize dynamic packaging operations, and the system can maintain efficient and stable operation regardless of the low or peak of the message traffic, thereby enhancing the overall robustness of the system, ensuring stable docking with the small batch payment system, better meeting the business needs of financial institutions, and improving the efficiency and quality of payment services.
[0080] Further, as a refinement and extension of the specific implementation of the above embodiment, in order to fully illustrate the specific implementation process of this embodiment, the embodiment of the present application provides another method for sending messages in batches, such as Figure 2A As shown, the method includes:
[0081] 201. Continue to receive messages, store the received messages in a message queue according to the message receiving time, and sequentially transmit the messages stored in the message queue to the cache object.
[0082] In the embodiment of the present application, since the system provides services to users, the system will continuously receive messages generated when users have service needs. In order to ensure efficient transmission and processing of messages, a message queue is set in the system. The message queue adopts a high-availability queue mechanism. When receiving messages to be packaged and transmitted, the system will store the received messages in the message queue according to the reception time of the messages, that is, temporarily store these single messages in this high-availability queue. The purpose of this is to ensure the stability and reliability of messages during transmission and prevent message loss due to network fluctuations or other external factors.
[0083] In another optional implementation scheme, the system will also store the messages in the message queue in a cache object for caching messages. The creation method of this cache object refers to the principle of sliding window counter. Sliding window counter is a classic algorithm for controlling data flow. It can dynamically adjust the size of the window according to the real-time and importance of the data, thereby achieving effective management of the data. The system will transfer the messages stored in the message queue to the cache object in sequence, and determine which messages need to be stored and which messages need to be discarded in the cache object according to the principle of sliding window counter, so as to achieve flow control and enhance the overall robustness of the system.
[0084] 202. Based on the sliding window counter principle in the cache object, determine the message to be transmitted from the received message.
[0085] In an embodiment of the present application, since the cache object operates based on the sliding window counter principle, not every message transmitted to the cache object will be cached. The system will determine the messages to be transmitted from the received messages based on the sliding window counter principle in the cache object, cache the messages to be transmitted, and discard other messages.
[0086] Specifically, when determining the message to be transmitted, for each message received, the system will query the timestamp of the message, determine the window time range to which the timestamp indicated by the sliding window counter principle belongs in the cache object, and read the amount of received messages corresponding to the window time range. Then, the message amount threshold is obtained, and the amount of received messages is compared with the message amount threshold. Among them, when the amount of received messages is less than the message amount threshold, it means that the amount of messages received in the window time range to which the timestamp belongs has not reached the message amount threshold, and messages sent in the window time range can continue to be received. Therefore, the message is used as a message to be transmitted. When the amount of received messages is equal to the message amount threshold, it means that the amount of messages received in the window time range to which the timestamp belongs has reached the message amount threshold, and a current limiting operation needs to be performed. Messages sent within the window time range can no longer be received. Therefore, the message needs to be discarded, and other messages continue to be received, and the amount of received messages corresponding to the window time range to which other timestamps of other messages belong is compared with the message amount threshold to determine whether other messages are used as messages to be transmitted.
[0087] 203. Obtain a message body message of the message to be transmitted, read the message volume of the message body message, refer to the message volume, and use a cache object to store the message to be transmitted.
[0088] In an embodiment of the present application, in order to reduce the occupancy of storage space, when storing the message to be transmitted based on the cache object, it is necessary to obtain the message body message of the message to be transmitted, read the message volume of the message body message, and refer to the message volume to use the cache object to store the message to be transmitted.
[0089] Specifically, it is necessary to query the preset volume threshold and compare the message volume with the preset volume threshold. Among them, when the message volume is less than or equal to the preset volume threshold, it means that the message volume is small, and even if the message to be transmitted is directly stored in the cache object, it will not occupy too much storage space. Therefore, the message to be transmitted is stored in the cache object. When the message volume is greater than the preset volume threshold, it means that the message volume is large, and the system will not directly store the entire message to be transmitted, but choose to store only the message identifier corresponding to the message to be transmitted, that is, obtain the message identifier of the message to be transmitted, store the message identifier in the cache object, and store the message body message of the message to be transmitted in the database. Among them, the message identifier can be the message ID of the message to be transmitted. The advantage of doing so is that it can greatly reduce the storage space occupied and improve the operating efficiency of the system; moreover, by storing the message identifier, the system can quickly locate the specific message content in the database according to the message identifier when needed, so as to achieve fast reading and processing.
[0090] 204. Obtain the current query rate per second, and query the single packet volume of the current single message packet, and determine the message packetization strategy based on the query rate per second and the single packet volume.
[0091] In order to be able to dynamically group and send messages in batches when facing different message peaks, in an embodiment of the present application, before grouping the messages, the current query rate per second is obtained, and the single packet volume of the current single message packet is queried, and the message grouping strategy is determined based on the query rate per second and the single packet volume, so that it is determined whether the single packet volume of the message packet can be appropriately adjusted according to the relationship between the query rate per second and the single packet volume, thereby improving the grouping efficiency and realizing flexible grouping in different message peaks.
[0092] The query rate per second is a key indicator to measure the system's processing power. It indicates the number of requests or queries that the system can handle per unit time. Therefore, the system will compare the query rate per second with the single packet size to decide how to handle the message to be transmitted.
[0093] Among them, when the query rate per second is greater than or equal to the single packet volume, it means that the current QPS is high, the server is processing a large number of requests, and the message volume of a single packet needs to be appropriately reduced. Therefore, the system will query the maximum single packet volume corresponding to a single message package, calculate the ratio between the query rate per second and the maximum single packet volume, use the ratio as the package message volume, and generate a message package strategy including the package message volume. That is, a value basis for package operation of messages is calculated based on the current QPS divided by the maximum value of the package batch configuration. The value basis can be used to determine how many messages to take out for package sending. The purpose of this is to better balance the system load and performance, and avoid system overload due to excessive message volume.
[0094] Correspondingly, when the query rate per second is less than the volume of a single packet, it means that the current QPS is low and the server is relatively idle. The data volume of a single packet can be appropriately increased. Therefore, the system will query the maximum waiting time and generate a message packaging strategy that includes the maximum waiting time, so that when the server is relatively idle, all messages that have been waiting for a long time can be transmitted to avoid long-term message retention.
[0095] 205. Extract multiple messages to be transmitted from the cache object according to the message packaging strategy.
[0096] In an embodiment of the present application, after the message package strategy is determined, since the message package strategy indicates how to generate a message package, multiple messages to be transmitted can be directly extracted from the cache object according to the message package strategy, so as to subsequently perform batch message package sending operations on the multiple messages to be transmitted.
[0097] It can be seen from the content in the above step 204 that the message packaging strategy may include two different contents. Therefore, different processing procedures of the message packaging strategies including different contents are described below:
[0098] If the message grouping strategy includes the number of grouped messages, it means that the message grouping strategy limits the number of messages included in a single message package in the grouping operation. Therefore, the system extracts the number of to-be-transmitted messages equal to the number of grouped messages from the cache object as multiple to-be-transmitted messages. When extracting messages, the messages can be extracted and grouped in sequence according to the receiving time, thereby preventing some messages from being retained for too long.
[0099] If the message packaging strategy includes the maximum waiting time, it means that when the server is relatively idle, all messages that have been waiting for a long time can be transmitted to avoid long-term message retention. Therefore, it is necessary to query the cache time of each message to be transmitted in the cache object separately, and treat the messages to be transmitted whose cache time is greater than or equal to the maximum waiting time as multiple messages to be transmitted.
[0100] 206. Query the interface requirements set by the message receiver, perform a package grouping operation on the multiple messages to be transmitted according to the interface requirements, obtain a message package to be sent, generate a message package identifier for the message package to be sent, set the states corresponding to the multiple messages to be transmitted as to be sent in the message queue, and mark the multiple messages to be transmitted using the message package identifier.
[0101] In the embodiment of the present application, since the explanation is made by taking the bank system sending messages to the small-amount batch payment system as an example, the message receiver here is the small-amount batch payment system. Among them, the message receiver such as the small-amount batch payment system usually sets interface requirements, such as interface protocols, etc., to limit the data format, encoding method, field length, etc. of the received messages. Therefore, before transmitting multiple messages to be transmitted, it is necessary to query the interface requirements set by the message receiver, perform the package operation on the multiple messages to be transmitted according to the interface requirements, and obtain the message package to be sent. In this way, the multiple messages to be transmitted can be sorted, converted and packaged according to the data format specifications required by the message receiver, ensuring that the generated message package to be sent is presented in a form that meets the interface requirements, and ensuring the integrity and accuracy of the message during the transmission process.
[0102] After the packet assembly operation is completed, the system will generate a unique message packet identifier. This message packet identifier is used to track and identify the message packet to be sent during the subsequent transmission and processing process, ensuring the uniqueness and identifiability of the message packet to be sent in the system, and providing convenience for subsequent operations.
[0103] Next, the system will set the status of multiple messages to be transmitted in the message queue to be sent, indicating that these messages have completed the process of packet assembly and identifier generation and are ready to enter the sending stage. At the same time, the system will also use the previously generated message package identifier to mark these messages to be transmitted, so as to facilitate the subsequent tracking and monitoring of the sending status.
[0104] 207. Perform a batch sending operation on the message packets to be sent. After the batch sending operation is successfully executed, use the message packet identifier to query the sending status corresponding to each message to be transmitted. In the message queue, use the queried sending status to update the status corresponding to the corresponding message to be transmitted.
[0105] In the embodiment of the present application, after the message package to be sent is generated, a batch sending operation can be performed on the message package to be sent. When the batch sending operation is successfully executed, since the messages in the current message package to be sent are marked with the generated message package identifier in the above step 206, the system will use the message package identifier to query the sending status corresponding to each message to be transmitted, so as to achieve accurate tracking and real-time feedback of the message sending status. Through the message package identifier, the system can quickly and accurately locate the sending status of each message to be transmitted, including key information such as whether it is successfully sent, the specific time of sending, whether there is an error or abnormality, etc.
[0106] Subsequently, in the message queue, the system will update the status of the corresponding message to be transmitted in real time according to the queried sending status. Specifically, if a message to be transmitted is successfully sent, its corresponding status can be updated to "sent"; on the contrary, if the sending fails or other abnormal status occurs, its corresponding status can be updated to the corresponding error or abnormal status. This real-time status update mechanism can ensure the transparency and traceability of the message transmission process, and help the system to promptly discover and solve potential problems.
[0107] Thus, in the above process, the message packet identification system can realize blocking operation. The system ensures that after the batch message group is sent, it can wait and obtain the final sending result through blocking operation. Before the sending operation is completed or the result is not returned, the system will suspend other operations and wait for the confirmation of the final result. The blocking mechanism can ensure the integrity and accuracy of message transmission and avoid data confusion or loss caused by concurrent operations; at the same time, the system continuously updates the status corresponding to each message in the message queue in real time, which can ensure that the message transmission process is synchronized with the status in the message queue, so that the system can accurately grasp the transmission status of each message and provide reliable data support for subsequent processing or analysis.
[0108] To sum up, the overall logic of the technical solution of the present application is summarized as follows: the technical solution of the present application can be divided into two stages, namely the message receiving stage and the asynchronous packaging and sending response stage. The overall logic of the two stages is described below.
[0109] The logic of the message receiving stage is as follows Figure 2BAs shown, a request volume monitor is provided in the system, and the request control component configured in the request volume monitor can continuously receive various messages initiated by users based on the front-end service. In the message receiving stage, on the one hand, after receiving the message, the system will cache the received message in the message queue, and transfer the message in the message queue to the cache object, so that the cache object can implement message flow limiting operation based on the sliding window counter principle to ensure the stable operation of the system. Among them, when storing the message in the cache object, the message identifier of the message can be stored in the cache object with reference to the size of the message body message, and the message body message can be stored in the database. On the other hand, the system will also update the sending status of the message in the message queue in real time according to the response after the message is sent, thereby realizing the blocking operation.
[0110] The logic of the asynchronous packaging and sending response phase is as follows Figure 2C As shown, an asynchronous thread can be set up in the system, and the asynchronous thread dynamically locks based on the current query rate per second and the volume of a single packet to obtain the pending messages that need to be packaged and sent, and performs batch message package sending operations on these pending messages, so that the small-amount batch payment system receives these batch-sent messages.
[0111] In this way, the technical solution of the present application combines the dynamic monitoring of the query rate per second and the sliding window counter principle for message assembly, so that the system can more flexibly assemble messages dynamically in different message peak segments, which can not only ensure the real-time performance of batch packaging during the low-peak period of messages, but also play a certain role in current limiting and blocking during the peak period, and can have better message sending performance during the period of uniform message volume; at the same time, the technical solution of the present application greatly improves the efficiency of packaging through the flexible adjustment of the number of messages during packaging, and also greatly improves the performance of the system.
[0112] The method provided in the embodiment of the present application continuously receives messages to be transmitted, stores the received messages to be transmitted based on a cache object that stores the messages to be transmitted according to the principle of a sliding window counter, obtains the current query rate per second, and queries the single packet volume of the current single message packet, determines the message packaging strategy based on the query rate per second and the single packet volume, extracts multiple messages to be transmitted from the cache object according to the message packaging strategy, performs batch message packaging and sending operations on the multiple messages to be transmitted, combines the query rate per second and the single packet volume to realize dynamic packaging operations, and the system can maintain efficient and stable operation regardless of the low or peak of the message traffic, thereby enhancing the overall robustness of the system, ensuring stable docking with the small batch payment system, better meeting the business needs of financial institutions, and improving the efficiency and quality of payment services.
[0113] Further, as Figure 1The specific implementation of the method, the embodiment of the present application provides a device for sending batches of messages, such as Figure 3 As shown, the device includes: a storage module 301, an acquisition module 302, a determination module 303 and a packaging module 304.
[0114] The storage module 301 is used to continuously receive messages to be transmitted, and store the received messages to be transmitted based on a cache object, wherein the cache object stores the messages to be transmitted according to a sliding window counter principle;
[0115] The acquisition module 302 is used to acquire the current query rate per second and query the single packet volume of the current single message packet;
[0116] The determination module 303 is used to determine a message grouping strategy based on the query rate per second and the single packet volume;
[0117] The packaging module 304 is used to extract multiple messages to be transmitted from the cache object according to the message packaging strategy, and perform a batch message packaging and sending operation on the multiple messages to be transmitted.
[0118] In a specific application scenario, the storage module 301 is used to continuously receive messages, store the received messages in a message queue according to the message reception time; transmit the messages stored in the message queue to the cache object in sequence; determine the message to be transmitted in the received message based on the sliding window counter principle in the cache object; obtain the message body message of the message to be transmitted, and read the message volume of the message body message; and use the cache object to store the message to be transmitted with reference to the message volume.
[0119] In a specific application scenario, the storage module 301 is used to query the timestamp of each received message; determine the window time range to which the timestamp indicated by the sliding window counter principle belongs in the cache object, and read the amount of received messages corresponding to the window time range; obtain a message volume threshold, and compare the amount of received messages with the message volume threshold; when the amount of received messages is less than the message volume threshold, treat the message as the message to be transmitted; when the amount of received messages is equal to the message volume threshold, discard the message, continue to receive other messages, and compare the amount of received messages corresponding to the window time range to which other timestamps of the other messages belong with the message volume threshold to determine whether to treat the other messages as the messages to be transmitted.
[0120] In a specific application scenario, the storage module 301 is used to query a preset volume threshold and compare the message volume with the preset volume threshold; when the message volume is less than or equal to the preset volume threshold, the message to be transmitted is stored in the cache object; when the message volume is greater than the preset volume threshold, the message identifier of the message to be transmitted is obtained, the message identifier is stored in the cache object, and the message body message of the message to be transmitted is stored in the database.
[0121] In a specific application scenario, the determination module 303 is used to compare the query rate per second with the single packet volume; when the query rate per second is greater than or equal to the single packet volume, query the maximum single packet volume corresponding to the single message packet, calculate the ratio between the query rate per second and the maximum single packet volume, use the ratio as the package message volume, and generate the message package strategy including the package message volume; when the query rate per second is less than the single packet volume, query the maximum waiting time, and generate the message package strategy including the maximum waiting time.
[0122] In a specific application scenario, the determination module 303 is used to extract, if the message grouping strategy includes the amount of grouped messages, messages to be transmitted whose number is equal to the amount of grouped messages in the cache object as the multiple messages to be transmitted; if the message grouping strategy includes the maximum waiting time, the cache time of each message to be transmitted in the cache object is queried separately, and the messages to be transmitted whose cache time is greater than or equal to the maximum waiting time are taken as the multiple messages to be transmitted.
[0123] In a specific application scenario, the package assembly module 304 is used to query the interface requirements set by the message recipient, perform a package assembly operation on the multiple messages to be transmitted according to the interface requirements, and obtain a message package to be sent; generate a message package identifier for the message package to be sent; set the status corresponding to the multiple messages to be transmitted as to be sent in the message queue, and use the message package identifier to mark the multiple messages to be transmitted; perform a batch sending operation on the message packages to be sent; after the batch sending operation is successfully executed, use the message package identifier to query the sending status corresponding to each of the messages to be transmitted; in the message queue, use the queried sending status to update the status corresponding to the corresponding message to be transmitted.
[0124] The device provided in the embodiment of the present application continuously receives messages to be transmitted, stores the received messages to be transmitted based on the cache object that stores the messages to be transmitted according to the principle of a sliding window counter, obtains the current query rate per second, and queries the single packet volume of the current single message packet, determines the message packaging strategy based on the query rate per second and the single packet volume, extracts multiple messages to be transmitted from the cache object according to the message packaging strategy, performs batch message packaging and sending operations on the multiple messages to be transmitted, combines the query rate per second and the single packet volume to realize dynamic packaging operations, and the system can maintain efficient and stable operation regardless of the low or peak of message traffic, thereby enhancing the overall robustness of the system, ensuring stable docking with the small batch payment system, better meeting the business needs of financial institutions, and improving the efficiency and quality of payment services.
[0125] It should be noted that for other corresponding descriptions of the functional units involved in the batch sending device for messages provided in the embodiment of the present application, reference can be made to Figure 1 and FIG. 2A to FIG. 2C The corresponding description in will not be repeated here.
[0126] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties.
[0127] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0128] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
[0129] In an exemplary embodiment, see Figure 4 , and also provides an electronic device, which includes a bus, a processor, a memory and a communication interface, and may also include an input and output interface and a display device, wherein each functional unit can communicate with each other through the bus. The memory stores a computer program, and the processor is used to execute the program stored in the memory and execute the batch sending method of the message in the above embodiment.
[0130] A readable storage medium stores a computer program, which implements the steps of the batch sending method of messages when executed by a processor.
[0131] Through the description of the above implementation methods, those skilled in the art can clearly understand that the present application can be implemented by hardware, or by means of software plus a necessary general hardware platform. Based on such an understanding, the technical solution of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.), including a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each implementation scenario of the present application.
[0132] Those skilled in the art will appreciate that the accompanying drawings are merely schematic diagrams of a preferred implementation scenario, and the modules or processes in the accompanying drawings are not necessarily required for implementing the present application.
[0133] Those skilled in the art will appreciate that the modules in the device in the implementation scenario can be distributed in the device in the implementation scenario according to the implementation scenario description, or can be changed accordingly and located in one or more devices different from the implementation scenario. The modules in the above implementation scenario can be combined into one module, or can be further split into multiple sub-modules.
[0134] The above application serial numbers are for description only and do not represent the advantages or disadvantages of the implementation scenarios.
[0135] The above disclosure only discloses several specific implementation scenarios of the present application. However, the present application is not limited thereto, and any changes that can be conceived by technicians in this field should fall within the scope of protection of the present application.
Claims
1. A method for sending batches of messages. It is characterized in that include: Continuously receiving messages to be transmitted, and storing the received messages to be transmitted based on a cache object, wherein the cache object stores the messages to be transmitted according to a sliding window counter principle; Get the current query rate per second and query the current single message packet size; Determining a message grouping strategy based on the query rate per second and the single packet volume; A plurality of messages to be transmitted are extracted from the cache object according to the message packaging strategy, and a batch message packaging and sending operation is performed on the plurality of messages to be transmitted.
2. The method according to claim 1, It is characterized in that The continuously receiving the to-be-transmitted message and storing the received to-be-transmitted message based on the cache object includes: Continuously receive messages and store the received messages in the message queue according to the message receiving time; Transmitting the messages stored in the message queue to the cache object in sequence; Determining the to-be-transmitted message in the received message based on the sliding window counter principle in the cache object; Obtaining the message body message of the message to be transmitted, and reading the message volume of the message body message; Referring to the message volume, the cache object is used to store the message to be transmitted.
3. The method according to claim 2, It is characterized in that The determining the message to be transmitted in the received message based on the sliding window counter principle in the cache object includes: For each message received, query the timestamp of the message; Determine in the cache object the window time range to which the timestamp indicated by the sliding window counter principle belongs, and read the amount of received messages corresponding to the window time range; Obtaining a message volume threshold, and comparing the received message volume with the message volume threshold; When the amount of received messages is less than the message amount threshold, taking the messages as the messages to be transmitted; When the amount of received messages is equal to the message amount threshold, the message is discarded, and other messages are continued to be received. The amount of received messages corresponding to the window time range to which other timestamps of the other messages belong is compared with the message amount threshold to determine whether to use the other messages as the messages to be transmitted.
4. The method according to claim 2, It is characterized in that The referring to the message volume and using the cache object to store the message to be transmitted includes: Querying a preset volume threshold, and comparing the message volume with the preset volume threshold; When the message volume is less than or equal to the preset volume threshold, storing the message to be transmitted in the cache object; When the message volume is greater than the preset volume threshold, the message identifier of the message to be transmitted is obtained, the message identifier is stored in the cache object, and the message body message of the message to be transmitted is stored in a database.
5. The method according to claim 1, It is characterized in that The determining of the message grouping strategy based on the query rate per second and the single packet volume includes: Comparing the query rate per second with the single packet volume; When the query rate per second is greater than or equal to the single packet volume, query the maximum single packet volume corresponding to the single message packet, calculate the ratio between the query rate per second and the maximum single packet volume, use the ratio as the package message volume, and generate the message package strategy including the package message volume; When the query rate per second is less than the single packet volume, the maximum waiting time is queried, and the message package strategy including the maximum waiting time is generated.
6. The method according to claim 5, It is characterized in that Extracting a plurality of messages to be transmitted from the cache object according to the message packaging strategy includes: If the message grouping strategy includes the grouped message quantity, extracting to-be-transmitted messages whose number is equal to the grouped message quantity from the cache object as the multiple to-be-transmitted messages; If the message grouping strategy includes the maximum waiting time, the cache time of each to-be-transmitted message in the cache object is queried respectively, and the to-be-transmitted messages whose cache time is greater than or equal to the maximum waiting time are taken as the multiple to-be-transmitted messages.
7. The method according to claim 2, It is characterized in that The performing a batch message grouping and sending operation on the multiple messages to be transmitted includes: Querying the interface requirements set by the message receiver, and performing a package grouping operation on the multiple messages to be transmitted according to the interface requirements to obtain a message package to be sent; Generating a message packet identifier for the message packet to be sent; Setting the states corresponding to the multiple messages to be transmitted in the message queue to be sent, and marking the multiple messages to be transmitted using the message packet identifier; Performing a batch sending operation on the message packets to be sent; After the batch sending operation is successfully executed, query the sending status corresponding to each of the to-be-transmitted messages using the message packet identifier; In the message queue, the queried sending status is used to update the status corresponding to the corresponding message to be transmitted.
8. A device for sending batches of messages, It is characterized in that include: A storage module, used for continuously receiving messages to be transmitted, and storing the received messages to be transmitted based on a cache object, wherein the cache object stores the messages to be transmitted according to a sliding window counter principle; The acquisition module is used to obtain the current query rate per second and query the single packet volume of the current single message packet; A determination module, configured to determine a message grouping strategy based on the query rate per second and the single packet volume; The package assembly module is used to extract multiple messages to be transmitted from the cache object according to the message package assembly strategy, and perform batch message package assembly and sending operations on the multiple messages to be transmitted.
9. An electronic device comprising a memory and a processor, wherein the memory stores a computer program. It is characterized in that When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A readable storage medium having a computer program stored thereon, It is characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
