WO2022089455A1 - 消息获取方法、装置、设备及存储介质 - Google Patents

消息获取方法、装置、设备及存储介质 Download PDF

Info

Publication number
WO2022089455A1
WO2022089455A1 PCT/CN2021/126543 CN2021126543W WO2022089455A1 WO 2022089455 A1 WO2022089455 A1 WO 2022089455A1 CN 2021126543 W CN2021126543 W CN 2021126543W WO 2022089455 A1 WO2022089455 A1 WO 2022089455A1
Authority
WO
WIPO (PCT)
Prior art keywords
message
sequence number
server
confirmation
maximum
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Ceased
Application number
PCT/CN2021/126543
Other languages
English (en)
French (fr)
Inventor
邓昊
林镇泽
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Bigo Technology Pte Ltd
Original Assignee
Bigo Technology Pte Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Bigo Technology Pte Ltd filed Critical Bigo Technology Pte Ltd
Publication of WO2022089455A1 publication Critical patent/WO2022089455A1/zh
Anticipated expiration legal-status Critical
Ceased legal-status Critical Current

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L1/00Arrangements for detecting or preventing errors in the information received
    • H04L1/12Arrangements for detecting or preventing errors in the information received by using return channel
    • H04L1/16Arrangements for detecting or preventing errors in the information received by using return channel in which the return channel carries supervisory signals, e.g. repetition request signals
    • H04L1/18Automatic repetition systems, e.g. Van Duuren systems
    • H04L1/1867Arrangements specially adapted for the transmitter end
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L1/00Arrangements for detecting or preventing errors in the information received
    • H04L1/12Arrangements for detecting or preventing errors in the information received by using return channel
    • H04L1/16Arrangements for detecting or preventing errors in the information received by using return channel in which the return channel carries supervisory signals, e.g. repetition request signals
    • H04L1/1607Details of the supervisory signal

