A message processing method and apparatus
By merging and updating item attribute change messages in message cache data, the problem of frequent sending item attribute change messages is solved, reducing resource waste and ensuring immediacy and high availability.
Patent Information
- Application Number
- CN202110153651.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-02-04
- Publication Date
- 2025-07-18
- Estimated Expiration
- 2041-02-04
AI Technical Summary
In the prior art, frequent sending of item attribute changes messages leads to excessive use of server resources and bandwidth, and downstream message consumers frequently spend high load update resources and are inefficient.
Merge the received item attribute change messages in the message cache data. By creating or updating the second item attribute change messages, it reduces frequent sending in a short time, and uses timing tasks and message queues to send merged messages.
It reduces the use of server and bandwidth, reduces resource waste, and ensures the immediacy and high availability of downstream message consumers receiving item attribute changes messages.
Smart Images

Figure CN113760572B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular, to a message processing method and apparatus. Background Art
[0002] With the development of e-commerce business and the expansion and enrichment of the application scenarios of items, the item attributes are growing rapidly, corresponding to the formation of hundreds or thousands of attributes or attribute groups, such as basic attributes including name, price, and inventory, sales attributes including color and size, and specification parameters, etc. Based on this, in order to adapt to the rapid growth of item attributes to better support business search and display, many business systems use message queues to transmit change messages of item attributes to improve user experience.
[0003] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art: each change message of item attributes will be pushed to the message queue. Thus, in the case of frequent changes of item attributes in a short period of time, the upstream message sender will frequently use the message queue to transmit messages, resulting in the occupation of a large amount of server resources and bandwidth; for the downstream message consumers, they need to update the corresponding item attributes frequently and with high load according to the change messages, and there may be a large number of invalid updates among them, resulting in resource waste and reduced processing efficiency. Summary of the Invention
[0004] In view of this, embodiments of the present invention provide a message processing method and apparatus, which can, while ensuring the instantaneity of messages, avoid frequent transmission of change messages in a short period of time by merging one or more received item attribute change messages in the message cache data, thereby avoiding frequent update of item attributes by downstream message consumers in a short period of time and reducing the waste of resources such as servers.
[0005] To achieve the above object, according to one aspect of the embodiments of the present invention, there is provided a message processing method, including:
[0006] Obtain a first item attribute change message, where the first item attribute change message indicates an item identifier and one or more updated item attribute values corresponding to the item identifier;
[0007] According to the item identifier, determine whether there is a second item attribute change message corresponding to the item identifier in the message cache data:
[0008] If not, create a second item attribute change message corresponding to the item identifier in the message cache data according to the first item attribute change message, and push the first item attribute change message to the message queue;
[0009] If it exists, update the second item attribute change message according to the first item attribute change message, and increase the message change count corresponding to the second item attribute change message, so as to determine whether to push the second item attribute change message to the message queue according to the message change count.
[0010] Optionally, it further includes:
[0011] When creating the second item attribute change message corresponding to the item identifier in the message cache data, start a first timing task for the second item attribute change message, so as to determine whether to push the second item attribute change message to the message queue according to the message change count after a first threshold time has elapsed.
[0012] Optionally, determining whether to push the second item attribute change message to the message queue according to the message change count includes:
[0013] Determine whether the current message change count corresponding to the second item attribute change message is greater than the message change count corresponding to when the second item attribute change message was created:
[0014] If it is greater, push the second item attribute change message to the message queue, and delete the second item attribute change message from the message cache data;
[0015] If it is not greater, directly delete the second item attribute change message from the message cache data.
[0016] Optionally, it further includes:
[0017] Start a second timing task for the message cache data to periodically traverse the second item attribute change messages in the message cache data;
[0018] And when the sending time corresponding to the second item attribute change message is less than the current time, determine whether to push the second item attribute change message to the message queue according to the message change count, where the sending time indicates the sum of the creation time of the second item attribute change message and a second threshold time.
[0019] Optionally, obtain the first item attribute change message by parsing the database log file, where the database is used to store the item identifier and the corresponding item attribute value.
[0020] Optionally, it further includes:
[0021] In the case of pushing the second item attribute change message to the message queue, notify the consumer of the second item attribute change message to obtain the changed item attribute value corresponding to the item identifier from the database by means of remote procedure call.
[0022] Optionally, it further includes:
[0023] Set a cache period for the second item attribute change message so as to delete the second item attribute change message from the message cache data after the cache period has elapsed.
[0024] Optionally, it further includes:
[0025] Before determining whether there is a second item attribute change message corresponding to the item identifier in the message cache data according to the item identifier, determine whether the message type corresponding to the first item attribute change message can be used to create a corresponding second item attribute change message.
[0026] Optionally, it further includes:
[0027] Before determining whether there is a second item attribute change message corresponding to the item identifier in the message cache data according to the item identifier, determine whether a second item attribute change message can be created during the current time period.
[0028] Optionally, store the second item attribute change message in the message cache data in the form of key-value pairs.
[0029] To achieve the above object, according to another aspect of the embodiments of the present invention, there is provided a message processing device, including: an item attribute change message acquisition module, an item attribute change message processing module; wherein,
[0030] The item attribute change message acquisition module is used to acquire a first item attribute change message, and the first item attribute change message indicates an item identifier and one or more updated item attribute values corresponding to the item identifier;
[0031] The item attribute change message processing module is used to determine whether there is a second item attribute change message corresponding to the item identifier in the message cache data according to the item identifier:
[0032] If not, create a second item attribute change message corresponding to the item identifier in the message cache data according to the first item attribute change message, and push the first item attribute change message to the message queue;
[0033] If it exists, update the second item attribute change message according to the first item attribute change message, and increase the message change count corresponding to the second item attribute change message, so as to determine whether to push the second item attribute change message to the message queue according to the message change count.
[0034] Optionally, it further includes: a timing task startup module; wherein,
[0035] The timing task startup module is used to, when creating the second item attribute change message corresponding to the item identifier in the message cache data, start a first timing task for the second item attribute change message, so as to determine whether to push the second item attribute change message to the message queue according to the message change count after a first threshold time has passed.
[0036] Optionally, the determining whether to push the second item attribute change message to the message queue according to the message change count includes:
[0037] Determine whether the current message change count corresponding to the second item attribute change message is greater than the message change count corresponding to the creation of the second item attribute change count:
[0038] If it is greater, push the second item attribute change message to the message queue and delete the second item attribute change message from the message cache data;
[0039] If it is not greater, directly delete the second item attribute change message from the message cache data.
[0040] Optionally, the timing task startup module is further used for,
[0041] Start a second timing task for the message cache data to periodically traverse the second item attribute change messages in the message cache data;
[0042] And when the sending time corresponding to the second item attribute change message is less than the current time, determine whether to push the second item attribute change message to the message queue according to the message change count; wherein, the sending time indicates the sum of the creation time of the second item attribute change message and a second threshold time.
[0043] Optionally, the item attribute change message acquisition module is used to obtain the first item attribute change message by parsing the database log file, and the database is used to store the item identifier and the corresponding item attribute value.
[0044] Optionally, the item attribute change message processing module is further used for,
[0045] In the case of pushing the second item attribute change message to the message queue, notify the consumer of the second item attribute change message to obtain the changed item attribute value corresponding to the item identifier from the database in a remote procedure call manner.
[0046] Optionally, the item attribute change message processing module is further configured to
[0047] Set a cache expiration period for the second item attribute change message, so as to delete the second item attribute change message from the message cache data after the cache expiration period.
[0048] Optionally, the item attribute change message processing module is further configured to
[0049] Before determining whether there is a second item attribute change message corresponding to the item identifier in the message cache data according to the item identifier, determine whether the message type corresponding to the first item attribute change message can be used to create a corresponding second item attribute change message.
[0050] Optionally, the item attribute change message processing module is further configured to
[0051] Before determining whether there is a second item attribute change message corresponding to the item identifier in the message cache data according to the item identifier, determine whether a second item attribute change message can be created during the current time period.
[0052] Optionally, store the second item attribute change message in the message cache data in a key-value pair manner.
[0053] To achieve the above object, according to another aspect of the embodiments of the present invention, there is provided an electronic device for message processing, including: one or more processors; a storage device for storing one or more programs,
[0054] When the one or more programs are executed by the one or more processors, the one or more processors implement any of the methods in the message processing method described above.
[0055] To achieve the above object, according to yet another aspect of the embodiments of the present invention, there is provided a computer-readable medium, on which a computer program is stored, and when the program is executed by a processor, it implements any of the methods in the message processing method described above.
[0056] One embodiment of the above invention has the following advantages or beneficial effects: By creating or continuously updating the second item attribute change message in the message cache data when receiving the first item attribute change message, the merging of one or more first item attribute change messages obtained is achieved, avoiding frequent sending of change messages in a short period of time, thereby avoiding frequent updating of item attributes by downstream message consumers in a short period of time, reducing the occupation of the server and bandwidth, and also reducing the waste of resources caused by frequent ineffective updates of item attributes. At the same time, by directly sending the first item attribute change message through the message queue when creating the second item attribute change message, the immediacy of the downstream message consumer receiving the item attribute change message is ensured.
[0057] The further effects of the above non-conventional alternative manner will be described in conjunction with specific embodiments below. BRIEF DESCRIPTION OF THE DRAWINGS
[0058] The drawings are used to better understand the present invention and do not constitute an improper limitation to the present invention. Among them:
[0059] Figure 1 is a schematic diagram of the main process of the message processing method according to an embodiment of the present invention;
[0060] Figure 2 is a schematic diagram of the main process of another message processing method according to an embodiment of the present invention;
[0061] Figure 3 is a schematic diagram of the main process of yet another message processing method according to an embodiment of the present invention;
[0062] Figure 4 is a schematic diagram of the main modules of the message processing device according to an embodiment of the present invention;
[0063] Figure 5 is an exemplary system architecture diagram to which the embodiments of the present invention can be applied;
[0064] Figure 6 is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing the embodiments of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0065] The following describes exemplary embodiments of the present invention in conjunction with the drawings. Various details of the embodiments of the present invention are included to facilitate understanding, and they should be considered merely exemplary. Therefore, those of ordinary skill in the art should recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for the sake of clarity and conciseness, the description below omits the description of well-known functions and structures.
[0066] Figure 1 It is a schematic diagram of the main process of the message processing method according to an embodiment of the present invention. As Figure 1 shown, the steps that the message processing method may specifically include are as follows:
[0067] Step S101: Obtain a first item attribute change message, where the first item attribute change message indicates an item identifier and one or more item attribute values corresponding to the item identifier.
[0068] Among them, the item identifier refers to information that can be used to distinguish different items, such as a product SKU code, etc. The item attribute refers to any attribute information used to describe an item or related to the item in practice, including but not limited to item name, item price, item inventory, item color, item size, specification parameters, whether it is self-operated, POP, item picture, item video, item evaluation, etc. Taking a mobile phone with an item identifier of 0001 as an example, as promotional activities, sales activities, etc. are carried out, the values of attribute information such as the actual selling price and actual inventory of this mobile phone are constantly changing. Especially during classic large-scale promotion activities such as Double Eleven and Double Twelve, the values of its attribute information will change frequently within a short period of time. Correspondingly, to ensure the reliability of the item attribute information displayed or recorded, it is necessary to continuously update the item attribute values according to the actual situation.
[0069] Generally speaking, the item management system can use a database to record the attribute information corresponding to different items, and can continuously update the item attribute values corresponding to the item identifier in the database record by adding, deleting, or modifying data according to the actual situation, so as to continuously send item attribute change messages to consumers downstream who need to obtain item attribute information.
[0070] Based on this, the first item attribute change message can be obtained by parsing the database log file, and the database is used to store the item identifier and the corresponding item attribute values. It can be understood that this embodiment only takes using a database to store the attribute information corresponding to items as an example for illustration, and in actual implementation, a distributed cache or other storage methods can also be used for replacement. Specifically, taking the use of a MySQL database as an example for illustration, the incremental log of the MySQL database, that is, the Binlog log file, can be parsed through canal to obtain the first item attribute change message. More specifically, the first item attribute change message indicates an item identifier (such as 0001), and one or more item attribute values after the change corresponding to the item identifier, such as the color is yellow; the price is 100; the inventory is 23, etc.
[0071] Step S102: Determine whether there is a second item attribute change message corresponding to the item identifier in the message cache data. Specifically, if not, continue to execute the following step S103; if so, continue to execute the following step S104.
[0072] That is to say, after obtaining the first item attribute change message by parsing the database log file, instead of directly sending the first item attribute change message to the downstream message consumer through the message queue, one or more first item attribute change messages for the same item identifier are first merged in the message cache data, that is, the second item attribute change message is created or continuously updated according to the first item attribute change message. In this way, the problem of occupying a large amount of server resources and bandwidth caused by frequently sending change messages to the downstream due to frequent changes of item attributes in a short period of time is avoided.
[0073] Among them, the second item attribute change message indicates one or more latest updated item attribute values corresponding to the item identifier. Specifically, the second item attribute change message can either only indicate one or more item attribute values that are the latest updated as indicated by the first item attribute change message, or indicate all item attribute values corresponding to the item identifier that are the latest updated according to the first item attribute change message. For example, taking the case where all item attributes corresponding to the item identifier 0001 only include color, size, price, and inventory as an example, if the latest obtained first item attribute change message indicates that the price is 100 and the inventory is 23, then the second item attribute change message updated according to the first item attribute change message can either only indicate that the price corresponding to the item identifier 0001 is 100 and the inventory is 23, or indicate that the price corresponding to the item identifier 0001 is 100, the inventory is 23, the color is yellow, the size is 5.5 inches, etc.
[0074] Furthermore, the second item attribute change message can be stored in the form of key-value pairs in the storage message cache data, that is, the second item attribute change message is stored using the Hash data structure. Taking the example of storing the message cache data in Redis, the second item identifier can be used as the key value, and the corresponding updated one or more item attribute values can be used as the value for storage. In this way, by querying the key value of the item identifier, it can be quickly determined whether the value corresponding to the item identifier, that is, the second item attribute change message, already exists in Redis. In addition, during the actual execution process, information such as the sending time of the item identifier and the number of message changes can also be stored correspondingly in the value.
[0075] Among them, the sending time is determined by the sum of the creation time of the second item attribute change message and the second threshold time, and the second threshold time indicates the length of time for using the message cache data to merge one or more first item attribute messages corresponding to the same item identifier, which can be preset according to the actual situation, such as 30s, 50s, etc. The message change count indicates the number of times the attribute information corresponding to the item identifier has changed within the second threshold time since the creation of the second item attribute change message, that is, the total number of received first item attribute change messages. By default, the message change count corresponding to the creation of the second item attribute change message is 1. It can be understood that the message change count corresponding to the creation of the second item attribute change message can also be set to other values other than 1 according to the actual situation.
[0076] In an alternative implementation, it further includes: before determining whether there is a second item attribute change message corresponding to the item identifier in the message cache data according to the item identifier, determining whether a second item attribute change message can be created during the current time period.
[0077] That is to say, in the actual execution process, according to the time law of frequent changes in item attributes in a short period of time, the time period for using the message cache data to merge the first item attribute change messages, that is, creating the second item attribute change message, can be reasonably set. For example, the strategy of creating the second item attribute change message is adopted during major promotion periods such as Double Eleven and Double Twelve, and this strategy is not adopted at other times. In this way, it can reduce the frequent and ineffective update of item attribute values by downstream message consumers caused by directly sending the first item attribute change messages frequently in a short period of time, and at the same time, it can take into account the immediacy of sending item attribute change messages to the downstream, ensuring the high availability of the item attribute values received by downstream consumers.
[0078] Furthermore, it further includes: before determining whether there is a second item attribute change message corresponding to the item identifier in the message cache data according to the item identifier, determining whether the message type corresponding to the first item attribute change message can be used to create the corresponding second item attribute change message.
[0079] That is to say, in addition to determining whether to adopt the strategy of creating a second item attribute change message based on the time pattern of frequent changes in item attributes in a short period, it is also possible to more finely determine whether to use message cache data to merge the first item attribute change message, that is, create a second item attribute change message, according to the immediate needs of downstream message consumers for different item attribute change messages, that is, different message types, to reduce the frequency of sending change messages in a short period. For example, during the Double Eleven and Double Twelve promotions, the immediate requirements for item attribute change messages such as price and inventory are relatively high. In this case, instead of creating a second item attribute change message, all the obtained first item attribute change messages containing price and inventory can be directly sent to ensure the immediacy and high availability of downstream price and inventory acquisition. On the other hand, for the first item attribute change messages that only indicate item attributes such as item pictures and item videos, the immediate requirements are relatively low. To reduce the consumption of server resources or bandwidth, creating a second item attribute change message can be considered to reduce the frequency of sending change messages in a short period.
[0080] Step S103: According to the first item attribute change message, create a second item attribute change message corresponding to the item identifier in the message cache data, and push the first item attribute change message to the message queue.
[0081] That is to say, in the case where there is no second item attribute change message corresponding to the item identifier in the message cache data, a second item attribute change message is created. In the case where one or more first item attribute change messages corresponding to the item identifier are subsequently obtained, the second item attribute change message is updated, rather than directly sending the subsequently obtained first item attribute change messages, to reduce the frequency of sending item attribute change messages corresponding to the same item identifier in a short period. At the same time, when creating a second item attribute change message according to the first item attribute change message, the first item attribute change message is directly pushed to the message queue, so that downstream message consumers can update the corresponding item attribute values according to the first item attribute change message, ensuring the immediacy and high availability of item attribute change messages to a certain extent.
[0082] More specifically, this embodiment only takes the case where the second item attribute change message indicates one or more item attribute values corresponding to the latest update of the item identifier as an example for illustration. If the first item attribute change message indicates that the price corresponding to the item identifier 0001 is 100 and the inventory is 23, then the second item attribute change message created according to the first item attribute change message also indicates that the price corresponding to the item identifier 0001 is 100 and the inventory is 23. It can be understood that the second item attribute change message may also indicate other item attribute values corresponding to the item identifier 0001, as well as the corresponding message change count (such as 1), the sending time T1, etc., where the sending time T1 indicates the sum of the current time T0 and the second threshold time (such as 30s). That is, within the next 30s, if a first item attribute change message corresponding to the item identifier 0001 is obtained, it is not directly sent but instead the second item attribute change message is correspondingly updated; until after 30s, that is, when the corresponding sending time is reached, the second item attribute change message can be directly pushed to the message queue, and the second item attribute change message is deleted from the message cache data to avoid duplicate sending of the same second item attribute change message and reduce resource waste.
[0083] Furthermore, it also includes: when creating the second item attribute change message corresponding to the item identifier in the message cache data, starting a first timing task for the second item attribute change message to determine whether to push the second item attribute change message to the message queue according to the message change count after a first threshold time. That is to say, to ensure the immediacy of sending the second item attribute change message in the message cache data, a timing task can be set through Timer so that after a first threshold time (such as 40s), the second item attribute change message in the message cache data is pushed to the message queue, and the second item attribute change message is deleted from the message cache data to avoid duplicate sending of the same second item attribute change message and reduce resource waste.
[0084] More specifically, the judging whether to send the second item attribute change message to the message queue according to the message change count includes: judging whether the current message change count corresponding to the second item attribute change message is greater than the message change count corresponding to when the second item attribute change message is created: if it is greater, then push the second item attribute change message to the message queue and delete the second item attribute change message from the message cache data; if it is not greater, then directly delete the second item attribute change message from the message cache data.
[0085] Step S104: Update the second item attribute change message according to the first item attribute change message, and increase the message change count corresponding to the second item attribute change message, so as to determine whether to push the second item attribute change message to the message queue according to the message change count.
[0086] Specifically, in this embodiment, it is only illustrated by taking the second item attribute change message indicating one or more item attribute values corresponding to the latest update of the item identifier as an example. If the first item attribute change message indicates that the price corresponding to the item identifier 0001 is 100 and the inventory is 23, and the second item attribute change message existing in the message cache data indicates that the price is 150 and the inventory is 50, and the corresponding message change count is 3, then the updated second item attribute change message according to the first item attribute change message indicates that the price corresponding to the item identifier 0001 is 100 and the inventory is 23, and the corresponding message change count is increased to 5, that is, since the creation of the second item attribute change message, a total of 5 first item attribute change messages corresponding to this item identifier have been obtained successively.
[0087] Furthermore, to avoid the failure of the Timer, resulting in the failure of the set first scheduled task to execute normally, and further causing the second item attribute change message to be unable to be sent normally, a periodic second scheduled task is also set in the way of a daemon process, such as executing once every 10s, to ensure the immediacy and high availability of the downstream message consumer receiving the second item attribute change message. Specifically, it further includes: starting a second scheduled task for the message cache data to periodically traverse the second item attribute change messages in the message cache data; and when the sending time corresponding to the second item attribute change message is less than the current time, determining whether to push the second item attribute change message to the message queue according to the message change count, where the sending time indicates the sum of the creation time of the second item attribute change message and the second threshold time.
[0088] More specifically, during the process of periodically traversing the message cache data, if it is found that the sending time corresponding to the second item attribute change message is less than the current time, that is, the second item attribute change message should be sent but has not been sent, then it is further determined whether the current message change count corresponding to the second item attribute change message is greater than the message change count (such as 1) when the second item attribute change message is created: if it is greater, it indicates that the second item attribute change message has changed since its creation, so the second item attribute change message is pushed to the message queue, and the second item attribute change message is deleted from the message cache data to avoid repeated sending; if it is not greater, it indicates that the second item attribute change message has not changed since its creation, so the second item attribute change message is directly deleted from the message cache data to avoid repeated sending.
[0089] In addition, to avoid the residual accumulation of expired second item attribute change messages in the message cache data due to Timer failures, daemon process failures, etc., and to ensure the effective utilization rate of the storage space of the message cache device, it further includes: setting a cache period for the second item attribute change message, so that after the expiration of the cache period, the second item attribute change message is deleted from the message cache data. For example, if the cache period, i.e., TTL (Time To Live), is 100s, the second item attribute change messages that have been stored in the message cache data for 100s will be automatically cleared.
[0090] It should be noted that when the second item attribute change message only indicates one or more item attribute values that are the latest updated as indicated by the first item attribute change message, if the item attributes with updates indicated by the first item attribute change messages obtained successively are different, only the latest updated second item attribute change message is pushed to the message queue, and there will be a situation where updated item attributes are missed, which to a certain extent reduces the high availability of the second item attribute change messages received by the downstream. If the second item attribute change message indicates all the item attribute values corresponding to the item identifier after the latest update according to the first item attribute change message, although the omission of updated item attributes can be avoided, with the rapid increase of item attributes, limited by the size of the message capacity, the number of item attributes with updates indicated in the second item attribute change message is limited.
[0091] Based on this, while avoiding frequent sending of change messages to the downstream in a short period of time and ensuring the high availability of the second item attribute change messages received by the downstream, it further includes: when pushing the second item attribute change message to the message queue, notifying the consumer of the second item attribute change message to obtain the changed item attribute values corresponding to the item identifier from the database through remote procedure call. That is to say, by creating a second item attribute change message, the frequency of sending item attribute change messages to the downstream is reduced, so that while the downstream message consumer is aware of the item attribute change, it queries all the item attribute values that are the latest updated corresponding to the item identifier from the MySQL database storing the attribute information corresponding to the item identifier through the RPC remote procedure call method.
[0092] Based on the above embodiments, by creating or continuously updating the second item attribute change message in the message cache data when receiving the first item attribute change message, the merging of one or more first item attribute change messages obtained is realized, avoiding frequent sending of change messages in a short period of time. Furthermore, it avoids downstream message consumers from frequently updating item attributes in a short period of time, reduces the occupation of the server and bandwidth, and also reduces the waste of resources caused by frequent and ineffective updates of item attributes. At the same time, by directly sending the first item attribute change message through the message queue when creating the second item attribute change message, the immediacy of downstream message consumers receiving the item attribute change message is ensured.
[0093] See Figure 2 , based on the above embodiments, an embodiment of the present invention provides another message processing method, and the steps that this method may specifically include are as follows:
[0094] Step S201, obtain a first item attribute change message, where the first item attribute change message indicates an item identifier and one or more updated item attribute values corresponding to the item identifier.
[0095] Step S202, determine whether a second item attribute change message can be created within the current time period. If it can be created, continue to execute the following step S203; if it cannot be created, continue to execute the following step S204.
[0096] Step S203, based on the fact that a second item attribute change message can be created within the current time period, determine whether the message type corresponding to the first item attribute change message can be used to create the corresponding second item attribute change message. If it can be created, continue to execute the following step S205; if it cannot be created, continue to execute the following step S204.
[0097] Step S204, based on the fact that a second item attribute change message cannot be created, push the first item attribute change message to the message queue.
[0098] Step S205, according to the item identifier, determine whether there is a second item attribute change message corresponding to the item identifier in the message cache data. If it exists, continue to execute the following step S207; if it does not exist, continue to execute the following step S206.
[0099] Step S206, according to the first item attribute change message, create a second item attribute change message corresponding to the item identifier in the message cache data, and push the first item attribute change message to the message queue. In this embodiment, only the case where the number of message changes corresponding to the second item attribute change message is 1 is described here.
[0100] Step S207: Update the second item attribute change message according to the first item attribute change message, and increase the message change count corresponding to the second item attribute change message.
[0101] Step S208: Start a first timing task for the second item attribute change message. In this way, after a first threshold time (such as 30s), it can be determined whether to push the second item attribute change message to the message queue according to the message change count.
[0102] Step S209: After the first threshold time has passed, determine whether the current message change count corresponding to the second item attribute change message is greater than 1, that is, determine whether the second item attribute change message has been updated since it was created. If it is greater than, continue to execute the following step S210; if it is not greater than, continue to execute the following step S211.
[0103] Step S210: Push the second item attribute change message to the message queue, and delete the second item attribute change message deleted from the message cache data.
[0104] Step S211: Directly delete the second item attribute change message from the message cache data. It can be understood that since the corresponding first item attribute change message has been sent when the second item attribute change message was created, in the case where the second item attribute change message has not been updated, to avoid repeated sending, the second item attribute change message can be directly deleted, while saving cache space.
[0105] On this basis, to avoid the Timer from malfunctioning, resulting in the inability to execute the set first timing task normally, and further causing the second item attribute change message to be unable to be sent normally, a periodic second timing task is also set in the way of a daemon process, such as executing once every 10s, to ensure the immediacy and high availability of the downstream message consumer receiving the second item attribute change message. The specific message processing method is as Figure 3 shown, and the corresponding steps are as follows:
[0106] Step S301: Start a second timing task for the message cache data to periodically traverse the second item attribute change messages in the message cache data.
[0107] Step S302: Determine whether the sending time corresponding to the second item attribute change message is less than the current time; where the sending time indicates the sum of the creation time of the second item attribute change message and a second threshold time (such as 30 s). If it is less, it indicates that the second item attribute change message should have been sent but was not, and continue to execute the following step S303; if it is not less, it indicates that the second item attribute change message has not reached the time to be sent by the Timer, end the operation on the second item attribute change message, and continue to traverse other second item attribute change messages.
[0108] Step S303: Determine whether the current message change count corresponding to the second item attribute change message is greater than the message change count corresponding to the creation of the second item attribute change message (i.e., 1). If it is greater, it indicates that the second item attribute change message has changed since its creation, and continue to execute the following step S304; if it is not greater, it indicates that the second item attribute change message has not changed since its creation, and continue to execute the following step S305.
[0109] Step S304: Push the second item attribute change message to the message queue, and delete the second item attribute change message from the message cache data to avoid duplicate sending.
[0110] Step S305: Directly delete the second item attribute change message from the message cache data to avoid duplicate sending.
[0111] See Figure 4 , based on the above embodiments, an embodiment of the present invention provides a message processing device 400, including: an item attribute change message acquisition module 401 and an item attribute change message processing module 402; where,
[0112] The item attribute change message acquisition module 401 is configured to acquire a first item attribute change message, and the first item attribute change message indicates an item identifier and one or more updated item attribute values corresponding to the item identifier;
[0113] The item attribute change message processing module 402 is configured to determine, according to the item identifier, whether there is a second item attribute change message corresponding to the item identifier in the message cache data:
[0114] If not, create a second item attribute change message corresponding to the item identifier in the message cache data according to the first item attribute change message, and push the first item attribute change message to the message queue;
[0115] If it exists, update the second item attribute change message according to the first item attribute change message, and increase the message change count corresponding to the second item attribute change message, so as to determine whether to push the second item attribute change message to the message queue according to the message change count.
[0116] In an alternative embodiment, it further includes: a timing task startup module 403; wherein,
[0117] The timing task startup module is used to, when creating a second item attribute change message corresponding to the item identifier in the message cache data, start a first timing task for the second item attribute change message, so as to determine whether to push the second item attribute change message to the message queue according to the message change count after a first threshold time has elapsed.
[0118] In an alternative embodiment, determining whether to push the second item attribute change message to the message queue according to the message change count includes:
[0119] Determine whether the current message change count corresponding to the second item attribute change message is greater than the message change count corresponding to when the second item attribute change count was created:
[0120] If it is greater, push the second item attribute change message to the message queue, and delete the second item attribute change message from the message cache data;
[0121] If it is not greater, directly delete the second item attribute change message from the message cache data.
[0122] In an alternative embodiment, the timing task startup module 403 is further used for,
[0123] Start a second timing task for the message cache data to periodically traverse the second item attribute change messages in the message cache data;
[0124] And when the sending time corresponding to the second item attribute change message is less than the current time, determine whether to push the second item attribute change message to the message queue according to the message change count; wherein, the sending time indicates the sum of the creation time of the second item attribute change message and a second threshold time.
[0125] In an alternative embodiment, the item attribute change message acquisition module 401 is used to obtain the first item attribute change message by parsing the database log file, and the database is used to store the item identifier and the corresponding item attribute value.
[0126] In an alternative embodiment, the article attribute change message processing module 402 is further configured to,
[0127] When pushing the second article attribute change message to the message queue, notify the consumer of the second article attribute change message to obtain the changed article attribute value corresponding to the article identifier from the database by means of a remote procedure call.
[0128] In an alternative embodiment, the article attribute change message processing module 402 is further configured to,
[0129] Set a cache period for the second article attribute change message, so as to delete the second article attribute change message from the message cache data after the cache period has elapsed.
[0130] In an alternative embodiment, the article attribute change message processing module 402 is further configured to,
[0131] Before determining whether there is a second article attribute change message corresponding to the article identifier in the message cache data according to the article identifier, determine whether the message type corresponding to the first article attribute change message can be used to create a corresponding second article attribute change message.
[0132] In an alternative embodiment, the article attribute change message processing module 402 is further configured to,
[0133] Before determining whether there is a second article attribute change message corresponding to the article identifier in the message cache data according to the article identifier, determine whether a second article attribute change message can be created during the current time period.
[0134] In an alternative embodiment, the second article attribute change message is stored in the message cache data in a key-value pair manner. Specifically, the message data cache devices that can be used include but are not limited to Redis, etc.
[0135] Figure 5 An exemplary system architecture 500 to which the message processing method or message processing device of the embodiments of the present invention can be applied is shown.
[0136] As Figure 5 shown, the system architecture 500 may include terminal devices 501, 502, 503, a network 504, and a server 505. The network 504 is used to provide a medium for communication links between the terminal devices 501, 502, 503 and the server 505. The network 504 may include various connection types, such as wired, wireless communication links, or fiber optic cables, etc.
[0137] Users can use terminal devices 501, 502, and 503 to interact with server 505 via network 504 to receive or send messages, etc. Client applications can be installed on terminal devices 501, 502, and 503.
[0138] Terminal devices 501, 502, and 503 can be various electronic devices with a display screen and supporting web browsing, including but not limited to smartphones, tablets, laptop computers, and desktop computers, etc.
[0139] Server 505 can be a server that provides various services, such as a server for managing the item attributes browsed by users using terminal devices 501, 502, and 503. The background management server can analyze and process the received item attribute change messages, etc., and feedback the processing results as the second item attribute change messages to the terminal devices.
[0140] It should be noted that the message processing method provided by the embodiments of the present invention is generally executed by server 505. Correspondingly, the message processing device is generally set in server 505.
[0141] It should be understood that Figure 5 the numbers of the terminal devices, the network, and the server in
[0142] are merely illustrative. According to the implementation requirements, there can be any number of terminal devices, networks, and servers. Figure 6 The following refers to Figure 6 which shows a schematic structural diagram of a computer system 600 of a terminal device suitable for implementing the embodiments of the present invention.
[0143] As Figure 6 shown, the computer system 600 includes a central processing unit (CPU) 601, which can perform various appropriate actions and processes according to the programs stored in the read-only memory (ROM) 602 or the programs loaded from the storage section 608 into the random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the system 600 are also stored. The CPU 601, the ROM 602, and the RAM 603 are connected to each other through a bus 604. The input / output (I / O) interface 605 is also connected to the bus 604.
[0144] The following components are connected to the I / O interface 605: an input section 606 including a keyboard, a mouse, etc.; an output section 607 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc. and a speaker, etc.; a storage section 608 including a hard disk, etc.; and a communication section 609 including a network interface card such as a LAN card, a modem, etc. The communication section 609 performs communication processing via a network such as the Internet. A drive 610 is also connected to the I / O interface 605 as required. A removable medium 611 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc. is mounted on the drive 610 as required so that a computer program read therefrom is installed into the storage section 608 as required.
[0145] Specifically, according to an embodiment disclosed by the present invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, an embodiment disclosed by the present invention includes a computer program product which includes a computer program carried on a computer-readable medium, and the computer program includes program codes for performing the methods shown in the flowcharts. In such an embodiment, the computer program can be downloaded and installed from a network via the communication section 609, and / or installed from the removable medium 611. When the computer program is executed by a central processing unit (CPU) 601, the above functions defined in the system of the present invention are executed.
[0146] It should be noted that the computer-readable medium shown in the present invention can be a computer-readable signal medium, a computer-readable storage medium, or any combination of the two. A computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples of a computer-readable storage medium can include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium can be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In the present invention, a computer-readable signal medium can include a data signal propagated in a baseband or as part of a carrier wave, which carries computer-readable program code. Such a propagated data signal can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. A computer-readable signal medium can also be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device. The program code contained on a computer-readable medium can be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical fiber, RF, etc., or any suitable combination of the above.
[0147] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architectures, functions, and operations of systems, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in a flowchart or block diagram can represent a module, a program segment, or a part of code that contains one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than marked in the accompanying drawings. For example, two consecutive blocks shown may actually be executed substantially in parallel, and they can sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, can be implemented by a dedicated hardware-based system for performing the specified functions or operations, or can be implemented by a combination of dedicated hardware and computer instructions.
[0148] The modules involved in the embodiments of the present invention can be implemented in software or in hardware. The described units (or "modules") can also be provided in a processor. For example, it can be described as: a processor includes an item attribute change message acquisition module and an item attribute change message processing module. Among them, the names of these modules do not constitute a limitation on the unit itself in some cases. For example, the timing task start module can also be described as "timing task start module module".
[0149] As another aspect, the present invention also provides a computer-readable medium. The computer-readable medium can be included in the device described in the above embodiments; or it can exist alone and not be assembled into the device. The above computer-readable medium carries one or more programs. When the one or more programs are executed by the device, the device includes: acquiring a first item attribute change message, where the first item attribute change message indicates an item identifier and one or more updated item attribute values corresponding to the item identifier; according to the item identifier, determining whether there is a second item attribute change message corresponding to the item identifier in the message cache data: if not, creating, according to the first item attribute change message, a second item attribute change message corresponding to the item identifier in the message cache data, and pushing the first item attribute change message to a message queue; if so, updating the second item attribute change message according to the first item attribute change message, and increasing the message change count corresponding to the second item attribute change message, so as to determine whether to push the second item attribute change message to the message queue according to the message change count.
[0150] According to the technical solution of the embodiments of the present invention, by creating or continuously updating a second item attribute change message in the message cache data when receiving a first item attribute change message, the merging of one or more first item attribute change messages obtained is realized, avoiding frequent sending of change messages in a short time, thereby avoiding frequent updates of item attributes by downstream message consumers in a short time, reducing the occupation of the server and bandwidth, and also reducing the waste of resources caused by frequent ineffective updates of item attributes. At the same time, by directly sending the first item attribute change message through the message queue when creating the second item attribute change message, the immediacy of the downstream message consumer receiving the item attribute change message is ensured.
[0151] The above specific implementation manners do not constitute a limitation on the protection scope of the present invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations and substitutions can occur depending on design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principle of the present invention shall be included within the protection scope of the present invention.
Claims
1. A message processing method, characterized in that, Including: Obtain a first item attribute change message, where the first item attribute change message indicates an item identifier and one or more updated item attribute values corresponding to the item identifier; According to the item identifier, determine whether there is a second item attribute change message corresponding to the item identifier in the message cache data: If not, create a second item attribute change message corresponding to the item identifier in the message cache data according to the first item attribute change message, and push the first item attribute change message to the message queue; If it exists, update the second item attribute change message according to the first item attribute change message, and increase the message change count corresponding to the second item attribute change message, so as to determine whether to push the second item attribute change message to the message queue according to the message change count; Start a second timing task for the message cache data to periodically traverse the second item attribute change messages in the message cache data; And when the sending time corresponding to the second item attribute change message is less than the current time, determine whether to push the second item attribute change message to the message queue according to the message change count, where the sending time indicates the sum of the creation time of the second item attribute change message and a second threshold time, and the second threshold time indicates the duration for using the message cache data to merge one or more first item attribute messages corresponding to the same item identifier.
2. The message processing method according to claim 1, wherein Also including: When creating a second item attribute change message corresponding to the item identifier in the message cache data, start a first timing task for the second item attribute change message to determine whether to push the second item attribute change message to the message queue according to the message change count after a first threshold time.
3. The message processing method according to claim 2, wherein The determining whether to push the second item attribute change message to the message queue according to the message change count includes: Determine whether the current message change count corresponding to the second item attribute change message is greater than the message change count corresponding to when the second item attribute change message is created: If it is greater, push the second item attribute change message to the message queue and delete the second item attribute change message from the message cache data; If it is not greater, directly delete the second item attribute change message from the message cache data.
4. The message processing method according to claim 1 or 3, characterized in that Obtain the first item attribute change message by parsing the database log file, and the database is used to store the item identifier and the corresponding item attribute value.
5. The message processing method according to claim 4, wherein Also including: When pushing the second item attribute change message to the message queue, notify the consumer of the second item attribute change message to obtain the changed item attribute value corresponding to the item identifier from the database by means of remote procedure call.
6. The message processing method according to claim 3, wherein Also including: Set a cache period for the second item attribute change message so that after the cache period elapses, the second item attribute change message is deleted from the message cache data.
7. The message processing method according to claim 1, wherein It further includes: Before determining whether there is a second item attribute change message corresponding to the item identifier in the message cache data according to the item identifier, determine whether the message type corresponding to the first item attribute change message can be used to create a corresponding second item attribute change message.
8. The message processing method according to claim 1, wherein It further includes: Before determining whether there is a second item attribute change message corresponding to the item identifier in the message cache data according to the item identifier, determine whether a second item attribute change message can be created during the current time period.
9. The message processing method according to claim 1, wherein: Store the second item attribute change message in the message cache data in the form of key-value pairs.
10. A message processing device, characterized in that, It includes: An item attribute change message acquisition module, an item attribute change message processing module, and a scheduled task start module; wherein, The item attribute change message acquisition module is used to acquire a first item attribute change message, and the first item attribute change message indicates an item identifier and one or more updated item attribute values corresponding to the item identifier; The item attribute change message processing module is used to determine whether there is a second item attribute change message corresponding to the item identifier in the message cache data according to the item identifier: If not, create a second item attribute change message corresponding to the item identifier in the message cache data according to the first item attribute change message, and push the first item attribute change message to the message queue; If it exists, update the second item attribute change message according to the first item attribute change message, and increase the message change count corresponding to the second item attribute change message, so as to determine whether to push the second item attribute change message to the message queue according to the message change count; The scheduled task start module is used to start a second scheduled task for the message cache data to periodically traverse the second item attribute change messages in the message cache data; and when the sending time corresponding to the second item attribute change message is less than the current time, determine whether to push the second item attribute change message to the message queue according to the message change count, the sending time indicates the sum of the creation time of the second item attribute change message and a second threshold time, and the second threshold time indicates the length of time for using the message cache data to merge one or more first item attribute messages corresponding to the same item identifier.
11. An electronic device for message processing, characterized in that, It includes: One or more processors; A storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1-9.
12. A computer-readable medium having a computer program stored thereon, characterized in that, The program, when executed by the processor, implements the method according to any one of claims 1-9.
Citation Information
Patent Citations
Cache data management method and device
CN107291779A
Out of order data management
US9971987B1