Definitions

  • the embodiments of the present application relate to the field of communication technologies, for example, to a message acquisition method, apparatus, device, and storage medium.
  • the sender sends a message to the server through the client, the server notifies the recipient client of the arrival of the new message in some form, and the recipient client receives the server. After the notification, it actively obtains the newly arrived message from the server, and then the server sets the new message to the read state. When the client comes to get the new message next time, it will not be able to get the message.
  • the client may not be able to receive the notification of the arrival of a new message, or the obtained messages may be in disorder, or the same message may be obtained repeatedly due to the failure to set the read status of the message.
  • the server After the sender sends a message to the server, the server generates a unique self-incrementing sequence number for the receiver (referred to as id, that is, the message sequence number, the initial value of which is 1, and every new message is received. On the basis of the original value, add 1) to identify this message and store it in the database.
  • the client After the client obtains the message from the server, it immediately records the maximum id in the obtained message set (recorded as ackid, that is, the confirmation sequence number, Its initial value is 0) is returned to the server and saved.
  • the server finds all messages with an id greater than ackid in the message list of the receiver stored in the database and returns it to the client, and then the client immediately retrieves the largest message from the returned message set.
  • the id is returned to the server, and the server updates the value of ackid to the new value received.
  • the client After that, it is successfully stored on the server, and the client cannot receive the message with a small id value; for example, the message is lost during the sending process), which may still cause the loss of the message, that is, the client cannot obtain some messages. . Therefore, the message acquisition scheme in the related art is still not perfect and needs to be improved.
  • the embodiments of the present application provide a message acquisition method, apparatus, device, and storage medium, which can improve the message acquisition solution in the related art.
  • an embodiment of the present application provides a method for acquiring a message, which is applied to a client, including:
  • the maximum message sequence number is fed back to the server, where the maximum message sequence number is used to instruct the server to update the confirmation sequence number to the maximum message sequence number , the preset duration is greater than the time interval from the initiation time to the first repeated initiation of the message acquisition request.
  • an embodiment of the present application provides a message acquisition device, which is configured on a client and includes:
  • the initiation time recording module is configured to initiate a message acquisition request to the server, and record the initiation time of this request, wherein the message acquisition request is used to instruct the server to return a message whose message sequence number is greater than the confirmation sequence number, and the confirmation
  • the sequence number is stored in the server, and the message sequence number is incrementally configured by the server according to the order in which messages are received;
  • the maximum message sequence number recording module is set to receive the message returned by the server, and record the maximum message sequence number in the received message
  • a message repeated acquisition module configured to repeatedly initiate a message acquisition request to the server, and receive a message returned by the server;
  • the maximum message sequence number feedback module is configured to feed back the maximum message sequence number to the server after a preset time period from the initiation time, wherein the maximum message sequence number is used to instruct the server to confirm the confirmation
  • the sequence number is updated to the maximum message sequence number, and the preset duration is greater than the time interval from the initiation time to the first repeated initiation of the message acquisition request.
  • an embodiment of the present application provides a computer device, including a memory, a processor, and a computer program stored in the memory and running on the processor, the processor implementing the computer program as described in the present application when the processor executes the computer program.
  • the message acquisition method provided by the embodiment.
  • embodiments of the present application provide a computer-readable storage medium on which a computer program is stored, and when the program is executed by a processor, implements the message acquisition method provided by the embodiments of the present application.
  • FIG. 1 is a scene architecture diagram of an application scenario to which a message acquisition method provided by an embodiment of the present application is applicable;
  • FIG. 2 is a schematic flowchart of a method for acquiring a message according to an embodiment of the present application
  • FIG. 3 is a schematic flowchart of another message acquisition method provided by an embodiment of the present application.
  • FIG. 4 is a schematic diagram of a message acquisition sequence provided by an embodiment of the present application.
  • FIG. 5 is a schematic flowchart of still another message acquisition method provided by an embodiment of the present application.
  • FIG. 6 is a schematic flowchart of another message acquisition method provided by an embodiment of the present application.
  • FIG. 7 is a structural block diagram of a message acquisition apparatus provided by an embodiment of the present application.
  • FIG. 8 is a structural block diagram of a computer device according to an embodiment of the present application.
  • FIG. 1 is a scene architecture diagram of an application scenario to which a message acquisition method provided by an embodiment of the present application is applicable.
  • the application scenario may include a client 101 and a server 102, and the client 101 may be any communication application, such as an IM application.
  • the client 101 may be any communication application, such as an IM application.
  • the server 102 can add a current timestamp to the message body, and then write the message to the message queue, and return the message to the message queue after successful writing.
  • User B's message is sent successfully.
  • the message queue consumer in the server 102 reads the message, and generates a unique self-incrementing id (that is, the message sequence number) for the read message. Assuming that user A is a new user, the initial value of the id can be 1, and then from 1 add), and then write the message to the database. After the writing to the database is successful, set the message in the message queue to have been consumed, and you can notify the client 101 of user A that a new message arrives (or not notify, but wait for the client The terminal 101 actively initiates a message acquisition request).
  • a confirmation sequence number is stored in the server 102 , and the confirmation sequence number may indicate that the message whose message sequence number corresponding to the user A stored in the database is less than or equal to the confirmation sequence number has been returned to the client 101 .
  • the client 101 after the client 101 initiates a message acquisition request to the server 102 and receives the message returned by the server 102, it will immediately feed back the maximum message sequence number in the received message to the server 102, and the server 102 will send the message back to the server 102.
  • the originally stored confirmation sequence number is updated to the maximum message sequence number just received.
  • a message with a message sequence number greater than the updated confirmation sequence number will be returned to the client 101.
  • the server 102 stores these messages in the database in a concurrent storage manner. b, message a arrives at the server 102 before message b.
  • the message sequence number of message a is smaller than the message sequence number of message b, but when message a and message b are stored concurrently, message b is successfully stored before message a.
  • the client 101 initiates a message acquisition request.
  • the server 102 cannot return the message a to the client 101, but the message b can be received by the client 101.
  • the client 101 will immediately return the message sequence number of message b to the server 102, and the server 102 will update the locally stored confirmation sequence number to the message sequence number of b, then when the client 101 initiates a message acquisition request again, Since the message sequence number of message a is smaller than the message sequence number of message b, it will not be returned by the server 102 to the client 101. Even after updating the locally stored acknowledgment sequence number to the message sequence number of b, the message sequence number smaller than b will be changed. The message of the message sequence number is deleted (including the message a). Therefore, the client's message acquisition is missing. In addition, if the message is returned, the message may be lost due to factors such as network instability.
  • the client 101 after receiving the message returned by the server 102, the client 101 delays feeding back the maximum message number, which can improve the probability of the message being successfully acquired, realize redundant acquisition of the message, and effectively improve the client's missing message acquisition. Condition.
  • FIG. 2 is a schematic flowchart of a message acquisition method provided by an embodiment of the present application.
  • the method may be executed by a message acquisition apparatus, where the apparatus may be implemented by software and/or hardware, and may generally be integrated in a computer device serving as a client.
  • the computer device may be a mobile terminal such as a mobile phone, a tablet computer, or a notebook computer, or a fixed terminal such as a desktop computer, which is not specifically limited.
  • the method includes:
  • Step 201 initiate a message acquisition request to the server, and record the initiation time of the request, wherein the message acquisition request is used to instruct the server to return a message whose message sequence number is greater than the confirmation sequence number, and the confirmation sequence number is stored in the In the server, the message sequence number is configured incrementally by the server according to the order in which messages are received.
  • the specific timing for the client to initiate a message acquisition request to the server is not limited. For example, it may include when the client is detected to be started (that is, when the user opens the client), or when the server receives the request.
  • a new message to be sent reaches a notification (eg, a push notification)
  • the message acquisition request may be a message pull request.
  • the server queries the message whose message sequence number is greater than the current confirmation sequence number stored by the server, and sends the queried message to the client.
  • the confirmation sequence number currently stored by the server is 6, and the messages with message sequence numbers greater than 6 stored in the database include message 7, message 8, and message 10, but message 9 was not successfully stored in the database at this time. Therefore, the server cannot query it. message 9, then the server will return message 7, message 8 and message 10 to the client.
  • the client when the client initiates a message acquisition request to the server, it can record the initiation time of the request, which can be used to determine the timing of subsequent feedback of the maximum message sequence number and the maximum message sequence number that needs to be fed back.
  • Step 202 Receive the message returned by the server, and record the maximum message sequence number in the received messages.
  • the client receives the message returned by the server for this request, and if there is no exception during the receiving process, the client can successfully receive message 7, message 8, and message 10. However, if affected by factors such as network instability, the client may not be able to receive all the messages returned by the server. Assuming that message 8 is lost during the sending process, the client can only receive message 7 and message 10.
  • the client After receiving the message returned by the server, the client checks the message sequence numbers of multiple received messages, and records the largest message sequence number among them. For example, the maximum message sequence number is 10. In the related art, the client will immediately feed back the sequence number 10 to the server, and the server will update the original confirmation sequence number 6 to 10. When receiving a message acquisition request from the client subsequently, the sequence number 10 and previous messages are not will be returned to the client.
  • the origination time recorded in step 201 and the maximum message sequence number recorded in step 202 can be bound and stored, so that when the maximum message sequence number needs to be fed back later, the corresponding maximum message sequence number can be queried according to the corresponding origination time. .
  • Step 203 Repeatedly initiate a message acquisition request to the server, and receive a message returned by the server.
  • the server after the maximum message sequence number is obtained, it will not immediately feed back to the server, but repeatedly initiate a message acquisition request to the server.
  • the timing and the number of repetitions of the repeated request are not limited. Assuming that the number of repetitions is 1, and the time when the request is repeatedly initiated is the time interval between the above recorded initiation time and the first time interval, then after the first time interval, the previously unsuccessfully stored messages may have been stored successfully.
  • the confirmation sequence number of has not been updated, then the server will return the message that the storage is successful to the client. For example, after the first time interval, message 9 may have been successfully stored.
  • the messages with message sequence numbers greater than 6 stored in the database include message 7, message 8, message 9, and message 10. At this time, since the confirmation sequence number of the server is still is 6, therefore, it can be queried that the messages include message 7, message 8, message 9 and message 10, and return it to the client.
  • the client when the client receives the message returned by the server again, the network condition may have changed, and may receive message 7, message 8, message 9 and message 10 completely, or even if the network is still unstable, the client may succeed Message 9 is received, while other messages (eg, message 10) are lost.
  • Step 204 Feed back the maximum message sequence number to the server after a preset time period from the initiation time, where the maximum message sequence number is used to instruct the server to update the confirmation sequence number to the The maximum message sequence number, where the preset duration is greater than the time interval from the initiation time to the first repeated initiation of a message acquisition request.
  • the preset duration can also be understood as the duration of delayed feedback, which can be set according to actual conditions, such as 3 minutes. After the preset time period has elapsed, the previously recorded maximum message sequence number is promptly fed back to the server, so that the server updates the stored confirmation sequence number, so as to control the number of messages returned in subsequent response to the message acquisition request. It can be understood that the preset duration is greater than the time interval from the initiation time to the first repeated initiation of the message acquisition request, that is, greater than the above-mentioned first time interval.
  • the message acquisition method initiates a message acquisition request to the server, and records the initiation time of this request.
  • the message acquisition request is used to instruct the server to return a message whose message sequence number is greater than its stored confirmation sequence number, and receive the service.
  • the message returned by the server, and record the maximum message sequence number in the received message repeatedly initiate a message acquisition request to the server and receive the message returned by the server, after a preset time period from the initiation time, feedback the Maximum message sequence number, instructs the server to update the confirmation sequence number to the maximum message sequence number.
  • the client after receiving the message returned by the server, the client first records the maximum message number, but does not feed back the maximum message number to the server for the time being, but returns it after a period of time. During this period, the message acquisition request is repeatedly sent to the server. Since the confirmation sequence number of the server has not changed, some messages will be returned repeatedly, which can improve the probability of successful acquisition of messages and realize redundant acquisition of messages, which can effectively Improve the situation that the client's message acquisition is missing due to the reason that the message with the highest sequence number is not successfully stored on the server in time or the network condition is unstable.
  • the method further includes: performing deduplication processing on the received message according to the message sequence number.
  • the message sequence number is incrementally configured by the server according to the order of message reception, that is to say, each message has a unique and self-incrementing id. Therefore, deduplication can be performed based on the order of the message ids. If there are multiple messages corresponding to the same id message, it means that there are duplicates, and only one message is reserved for each id.
  • the received message may be deduplicated according to the message sequence number. In this way, deduplication processing can be performed every time a message is obtained, preventing duplicate messages from staying on the client for too long, and further saving the storage space of the client.
  • FIG. 3 is a schematic flowchart of another message acquisition method provided by an embodiment of the present application.
  • the technical details of repeatedly initiating a message acquisition request to a server and receiving a message returned by the server are refined.
  • the repeatedly initiating a message acquisition request to the server, and receiving the message returned by the server includes: repeatedly initiating a message acquisition request to the server for a preset number of times with a preset acquisition cycle, and Receive the message returned by the server.
  • the message acquisition request can be repeatedly initiated periodically, and the initiation timing of the message acquisition request can be managed more reasonably, which is beneficial to the superposition of the message cycle acquisition period.
  • the content of the message loop acquisition cycle will be described in detail below.
  • the method may include:
  • Step 301 initiate a message acquisition request to the server, and record the initiation time of this request.
  • the message acquisition request is used to instruct the server to return a message whose message sequence number is greater than the confirmation sequence number, the confirmation sequence number is stored in the server, and the message sequence number is incremented by the server according to the order of message reception configuration.
  • the client initiates the message acquisition request by means of timing triggering, and the timing triggering manner may be periodic triggering.
  • Step 302 Receive the message returned by the server, and record the maximum message sequence number in the received messages.
  • Step 303 Repeatedly initiate a message acquisition request to the server for a preset number of times with a preset acquisition cycle, receive a message returned by the server, and perform deduplication processing on the received message according to the message sequence number.
  • the trigger period corresponding to the periodic trigger initiation message acquisition request may be equal to the preset acquisition period.
  • the ackid of the server is 7, and the initiation time is recorded as t0.
  • the messages stored in the server with a sequence number greater than 7 include message 8 and message 10, and return message 8 and message 10 to the client. Assuming that regardless of network factors, the client can successfully receive the message returned by the server, then the client can receive the message.
  • Step 304 Feed back the maximum message sequence number to the server after a preset time period has elapsed from the initiation time.
  • the maximum message sequence number is used to instruct the server to update the confirmation sequence number to the maximum message sequence number.
  • the preset duration is a multiple of a preset acquisition period, and the multiple is greater than or equal to the preset number of times.
  • the multiple may be equal to a preset number of times.
  • the client can receive message 8, message 9, message 10, and message 11 when the message acquisition request is repeated for the second time.
  • the origination time of a message request may be used as the starting point
  • the time at which the maximum message sequence number is fed back to the server may be used as the ending point
  • the elapsed time between the starting point and the ending point may be referred to as the message cycle acquisition period T.
  • T the message cycle acquisition period
  • each message has the opportunity to be acquired K times, that is, on the basis of being acquired for the first time, it is repeatedly acquired K times.
  • the messages in each time period a have The opportunity is repeatedly acquired by the client K times (as shown in the message 11 in the figure, after the server responds to the request at time t2, message 11 is acquired for the first time, and is acquired twice after the following time t3 and t4), this application Embodiments refer to this acquisition as redundant acquisition.
  • the maximum sequence number of the message in each time period a is delayed by K*a time before it is sent by the client to the server to update the ackid, which is referred to as delayed acknowledgment in this embodiment of the present application. Since each message has a unique and self-incrementing id, the client will compare it with the local after obtaining the message, discard the locally existing message, and keep the non-existing message.
  • the display order of the messages on the client is also based on the message id. sequence, this method is referred to as deduplication based on a unique sequence number in this embodiment of the present application.
  • the embodiment of the present application adopts a combination of redundant acquisition, delayed confirmation, and deduplication based on a unique sequence number, so that the new message notification is chaotic due to messages being written to the database out of sequence or other situations.
  • a new message arrives at the client in order, or the new message notification is lost for some reason, it can still ensure that the state of the server and the client is eventually consistent, that is, the message is not out of order, repeated or lost, which improves the reliability and accuracy of the instant messaging system. sex.
  • FIG. 5 is a schematic flowchart of still another message acquisition method provided by an embodiment of the present application. On the basis of the above embodiment, the technical details of feeding back the maximum message sequence number to the server are refined.
  • the feeding back the maximum message sequence number to the server includes: judging whether the maximum message sequence number is greater than a local confirmation sequence number, wherein the local confirmation sequence number is consistent with the confirmation sequence number stored by the current server; If the maximum message sequence number is greater than the local acknowledgment sequence number, the maximum message sequence number is fed back to the server, and the local acknowledgment sequence number is updated to the maximum message sequence number. In this way, the maximum message sequence number can be fed back to the server only when it is necessary to update, reducing data interaction.
  • the method before initiating a message acquisition request to the server and recording the initiation time of this request, the method further includes: acquiring the confirmation sequence number stored in the server, and marking the acquired confirmation sequence number as the local confirmation sequence number. This can ensure the accuracy of the local confirmation serial number.
  • the acquiring the confirmation sequence number stored in the server includes: after detecting that the client is started, acquiring the confirmation sequence number stored in the server.
  • the confirmation serial number can be obtained in time when the client is started to ensure the accuracy of the local confirmation serial number.
  • the method may include:
  • Step 501 When it is detected that the client is started, obtain the confirmation serial number stored in the server, and record the obtained confirmation serial number as the local confirmation serial number.
  • Step 502 initiate a message acquisition request to the server, and record the initiation time of this request.
  • Step 503 Receive the message returned by the server, and record the maximum message sequence number in the received messages.
  • Step 504 Repeatedly initiate a message acquisition request to the server for a preset number of times with a preset acquisition cycle, receive a message returned by the server, and perform deduplication processing on the received message according to the message sequence number.
  • Step 505 After the preset time period has elapsed from the initiation time, determine whether the maximum message sequence number corresponding to the initiation time is greater than the local confirmation sequence number, and based on the judgment result that the maximum message sequence number corresponding to the initiation time is greater than the local confirmation sequence number, perform step 506; based on the initiation time If the corresponding maximum message sequence number is less than or equal to the determination result of the local confirmation sequence number, the process returns to step 502.
  • Step 506 Feed back the maximum message sequence number to the server, update the local confirmation sequence number to the maximum message sequence number, and return to step 502.
  • the embodiment of the present application acquires the confirmation sequence number of the server when the client starts and records it locally on the client, and sends Before the server sends the maximum message sequence number, it determines whether the maximum message sequence number is greater than the local confirmation sequence number. Based on the judgment result that the maximum message sequence number is greater than the local confirmation sequence number, the server sends the maximum message sequence number, so that the maximum message sequence number is fed back to the server only when it is necessary to update. Reduce data interaction.
  • FIG. 6 is a schematic flowchart of another message acquisition method provided by an embodiment of the present application. On the basis of the above-mentioned embodiment, the case where the client is not online for a long time is refined.
  • the method before initiating a message acquisition request to the server and recording the initiation time of this request, the method further includes: when detecting that the client is started, initiating a message acquisition request to the server, and receiving the service determine whether the total number of received messages is greater than the preset threshold, and determine the target confirmation sequence number based on the judgment result that the total number of received messages is greater than the preset threshold; send the Target confirmation sequence number, wherein the target confirmation sequence number is used to instruct the server to update the confirmation sequence number to the target confirmation sequence number, where the target confirmation sequence number is smaller than the maximum message sequence number in the received messages. In this way, the confirmation sequence number of the server can be updated more reasonably.
  • determining the target acknowledgment sequence number may include: obtaining a packet return timestamp when the server returns a message; filtering out a target message in the received messages, wherein the message timestamp in the target message is the same as the all The sum of the preset duration is less than or equal to the packet return time stamp; and the maximum message sequence number in the target message is determined as the target confirmation sequence number. In this way, the target confirmation sequence number can be determined more reasonably.
  • the method includes:
  • Step 601 When detecting that the client is started, initiate a message acquisition request to the server, and receive a message returned by the server.
  • Step 602 judging whether the total number of received messages is greater than the preset threshold, and based on the judgment result that the total number of received messages is greater than the preset threshold, perform step 603; based on the total number of received messages less than or If the judgment result is equal to the preset threshold, step 606 is executed.
  • the server will have a backlog of unread messages. Therefore, whether such a situation exists may be determined by judging whether the total number of messages is greater than a preset threshold.
  • the preset threshold can be set according to actual needs, and is not specifically limited.
  • Step 603 Obtain the packet return timestamp when the server returns the message, and filter out the target message in the received message.
  • the sum of the message timestamp in the target message and the preset duration is less than or equal to the return packet timestamp.
  • the timestamp msg_t in each message can be retrieved, that is, the message timestamp.
  • the preset duration is K*a
  • the target message is the message whose msg_t+K*a is less than t.
  • Step 604 Determine the maximum message sequence number in the target message as the target confirmation sequence number, and send the target confirmation sequence number to the server.
  • the target confirmation sequence number is used to instruct the server to update the confirmation sequence number to the target confirmation sequence number.
  • Step 605 mark the target confirmation sequence number as the local confirmation sequence number, and execute step 607 .
  • Step 606 Acquire the confirmation sequence number stored in the server, and record the acquired confirmation sequence number as the local confirmation sequence number.
  • Step 607 initiate a message acquisition request to the server, and record the initiation time of this request.
  • Step 608 Receive the message returned by the server, and record the maximum message sequence number in the received messages.
  • Step 609 Repeat the message acquisition request to the server for a preset number of times with a preset acquisition cycle, receive the message returned by the server, and perform deduplication processing on the received message according to the message sequence number.
  • Step 610 After a preset time period from the initiation time, determine whether the maximum message sequence number corresponding to the initiation time is greater than the local confirmation sequence number, and based on the judgment result that the maximum message sequence number corresponding to the initiation time is greater than the local confirmation sequence number, perform step 611; based on the initiation time If the corresponding maximum message sequence number is less than or equal to the determination result of the local confirmation sequence number, the process returns to step 607 .
  • Step 611 Feed back the maximum message sequence number to the server, and update the local confirmation sequence number to the maximum message sequence number.
  • the embodiment of the present application is optimized for the situation that the client has not been online for a long time. If it is determined that there are many unread messages in the backlog, several unread messages that are closer to the current moment can be regarded as repeated For the acquired target, determine the target confirmation sequence number and feed it back to the server to update the confirmation sequence number, so that in the subsequent message acquisition process, recent messages can be repeatedly acquired to ensure that recent messages are successfully acquired.
  • FIG. 7 is a structural block diagram of a message acquisition apparatus provided by an embodiment of the present application.
  • the apparatus may be implemented by software and/or hardware, and may generally be integrated in a computer device serving as a client.
  • Message acquisition may be performed by executing a message acquisition method.
  • the device includes:
  • the initiation time recording module 701 is configured to initiate a message acquisition request to the server, and record the initiation time of this request, wherein the message acquisition request is used to instruct the server to return a message whose message sequence number is greater than the confirmation sequence number, and the The confirmation sequence number is stored in the server, and the message sequence number is incrementally configured by the server according to the order of message reception;
  • the maximum message sequence number recording module 702 is configured to receive the message returned by the server, and record the maximum message sequence number in the received message;
  • the message repetition acquisition module 703 is configured to repeatedly initiate a message acquisition request to the server, and receive a message returned by the server;
  • the maximum message sequence number feedback module 704 is configured to feed back the maximum message sequence number to the server after a preset duration from the initiation time, wherein the maximum message sequence number is used to instruct the server to send the message to the server.
  • the confirmation sequence number is updated to the maximum message sequence number, and the preset duration is greater than the time interval from the initiation time to the first repeated initiation of the message acquisition request.
  • the message acquisition device initiates a message acquisition request to the server, and records the initiation time of this request.
  • the message acquisition request is used to instruct the server to return a message whose message sequence number is greater than the stored confirmation sequence number, and receives the server.
  • Return the message, and record the maximum message sequence number in the received message repeatedly initiate a message acquisition request to the server and receive the message returned by the server, after a preset time period from the initiation time, feedback the maximum message to the server.
  • Message sequence number instructing the server to update the confirmation sequence number to the maximum message sequence number.
  • the client After the client receives the message returned by the server, it first records the maximum message number, but does not feed back the maximum message number to the server for the time being, but returns it after a period of time. During this period, the message acquisition request is repeatedly sent to the server. Since the confirmation sequence number of the server has not changed, some messages will be returned repeatedly, which can improve the probability of successful acquisition of messages, realize redundant acquisition of messages, and effectively improve the The client's message acquisition is missing.
  • FIG. 8 is a structural block diagram of a computer device according to an embodiment of the present application.
  • the computer device 800 includes a memory 801, a processor 802, and a computer program stored in the memory 801 and running on the processor 802. When the processor 802 executes the computer program, the method for obtaining a message provided by the embodiments of the present application is implemented.
  • the embodiments of the present application further provide a storage medium containing computer-executable instructions, where the computer-executable instructions are used to execute the message acquisition method provided by the embodiments of the present application when executed by a computer processor.
  • the storage medium may be a non-transitory computer-readable storage medium.
  • the message obtaining apparatus, device and storage medium provided in the above embodiments can execute the message obtaining method provided by any embodiment of the present application, and have corresponding functional modules and beneficial effects for executing the method.
  • the message acquisition method provided by any embodiment of the present application.

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Information Transfer Between Computers (AREA)

Abstract

本申请实施例公开了消息获取方法、装置、设备及存储介质。其中,该方法包括:向服务端发起消息获取请求,并记录本次请求的发起时间,消息获取请求用于指示服务端返回消息序号大于确认序号的消息,接收服务端返回的消息,并记录所接收到的消息中的最大消息序号,重复向服务端发起消息获取请求,并接收服务端返回的消息,从发起时间起经过预设时长后,向服务端反馈所述最大消息序号,其中,最大消息序号用于指示服务端将确认序号更新为所述最大消息序号。

Description

消息获取方法、装置、设备及存储介质
本申请要求在2020年10月28日提交中国专利局、申请号为202011173739.4的中国专利申请的优先权,该申请的全部内容通过引用结合在本申请中。
技术领域
本申请实施例涉及通信技术领域,例如涉及消息获取方法、装置、设备及存储介质。
背景技术
随着通信技术及互联网技术的快速发展,人与人之间的基于网络的信息交互越来越频繁,消息数量骤增。
以即时通信(Instant Messaging,IM)系统为例,发送者通过客户端发送一条消息到达服务端,服务端将新消息到达以某种形式通知给接收者客户端,接收者客户端收到服务端通知后主动从服务端获取新到达的消息,然后服务端将新消息置为已读状态,当客户端下次过来获取新消息时候,就获取不到这条消息了。目前,由于服务端与客户端的网络连接状况的不确定性,导致客户端可能无法收到新消息到达的通知,或者获取到的消息顺序错乱,抑或因设置消息已读状态失败导致重复获取到同样的消息等等,这些情况造成了服务端与客户端之间的数据状态不一致,严重影响了IM功能的正确性和用户的使用体验。
相关技术中,发送者发送一条消息到达服务端后,服务端针对接收者生成一个唯一的自增序号(记为id,也即消息序号,其初始值为1,每接收到一条新消息都在原值的基础上加1)来标识这条消息,并存储到数据库中,客户端从服务端获取消息后,立即将获取到的消息集合中的最大id(记为ackid,也即确认序号,其初始值为0)返回给服务端保存起来。这样下次客户端再向服务端获取消息时,服务端在数据库存储的接收者的消息列表中找出id大于ackid的所有消息返回给客户端,然后客户端立即从返回的消息集合里取出最大id返回给服务端,服务端更新ackid的值为接收到的新值。这种方案在大部分场景下可以有效避免消息的乱序和重复,但是在一些特殊情况下(如在高并发情况下,id值较小的消息在id值较大的消息被客户端确认收到后,才成功在服务端存储下来, 客户端就不能接收到id值较小的消息;又如消息在发送过程中丢失),仍然可能造成消息的丢失,即客户端获取不到某些消息。因此,相关技术中的消息获取方案仍不够完善,需要改进。
发明内容
本申请实施例提供了消息获取方法、装置、设备及存储介质,可以改善相关技术中的消息获取方案。
第一方面,本申请实施例提供了一种消息获取方法,应用于客户端,包括:
向服务端发起消息获取请求,并记录本次请求的发起时间,其中,所述消息获取请求用于指示所述服务端返回消息序号大于确认序号的消息,所述确认序号存储于所述服务端中,所述消息序号由所述服务端根据消息接收顺序进行递增配置;
接收所述服务端返回的消息,并记录所接收到的消息中的最大消息序号;
重复向所述服务端发起消息获取请求,并接收所述服务端返回的消息;
从所述发起时间起经过预设时长后,向所述服务端反馈所述最大消息序号,其中,所述最大消息序号用于指示所述服务端将所述确认序号更新为所述最大消息序号,所述预设时长大于从所述发起时间到首次重复发起消息获取请求之间的时间间隔。
第二方面,本申请实施例提供了一种消息获取装置,配置于客户端,包括:
发起时间记录模块,设置为向服务端发起消息获取请求,并记录本次请求的发起时间,其中,所述消息获取请求用于指示所述服务端返回消息序号大于确认序号的消息,所述确认序号存储于所述服务端中,所述消息序号由所述服务端根据消息接收顺序进行递增配置;
最大消息序号记录模块,设置为接收所述服务端返回的消息,并记录所接收到的消息中的最大消息序号;
消息重复获取模块,设置为重复向所述服务端发起消息获取请求,并接收所述服务端返回的消息;
最大消息序号反馈模块,设置为从所述发起时间起经过预设时长后,向所述服务端反馈所述最大消息序号,其中,所述最大消息序号用于指示所述服务端将所述确认序号更新为所述最大消息序号,所述预设时长大于从所述发起时间到首次重复发起消息获取请求之间的时间间隔。
第三方面,本申请实施例提供了一种计算机设备,包括存储器、处理器及存储在存储器上并可在处理器上运行的计算机程序,所述处理器执行所述计算机程序时实现如本申请实施例提供的消息获取方法。
第四方面,本申请实施例提供了一种计算机可读存储介质,其上存储有计算机程序,该程序被处理器执行时实现如本申请实施例提供的消息获取方法。
附图说明
图1为本申请实施例提供的一种消息获取方法所适用的应用场景的场景架构图;
图2为本申请实施例提供的一种消息获取方法的流程示意图;
图3为本申请实施例提供的又一种消息获取方法的流程示意图;
图4为本申请实施例提供的一种消息获取时序示意图;
图5为本申请实施例提供的再一种消息获取方法的流程示意图;
图6为本申请实施例提供的另一种消息获取方法的流程示意图;
图7为本申请实施例提供的一种消息获取装置的结构框图;
图8为本申请实施例提供的一种计算机设备的结构框图。
具体实施方式
下面结合附图和实施例对本申请作进一步的详细说明。可以理解的是,此处所描述的具体实施例仅仅用于解释本申请,而非对本申请的限定。另外还需要说明的是,为了便于描述,附图中仅示出了与本申请相关的部分而非全部结构。此外,在不冲突的情况下,本申请中的实施例及实施例中的特征可以相互组合。
图1为本申请实施例提供的一种消息获取方法所适用的应用场景的场景架构图。例如,参考图1,该应用场景中可以包括客户端101和服务端102,客户端101可以是任意的通信应用程序,例如IM应用等。假设客户端101的使用者为用户A,当其他用户向用户A发送消息时,消息会先到达服务端102。示例性的,假设用户B发送给用户A的消息到达服务端102后,服务端102可以在消息体中添加一个当前时间戳,然后将消息写入到消息队列,写入消息队列成功后返回给用户B消息发送成功。服务端102中的消息队列消费者读出消息,为读出的消息生成一个唯一自增id(也即消息序号,假设用户A为新用户,则 id初始值可以为1,然后从1开始自增),随后将消息写入到数据库,在写入数据库成功后,设置消息队列中该消息已被消费,可以通知用户A的客户端101有新消息到达(也可以不通知,而是等客户端101主动发起消息获取请求)。服务端102中存储有确认序号,该确认序号可以表示数据库中存储的用户A对应的消息序号小于或等于确认序号的消息已经返回给客户端101。
相关技术中,客户端101向服务端102发起消息获取请求并接收服务端102返回的消息后,会立即将所接收到的消息中的最大消息序号反馈给服务端102,服务端102就会将原来存储的确认序号更新为刚刚接收到的最大消息序号,下次再接收到客户端101发起的消息获取请求时,就会将消息序号大于更新后的确认序号的消息返回给客户端101。然而,在一些特殊情况下,如其他用户同一时段内向用户A发送的消息数量较多,服务端102采用并发存储的方式将这些消息存储到数据库中,假设对于多条消息中的消息a和消息b,消息a先于消息b到达服务端102,因此,消息a的消息序号小于消息b的消息序号,但对消息a和消息b进行并发存储时,消息b先于消息a存储成功,而在消息a存储成功之前,客户端101发起了消息获取请求,此时服务端102就无法将消息a返回给客户端101,但消息b能够被客户端101接收,因此,若消息b的消息序号为最大消息序号,则客户端101会立即向服务端102反馈消息b的消息序号,服务端102会将本地存储的确认序号更新为b的消息序号,那么当客户端101再次发起消息获取请求时,由于消息a的消息序号小于消息b的消息序号,因此不会被服务端102返回给客户端101,甚至可能在将本地存储的确认序号更新为b的消息序号之后,就将消息序号小于b的消息序号的消息删除(包括消息a),因此,就会出现客户端的消息获取缺失情况。另外,若在消息返回过程中,由于网络不稳定等因素,也可能出现消息丢失。
本申请实施例中,客户端101在接收到服务端102返回的消息后,延迟反馈最大消息号,能够提高消息被成功获取的概率,实现消息的冗余获取,有效改善客户端的消息获取缺失的情况。
图2为本申请实施例提供的一种消息获取方法的流程示意图,该方法可以由消息获取装置执行,其中该装置可由软件和/或硬件实现,一般可集成在作为客户端的计算机设备中。其中,计算机设备可以是手机、平板电脑、笔记本电脑等移动终端,也可以是台式机等固定终端,具体不做限定。如图2所示,该方法包括:
步骤201、向服务端发起消息获取请求,并记录本次请求的发起时间,其中,所述消息获取请求用于指示所述服务端返回消息序号大于确认序号的消息,所述确认序号存储于所述服务端中,所述消息序号由所述服务端根据消息接收顺序进行递增配置。
本申请实施例中,对客户端向服务端发起消息获取请求的具体时机不做限定,例如,可以包括检测到客户端启动时(也即用户打开客户端时),还可以包括接收到服务端发送的新消息达到通知(如推送(Push)通知)时,还可以包括客户端定时触发(如周期性触发)发起消息获取请求。
示例性的,消息获取请求可以是消息拉取请求,服务端在接收到消息获取请求后,查询服务端存储的消息序号大于当前确认序号的消息,并将查询到的消息发送给客户端。例如,服务端当前存储的确认序号为6,数据库中存储的消息序号大于6的消息有消息7、消息8和消息10,而消息9因此时未成功存储至数据库,因此,服务端无法查询到消息9,那么服务端就会将消息7、消息8和消息10返回给客户端。
示例性的,客户端在向服务端发起消息获取请求时,可以记录本次请求的发起时间,可用于确定后续反馈最大消息序号的时机,以及所需要反馈的最大消息序号。
步骤202、接收所述服务端返回的消息,并记录所接收到的消息中的最大消息序号。
示例性的,客户端接收服务端针对本次请求返回的消息,若接收过程中不存在异常,则客户端能够成功接收到消息7、消息8和消息10。但若受到网络不稳定等因素的影响,客户端也可能无法收到服务端返回的全部消息,假设消息8在发送过程中丢失,那么客户端仅能够收到消息7和消息10。
客户端在接收到服务端返回的消息后,查看所接收的多个消息的消息序号,记录其中的最大消息序号,如上文举例,最大消息序号为10。在相关技术中,客户端会立即将序号10反馈给服务端,则服务端会将原来的确认序号6更新为10,后续再接收到客户端的消息获取请求时,序号10以及之前的消息都不会再返回给客户端。
本申请实施例中,可以将步骤201中记录的发起时间和步骤202中记录的最大消息序号进行绑定存储,便于后续需要反馈最大消息序号时,根据对应的发起时间查询到对应的最大消息序号。
步骤203、重复向所述服务端发起消息获取请求,并接收所述服务端返回的消息。
本申请实施例中,在得到最大消息序号后,不会立即反馈给服务端,而是重复向服务端发起消息获取请求。重复发起请求的时机以及重复次数等均不作限定。假设重复次数为1,重复发起请求的时间为与上述记录的发起时间的时间间隔为第一时间间隔,那么经过第一时间间隔后,之前未成功存储的消息可能已经存储成功,由于服务端存储的确认序号并未更新,那么服务端会将该存储成功的消息一起返回给客户端。如前文举例,经过第一时间间隔后,消息9可能已经存储成功,数据库中存储的消息序号大于6的消息有消息7、消息8、消息9和消息10,此时,由于服务端的确认序号仍为6,因此,可以查询到消息有消息7、消息8、消息9和消息10,并返回给客户端。
此外,客户端再次接收服务端返回的消息时,网络状况可能已发生变化,可能会完整地接收到消息7、消息8、消息9和消息10,或者即使网络仍不稳定,客户端也可能成功接收到消息9,而丢失其他消息(如消息10)。
综上,通过延迟反馈最大消息序号并重复发起消息获取请求的方式,可以有效提高消息被成功获取的概率。
步骤204、从所述发起时间起经过预设时长后,向所述服务端反馈所述最大消息序号,其中,所述最大消息序号用于指示所述服务端将所述确认序号更新为所述最大消息序号,所述预设时长大于从所述发起时间到首次重复发起消息获取请求之间的时间间隔。
示例性的,预设时长也可以理解为延迟反馈的时长,可以根据实际情况进行设置,如3分钟等。经过预设时长后,及时向服务端反馈之前记录的最大消息序号,使得服务端对所存储的确认序号进行更新,以便控制后续响应消息获取请求时所返回的消息数量。可以理解的是,所述预设时长大于从所述发起时间到首次重复发起消息获取请求之间的时间间隔,即大于上述第一时间间隔。
本申请实施例中提供的消息获取方法,向服务端发起消息获取请求,并记录本次请求的发起时间,消息获取请求用于指示服务端返回消息序号大于其存储的确认序号的消息,接收服务端返回的消息,并记录所接收到的消息中的最大消息序号,重复向服务端发起消息获取请求并接收服务端返回的消息,从发起时间起经过预设时长后,向服务端反馈所述最大消息序号,指示服务端将确认序号更新为最大消息序号。通过采用上述技术方案,客户端在接收到服务端 返回的消息后,先记录下最大消息号,但暂不向服务端反馈该最大消息号,而是经过一段时间后再反馈,在所经过的这段时间内,重复向服务端发起消息获取请求,由于服务端的确认序号未发生变化,因此,部分消息会被重复返回,能够提高消息被成功获取的概率,实现消息的冗余获取,可以有效改善由于消息序号靠前消息未及时在服务端成功存储或网络状况不稳定等原因导致的客户端的消息获取缺失情况。
在上述实施例基础上,在所述重复向所述服务端发起消息获取请求,并接收所述服务端返回的消息之后,还包括:根据消息序号对已接收到的消息进行去重处理。这样可以在多次获取消息后,统一进行去重处理,节省客户端的存储空间。其中,消息序号是服务端根据消息接收顺序进行递增配置的,也就是说,每条消息都有唯一且自增的id,因此,可以基于消息id的顺序进行去重,若存在多条对应同一id的消息,则说明存在重复,针对每个id仅保留一条消息。
在上述实施例基础上,还可在每次发起消息获取请求并接收所述服务端返回的消息之后,根据消息序号对已接收到的消息进行去重处理。这样可以每获取一次消息,就进行一次去重处理,防止重复消息在客户端过久停留,进一步节省客户端的存储空间。
图3为本申请实施例提供的又一种消息获取方法的流程示意图,在上述实施例基础上,针对重复向服务端发起消息获取请求并接收服务端返回的消息的技术细节进行细化。
示例性的,所述重复向所述服务端发起消息获取请求,并接收所述服务端返回的消息,包括:以预设获取周期向所述服务端重复发起预设次数的消息获取请求,并接收所述服务端返回的消息。这样可以周期性的重复发起消息获取请求,可以更合理地管理消息获取请求的发起时机,有利于消息循环获取周期的叠加。其中,关于消息循环获取周期的内容将在下文中进行详细介绍。
示例性的,该方法可包括:
步骤301、向服务端发起消息获取请求,并记录本次请求的发起时间。
其中,所述消息获取请求用于指示所述服务端返回消息序号大于确认序号的消息,所述确认序号存储于所述服务端中,所述消息序号由所述服务端根据消息接收顺序进行递增配置。
示例性的,客户端采用定时触发的方式发起消息获取请求,定时触发方式可以是周期性触发。
步骤302、接收服务端返回的消息,并记录所接收到的消息中的最大消息序号。
步骤303、以预设获取周期向服务端重复发起预设次数的消息获取请求,接收服务端返回的消息,并根据消息序号对已接收到的消息进行去重处理。
示例性的,周期性触发发起消息获取请求对应的触发周期可以与预设获取周期相等。
图4为本申请实施例提供的一种消息获取时序示意图,假设预设获取周期为a(如60秒),预设次数为K=2。步骤301中向服务端发起消息获取请求(图中以实线箭头表示,以k表示重复发起次数,首次发起时k=0)时,服务端的ackid为7,发起时间记为t0,此时,服务端中存储的消息序号大于7的有消息8和消息10,向客户端返回消息8和消息10,假设不考虑网络因素,客户端能够成功接收到服务端返回的消息,则客户端能够接收到消息8和消息10,记录最大消息序号为Maxid0=10,将t0和Maxid0=10绑定存储。经过一个预设获取周期(a)之后,消息9存储成功,当客户端第一次重复发起(k=1)消息获取请求时(发起时间t1),由于服务端的ackid仍为7,因此,客户端会收到消息8、消息9和消息10。此时,可以与之前收到的消息8和消息10一起进行去重处理,在客户端保存消息8、消息9和消息10。若经过一个a之后,消息9仍未存储成功,那么可能在第二个a期间存储成功,那么通过第二次重复发起(k=2)消息获取请求(发起时间t2),客户端就能够成功获取到消息9。
步骤304、从所述发起时间起经过预设时长后,向所述服务端反馈所述最大消息序号。
其中,所述最大消息序号用于指示所述服务端将所述确认序号更新为所述最大消息序号。
示例性的,所述预设时长为预设获取周期的倍数,所述倍数大于或等于所述预设次数。例如,该倍数可以等于预设次数。
继续参考图4,预设时长可以是K*a,也即在经过2个a之后,也即t2时刻之后,客户端获取消息完毕后,t3时刻之前,向服务端反馈t0时刻对应的Maxid0=10(图中以虚线箭头表示)。当然,也可以在t3时刻,在向服务端发起消息获取请求的同时向服务端反馈t0时刻对应的Maxid0=10。假设在第二个a期间,服务端又成功存储了消息11,那么第二次重复发起消息获取请求时,客户端能够接收到消息8、消息9、消息10和消息11。当客户端在t2时刻后向服 务端反馈t0时刻对应的Maxid0=10之后,服务端会将ackid更新为10,因此,客户端再向服务端发起消息获取请求时,如t3时刻,服务端会查找到大于10的消息为消息11,将消息11返回给客户端。
示例性的,可以将一次消息请求的发起时间作为起点,向服务端反馈最大消息序号的时间作为终点,将起点到终点之间经过的时间称为消息循环获取周期T。从图4中可以看出,每个K=0的时刻均可以视为消息循环获取周期的起点,从而可以实现消息循环获取周期的叠加。在每个消息循环获取周期内,每条消息都有机会被获取K次,也即在首次被获取的基础上,被重复获取K次,换句话说,每个a时间段内的消息都有机会被客户端重复获取K次(如图中的消息11,在服务端响应t2时刻的请求后,消息11首次被获取,在后面的t3和t4时刻之后又重复被获取2次),本申请实施例将这种获取方式称为冗余获取。此外,每个a时间段的消息的最大序号延迟K*a时间后才被客户端发往服务端用于更新ackid,本申请实施例将这种方式称为延迟确认。由于每条消息有唯一且自增的id,客户端在获取到消息后会和本地比对,本地存在的消息丢弃,不存在的消息才予以保留,消息在客户端的展示顺序也是基于消息id的顺序,本申请实施例将这种方式称为基于唯一序号去重。
本申请实施例在客户端与服务端进行交互的过程中,采用冗余获取、延迟确认以及基于唯一序号去重相结合的方式,使得因消息乱序写入数据库或其他情况导致新消息通知乱序到达客户端,或新消息通知因为某些原因丢失的情况下,依然能保证服务器和客户端状态最终一致,即消息不乱序、不重复以及不丢失,提升即时通信系统的可靠性和准确性。
图5为本申请实施例提供的再一种消息获取方法的流程示意图,在上述实施例基础上,针对向服务端反馈最大消息序号的技术细节进行细化。
示例性的,所述向所述服务端反馈所述最大消息序号,包括:判断所述最大消息序号是否大于本地确认序号,其中,所述本地确认序号与当前服务端存储的确认序号一致;基于最大消息序号大于本地确认序号的判断结果,向所述服务端反馈所述最大消息序号,并将所述本地确认序号更新为所述最大消息序号。这样可以在有必要更新时才向服务端反馈最大消息序号,减少数据交互。
例如,在向服务端发起消息获取请求,并记录本次请求的发起时间之前,还包括:获取所述服务端中存储的确认序号,并将所获取到的确认序号记为本地确认序号。这样可以保证本地确认序号的准确性。
例如,所述获取所述服务端中存储的确认序号,包括:检测到所述客户端启动后,获取所述服务端中存储的确认序号。这样可以在客户端启动时及时获取确认序号,保证本地确认序号的准确性。
示例性的,该方法可包括:
步骤501、检测到客户端启动时,获取服务端中存储的确认序号,并将所获取到的确认序号记为本地确认序号。
步骤502、向服务端发起消息获取请求,并记录本次请求的发起时间。
步骤503、接收服务端返回的消息,并记录所接收到的消息中的最大消息序号。
步骤504、以预设获取周期向服务端重复发起预设次数的消息获取请求,接收服务端返回的消息,并根据消息序号对已接收到的消息进行去重处理。
步骤505、从发起时间起经过预设时长后,判断发起时间对应的最大消息序号是否大于本地确认序号,基于发起时间对应的最大消息序号大于本地确认序号的判断结果,执行步骤506;基于发起时间对应的最大消息序号小于或等于本地确认序号的判断结果,返回执行步骤502。
步骤506、向服务端反馈最大消息序号,并将本地确认序号更新为最大消息序号,返回执行步骤502。
本申请实施例在在上述实施例中的采用冗余获取、延迟确认以及基于唯一序号去重相结合的方式基础上,在客户端启动时获取服务端的确认序号并记录到客户端本地,在向服务端发送最大消息序号之前,判断最大消息序号是否大于本地确认序号,基于最大消息序号大于本地确认序号的判断结果,发送最大消息序号,从而在有必要更新时才向服务端反馈最大消息序号,减少数据交互。
图6为本申请实施例提供的另一种消息获取方法的流程示意图,在上述实施例基础上,针对客户端较长时间未上线的情况进行细化。
示例性的,在向服务端发起消息获取请求,并记录本次请求的发起时间之前,还包括:检测到所述客户端启动时,向所述服务端发起消息获取请求,并接收所述服务端返回的消息;判断所接收到的消息的总数量是否大于预设阈值,基于所接收到的消息的总数量大于预设阈值的判断结果,确定目标确认序号;向所述服务端发送所述目标确认序号,其中,所述目标确认序号用于指示所述服务端将所述确认序号更新为所述目标确认序号,所述目标确认序号小于所接收到的消息中的最大消息序号。这样可以更合理地更新服务端的确认序号。
例如,所述确定目标确认序号,可包括:获取所述服务端返回消息时的回包时间戳;筛选出所接收到的消息中的目标消息,其中,所述目标消息中的消息时间戳与所述预设时长的和小于或等于所述回包时间戳;将所述目标消息中的最大消息序号确定为目标确认序号。这样可以更加合理地确定目标确认序号。
例如,该方法包括:
步骤601、检测到客户端启动时,向服务端发起消息获取请求,并接收服务端返回的消息。
步骤602、判断所接收到的消息的总数量是否大于预设阈值,基于所接收到的消息的总数量大于预设阈值的判断结果,执行步骤603;基于所接收到的消息的总数量小于或等于预设阈值的判断结果,执行步骤606。
示例性的,若用户一段时间内未使用客户端,则服务端会积压较多未读消息,因此,可以通过判断消息总数量是否大于预设阈值来确定是否存在这种情况。预设阈值可以根据实际需求设置,具体不做限定。
步骤603、获取服务端返回消息时的回包时间戳,筛选出所接收到的消息中的目标消息。
其中,目标消息中的消息时间戳与预设时长的和小于或等于回包时间戳。
示例性的,客户端每次请求服务器得到的回包中都包含有一个服务器当前的时间戳,此处称为回包时间戳,可记为t。在获取积压消息结束后,可以取出每条消息中的时间戳msg_t,也即消息时间戳。假设预设时长为K*a,则目标消息即为msg_t+K*a小于t的消息。
步骤604、将目标消息中的最大消息序号确定为目标确认序号,并向服务端发送目标确认序号。
其中,目标确认序号用于指示服务端将确认序号更新为目标确认序号。
可以理解的是,服务端将确认序号更新为目标确认序号后,对于msg_t+K*a大于或等于t的消息,将会得到重复获取,保证这些消息被成功获取的概率。
步骤605、将目标确认序号记为本地确认序号,执行步骤607。
步骤606、获取服务端中存储的确认序号,并将所获取到的确认序号记为本地确认序号。
步骤607、向服务端发起消息获取请求,并记录本次请求的发起时间。
步骤608、接收服务端返回的消息,并记录所接收到的消息中的最大消息序号。
步骤609、以预设获取周期向服务端重复发起预设次数的消息获取请求,接收服务端返回的消息,并根据消息序号对已接收到的消息进行去重处理。
步骤610、从发起时间起经过预设时长后,判断发起时间对应的最大消息序号是否大于本地确认序号,基于发起时间对应的最大消息序号大于本地确认序号的判断结果,执行步骤611;基于发起时间对应的最大消息序号小于或等于本地确认序号的判断结果,返回执行步骤607。
步骤611、向服务端反馈最大消息序号,并将本地确认序号更新为最大消息序号。
本申请实施例在在上述实施例基础上,针对客户端较长时间未上线的情况进行优化,若确定积压未读消息较多,则可以将距离当前时刻较近的几条未读消息作为重复获取的目标,确定目标确认序号并反馈给服务端进行确认序号的更新,以便在后续的消息获取过程中,能够重复获取近期消息,保证近期消息被成功获取。
图7为本申请实施例提供的一种消息获取装置的结构框图,该装置可由软件和/或硬件实现,一般可集成在作为客户端的计算机设备中,可通过执行消息获取方法来进行消息获取。如图7所示,该装置包括:
发起时间记录模块701,设置为向服务端发起消息获取请求,并记录本次请求的发起时间,其中,所述消息获取请求用于指示所述服务端返回消息序号大于确认序号的消息,所述确认序号存储于所述服务端中,所述消息序号由所述服务端根据消息接收顺序进行递增配置;
最大消息序号记录模块702,设置为接收所述服务端返回的消息,并记录所接收到的消息中的最大消息序号;
消息重复获取模块703,设置为重复向所述服务端发起消息获取请求,并接收所述服务端返回的消息;
最大消息序号反馈模块704,设置为从所述发起时间起经过预设时长后,向所述服务端反馈所述最大消息序号,其中,所述最大消息序号用于指示所述服务端将所述确认序号更新为所述最大消息序号,所述预设时长大于从所述发起时间到首次重复发起消息获取请求之间的时间间隔。
本申请实施例提供的消息获取装置,向服务端发起消息获取请求,并记录本次请求的发起时间,消息获取请求用于指示服务端返回消息序号大于其存储的确认序号的消息,接收服务端返回的消息,并记录所接收到的消息中的最大 消息序号,重复向服务端发起消息获取请求并接收服务端返回的消息,从发起时间起经过预设时长后,向服务端反馈所述最大消息序号,指示服务端将确认序号更新为最大消息序号。通过采用上述技术方案,客户端在接收到服务端返回的消息后,先记录下最大消息号,但暂不向服务端反馈该最大消息号,而是经过一段时间后再反馈,在所经过的这段时间内,重复向服务端发起消息获取请求,由于服务端的确认序号未发生变化,因此,部分消息会被重复返回,能够提高消息被成功获取的概率,实现消息的冗余获取,有效改善客户端的消息获取缺失情况。
本申请实施例提供了一种计算机设备,该计算机设备中可集成本申请实施例提供的消息获取装置。图8为本申请实施例提供的一种计算机设备的结构框图。计算机设备800包括存储器801、处理器802及存储在存储器801上并可在处理器802上运行的计算机程序,所述处理器802执行所述计算机程序时实现本申请实施例提供的消息获取方法。
本申请实施例还提供一种包含计算机可执行指令的存储介质,所述计算机可执行指令在由计算机处理器执行时用于执行本申请实施例提供的消息获取方法。存储介质可以是非暂态计算机可读存储介质。
上述实施例中提供的消息获取装置、设备以及存储介质可执行本申请任意实施例所提供的消息获取方法,具备执行该方法相应的功能模块和有益效果。未在上述实施例中详尽描述的技术细节,可参见本申请任意实施例所提供的消息获取方法。

Claims (12)

  1. 一种消息获取方法,应用于客户端,包括:
    向服务端发起消息获取请求,并记录本次请求的发起时间,其中,所述消息获取请求用于指示所述服务端返回消息序号大于确认序号的消息,所述确认序号存储于所述服务端中,所述消息序号由所述服务端根据消息接收顺序进行递增配置;
    接收所述服务端返回的消息,并记录所接收到的消息中的最大消息序号;
    重复向所述服务端发起消息获取请求,并接收所述服务端返回的消息;
    从所述发起时间起经过预设时长后,向所述服务端反馈所述最大消息序号,其中,所述最大消息序号用于指示所述服务端将所述确认序号更新为所述最大消息序号,所述预设时长大于从所述发起时间到首次重复发起消息获取请求之间的时间间隔。
  2. 根据权利要求1所述的方法,其中,所述重复向所述服务端发起消息获取请求,并接收所述服务端返回的消息,包括:
    以预设获取周期向所述服务端重复发起预设次数的消息获取请求,并接收所述服务端返回的消息。
  3. 根据权利要求2所述的方法,其中,所述预设时长为所述预设获取周期的倍数,所述倍数大于或等于所述预设次数。
  4. 根据权利要求1所述的方法,其中,所述向所述服务端反馈所述最大消息序号,包括:
    判断所述最大消息序号是否大于本地确认序号,其中,所述本地确认序号与当前服务端存储的确认序号一致;
    基于所述最大消息序号大于本地确认序号的判断结果,向所述服务端反馈所述最大消息序号,并将所述本地确认序号更新为所述最大消息序号。
  5. 根据权利要求4所述的方法,在所述向服务端发起消息获取请求,并记录本次请求的发起时间之前,还包括:
    获取所述服务端中存储的确认序号,并将所获取到的确认序号记为所述本地确认序号。
  6. 根据权利要求5所述的方法,其中,所述获取所述服务端中存储的确认序号,包括:
    响应于检测到所述客户端启动,获取所述服务端中存储的确认序号。
  7. 根据权利要求2所述的方法,在所述向服务端发起消息获取请求,并记录本次请求的发起时间之前,还包括:
    响应于检测到所述客户端启动,向所述服务端发起消息获取请求,并接收所述服务端返回的消息;
    判断所接收到的消息的总数量是否大于预设阈值,基于所接收到的消息的总数量大于预设阈值的判断结果,确定目标确认序号,其中,所述目标确认序号小于所接收到的消息中的最大消息序号;
    向所述服务端发送所述目标确认序号,其中,所述目标确认序号用于指示所述服务端将所述确认序号更新为所述目标确认序号。
  8. 根据权利要求7所述的方法,其中,所述确定目标确认序号,包括:
    获取所述服务端返回消息时的回包时间戳;
    筛选出所接收到的消息中的目标消息,其中,所述目标消息中的消息时间戳与所述预设时长的和小于或等于所述回包时间戳;
    将所述目标消息中的最大消息序号确定为目标确认序号。
  9. 根据权利要求1所述的方法,在所述重复向所述服务端发起消息获取请求,并接收所述服务端返回的消息之后,还包括:根据消息序号对已接收到的消息进行去重处理;或者,
    在每次发起消息获取请求并接收所述服务端返回的消息之后,还包括:
    根据消息序号对已接收到的消息进行去重处理。
  10. 一种消息获取装置,配置于客户端,包括:
    发起时间记录模块,设置为向服务端发起消息获取请求,并记录本次请求的发起时间,其中,所述消息获取请求用于指示所述服务端返回消息序号大于确认序号的消息,所述确认序号存储于所述服务端中,所述消息序号由所述服务端根据消息接收顺序进行递增配置;
    最大消息序号记录模块,设置为接收所述服务端返回的消息,并记录所接收到的消息中的最大消息序号;
    消息重复获取模块,设置为重复向所述服务端发起消息获取请求,并接收所述服务端返回的消息;
    最大消息序号反馈模块,设置为从所述发起时间起经过预设时长后,向所述服务端反馈所述最大消息序号,其中,所述最大消息序号用于指示所述服务端将所述确认序号更新为所述最大消息序号,所述预设时长大于从所述发起时 间到首次重复发起消息获取请求之间的时间间隔。
  11. 一种计算机设备,包括存储器、处理器及存储在存储器上并可在处理器上运行的计算机程序,所述处理器执行所述计算机程序时实现如权利要求1-9任一项所述的方法。
  12. 一种计算机可读存储介质,其上存储有计算机程序,所述计算机程序被处理器执行时实现如权利要求1-9中任一所述的方法。
PCT/CN2021/126543 2020-10-28 2021-10-27 消息获取方法、装置、设备及存储介质 Ceased WO2022089455A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202011173739.4A CN112367149B (zh) 2020-10-28 2020-10-28 消息获取方法、装置、设备及存储介质
CN202011173739.4 2020-10-28

Publications (1)

Publication Number Publication Date
WO2022089455A1 true WO2022089455A1 (zh) 2022-05-05

Family

ID=74511171

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2021/126543 Ceased WO2022089455A1 (zh) 2020-10-28 2021-10-27 消息获取方法、装置、设备及存储介质

Country Status (2)

Country Link
CN (1) CN112367149B (zh)
WO (1) WO2022089455A1 (zh)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115412519A (zh) * 2022-08-29 2022-11-29 中国建设银行股份有限公司 消息传输方法、装置、服务器及存储介质
CN117061470A (zh) * 2023-08-09 2023-11-14 中移互联网有限公司 消息拉取方法、装置及存储介质
CN118748661A (zh) * 2024-08-23 2024-10-08 苏州元脑智能科技有限公司 一种保序通信方法、装置、设备及存储介质

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112367149B (zh) * 2020-10-28 2022-10-14 百果园技术(新加坡)有限公司 消息获取方法、装置、设备及存储介质
CN113923179A (zh) * 2021-09-18 2022-01-11 深圳依时货拉拉科技有限公司 即时消息的传输方法及传输装置、计算机设备及存储介质
CN114465697B (zh) * 2022-04-11 2022-07-19 湖南戎腾网络科技有限公司 一种基于以太网的可靠通信方法、装置及设备
CN115208521B (zh) * 2022-08-22 2023-07-04 北京钢铁侠科技有限公司 一种会话层客户端与服务端通讯保障及工作流管控方法

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105812235A (zh) * 2016-03-04 2016-07-27 百度在线网络技术(北京)有限公司 消息处理方法、装置及系统
CN106027379A (zh) * 2016-07-28 2016-10-12 贵州中科汉天下信息技术有限公司 一种推送消息接收处理方法
CN107491356A (zh) * 2017-08-28 2017-12-19 广州市百果园信息技术有限公司 基于序号的消息处理方法、终端设备和服务器
CN112367149A (zh) * 2020-10-28 2021-02-12 百果园技术(新加坡)有限公司 消息获取方法、装置、设备及存储介质

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105812235A (zh) * 2016-03-04 2016-07-27 百度在线网络技术(北京)有限公司 消息处理方法、装置及系统
CN106027379A (zh) * 2016-07-28 2016-10-12 贵州中科汉天下信息技术有限公司 一种推送消息接收处理方法
CN107491356A (zh) * 2017-08-28 2017-12-19 广州市百果园信息技术有限公司 基于序号的消息处理方法、终端设备和服务器
CN112367149A (zh) * 2020-10-28 2021-02-12 百果园技术(新加坡)有限公司 消息获取方法、装置、设备及存储介质

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115412519A (zh) * 2022-08-29 2022-11-29 中国建设银行股份有限公司 消息传输方法、装置、服务器及存储介质
CN115412519B (zh) * 2022-08-29 2024-05-03 中国建设银行股份有限公司 消息传输方法、装置、服务器及存储介质
CN117061470A (zh) * 2023-08-09 2023-11-14 中移互联网有限公司 消息拉取方法、装置及存储介质
CN118748661A (zh) * 2024-08-23 2024-10-08 苏州元脑智能科技有限公司 一种保序通信方法、装置、设备及存储介质

Also Published As

Publication number Publication date
CN112367149B (zh) 2022-10-14
CN112367149A (zh) 2021-02-12

Similar Documents

Publication Publication Date Title
WO2022089455A1 (zh) 消息获取方法、装置、设备及存储介质
JP4906295B2 (ja) レートを同期させたクロックを使用した高信頼メッセージング
CN101316221B (zh) 通知消息处理方法及设备
WO2022001750A1 (zh) 数据同步处理方法、电子设备以及存储介质
WO2021120995A1 (zh) 数据库的数据同步方法、装置以及存储介质
CN111159233A (zh) 分布式缓存方法、系统、计算机设备以及存储介质
WO2013178082A1 (zh) 图片上传方法、系统、客户端及网络服务器、计算机存储介质
CN101310468B (zh) 一种报文同步定界方法及系统
CN110032478B (zh) 一种主备中心数据实时同步方法、装置、系统及存储介质
JPWO2008020644A1 (ja) プロキシ・サーバ、通信システム、通信方法及びプログラム
CN102075545B (zh) 一种客户端注册指示方法、注册方法及其设备
CN107040576B (zh) 信息推送方法及装置、通讯系统
CN110633168A (zh) 一种分布式存储系统的数据备份方法和系统
CN103095550A (zh) 一种即时通信方法、系统及装置
US20100228866A1 (en) Method for synchronizing data, system, and apparatus thereof
CN111416823A (zh) 一种数据传输方法和装置
WO2014206034A1 (zh) 数据的分解同步方法及系统
CN105450682B (zh) 一种用于数据同步保存、向客户端同步数据的方法、装置和系统
CN107872396A (zh) 具有超时控制的通信方法、处理设备、终端设备和服务器
WO2015090218A1 (zh) 服务端、用户端消息传输处理方法、消息传输方法及系统
US20080137531A1 (en) Sip presence server failover
WO2023011099A1 (zh) 区块链节点退出节点集合的方法及装置
CN107846476B (zh) 一种信息同步方法、设备及存储介质
CN101610225B (zh) 一种同步处理方法、系统和装置
CN107786607B (zh) 一种消息重传方法、消息重传服务器及用户设备

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 21885182

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 21885182

Country of ref document: EP

Kind code of ref document: A1