Detailed Description
The present invention will be described in further detail with reference to the accompanying drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the invention and are not limiting of the invention. It should be further noted that, for the convenience of description, only some of the structures related to the present invention are shown in the drawings, not all of the structures.
Before the embodiment of the present invention is described, an application scenario of the embodiment of the present invention is exemplarily described: taking the application scenario of interfacing the third party fresh platform on the public number or H5 page as an example, the order status between the two parties is synchronized by using asynchronous messages. It should be noted that, on one hand, there is a production sequence between the order states belonging to the same order, for example, the creation state, the state to be paid, the paid state, the shipped state, the in-delivery state, and the received state are order states produced in sequence, and then the consumption processes of these order states are also to be consumed according to their respective production sequences, for example, a consumer must ensure that the state to be paid is consumed before consuming the state to be paid, and the correct consumption sequence is a precondition for the order to be effectively performed; on the other hand, the production server where the public number and the H5 page are located and the consumption server where the third-party fresh platform is located are generally servers developed by different developers, so to ensure that the development processes of the two servers do not affect each other, asynchronous messages are used for message synchronization.
On this basis, aiming at the application scene that asynchronous messages are needed to be adopted to synchronize the messages with the sequence, in order to ensure the sequential consumption of the messages and realize the effect of high throughput, the embodiments of the invention provide the following message consumption method and message distribution method.
Example one
Fig. 1 is a flowchart of a message consumption method according to a first embodiment of the present invention. The embodiment can be applied to the condition of ensuring that the messages to be consumed belonging to the same message consumption task are sequentially consumed according to the production sequence, and is particularly suitable for realizing the condition of high throughput while ensuring that the messages to be consumed belonging to the same message consumption task are sequentially consumed according to the production sequence. The method can be executed by the message consumption device provided by the embodiment of the invention, the device can be realized by software and/or hardware, and the device can be integrated on a consumption server.
Referring to fig. 1, the method of the embodiment of the present invention specifically includes the following steps:
s110, determining target partitions corresponding to the consumption servers in all the partitions of the distribution server one by one, acquiring the messages to be consumed from the target partitions, and determining message identifiers of the messages to be consumed, wherein the message identifiers represent message consumption tasks to which the messages to be consumed belong, and the distribution server distributes the messages to be consumed to the target partitions according to the message identifiers.
The production server may be a server for producing the message to be consumed, that is, a server where the producer is located, and may send the message to be consumed produced by the production server to the distribution server. On this basis, the distribution server may be a server for distributing the message to be consumed sent by the production server to a corresponding partition (partition), that is, a server where the message queue is located, and a cluster formed by at least two distribution servers may be referred to as a message cluster, and in an application scenario of the embodiment of the present invention, it may also be referred to as an asynchronous message cluster. In practical applications, optionally, the partition may be a partition under a certain topic (topic), and each message to be consumed may be a message belonging to the same topic. Specifically, the distribution server may distribute the message to be consumed to the corresponding partition according to a message identifier of the message to be consumed, where the message identifier may indicate to which message consumption task the message to be consumed belongs, so that each message to be consumed belonging to the same message consumption task is distributed to the same partition, so as to perform the heap processing on the messages to be consumed. In other words, after the messages to be consumed belonging to the same message consumption task sequentially arrive at the distribution server, the distribution server can distribute the messages to be consumed to the same partition because the message identifications of the messages to be consumed are the same, so that the messages to be consumed are consumed by the same consumption server.
The consumption server may be a server for reading the message to be consumed from the partition and consuming the message to be consumed. In order to ensure the sequential consumption of the messages to be consumed belonging to the same message consumption task, each consumption server can have a partition corresponding to the consumption server one by one, so that the messages to be consumed belonging to the same message consumption task in the partition can be read by the same consumption server. In practical application, optionally, the number of the partitions in the distribution server is the same as the number of the consumption servers, and a one-to-one correspondence relationship exists between each partition and each consumption server. Therefore, for each consumption server, the consumption server can determine a target partition corresponding to the consumption server in a one-to-one manner in each partition of the distribution server, and acquire the message to be consumed from the target partition. At the same time, the consumption server can also determine the message identification of the message to be consumed.
In practical applications, optionally, in combination with an application scenario that may be involved in the embodiment of the present invention, the to-be-consumed message may include an item acquisition status in the item acquisition task, where the item acquisition status may include at least one of a creation status, a to-be-paid status, a shipped status, a in-delivery status, and a received status, and the item acquisition statuses are statuses in which a consumption order exists. In this basic mountain, the message consumption task may be understood as a task of consuming each item acquisition status in a certain item acquisition task.
S120, determining a target memory queue from each memory queue of the consumption server according to the message identifier, and sending the message to be consumed to the target memory queue.
After the messages to be consumed belonging to the same message consumption task sequentially arrive at the consumption server according to the production sequence, in order to ensure the consumption sequence of the messages to be consumed, the messages to be consumed need to enter the same memory queue and be consumed by the same thread. On this basis, considering that the messages to be consumed acquired by the consumption server may be from different message consumption tasks, the consumption server may determine a target memory queue from each memory queue of the consumption server according to the message identifier of each message to be consumed, where the target memory queue may be a memory queue specially used for processing each message to be consumed corresponding to the message identifier; furthermore, the consumption server may send the message to be consumed to the target memory queue, and at this time, each message to be consumed belonging to the same message consumption task enters the same memory queue.
S130, determining target threads corresponding to the target memory queues one by one in the threads of the consumption server, and consuming the messages to be consumed in the target memory queues based on the target threads.
As described above, in order to ensure the consumption sequence of the messages to be consumed belonging to the same message consumption task, the messages to be consumed need to be entered into the same memory queue and consumed by the same thread, at present, the messages to be consumed are already sent to the same memory queue, and then, in order to ensure that the messages can be consumed by the same thread, a one-to-one correspondence relationship may exist between each memory queue and each thread, that is, the number of the memory queues in the consumption server may be set according to the number of the threads in the consumption server, and the number of the threads may be set according to the performance and the service requirements of the consumption server.
Therefore, for the target memory queue where the message to be consumed is located, the consumption server can determine the target threads corresponding to the target memory queue one by one from the threads of the consumption server, and further consume the message to be consumed in the target memory queue based on the target threads, so that the effect that the message to be consumed in the same message consumption task is consumed by the same thread is achieved.
According to the technical scheme of the embodiment of the invention, as the messages to be consumed in each partition in the distribution server are the messages distributed to the partition by the distribution server according to the respective message identifiers, and the message identifiers can represent the message consumption tasks to which the messages to be consumed belong, the consumption server can determine the target partitions corresponding to the consumption server from the partitions one by one, and acquire the messages to be consumed from the target partitions, so that the messages to be consumed belonging to the same message consumption task can be acquired by the same consumption server; for each message to be consumed, the consumption server can determine a target memory queue from each memory queue of the consumption server according to the message identifier of the consumption server and send the message to be consumed to the target memory queue, so that each message to be consumed belonging to the same message consumption task can be sent to the same memory queue; furthermore, the consumption server can determine target threads corresponding to the target memory queues one by one in each thread of the consumption server, and consume the messages to be consumed in the target memory queues based on the target threads, so that the messages to be consumed belonging to the same message consumption task can be consumed by the same thread. According to the technical scheme, the consumption server splits the messages to be consumed according to the message identifications of the messages to be consumed, so that the messages to be consumed belonging to the same message consumption task can enter the same memory queue in the same partition and the same consumption server and are consumed by the same thread, and therefore the consumption sequence of the messages to be consumed is guaranteed; meanwhile, the consumption server acquires the messages to be consumed which are split into the target partition from the target partition corresponding to the consumption server, and splits the acquired messages to be consumed into the corresponding threads respectively for consumption, so that the multi-partition and multi-thread application achieves the effect of high throughput.
Example two
Fig. 2 is a flowchart of a message consumption method provided in the second embodiment of the present invention. The present embodiment is optimized based on the above technical solutions. In this embodiment, optionally, determining the target memory queue from the memory queues of the consumption server according to the message identifier may include: processing the message identifier based on a preset load balancing strategy to obtain a processing identifier; and acquiring the queue number of each memory queue of the consumption server, and determining a target memory queue from each memory queue according to the processing identifier and the queue number. The same or corresponding terms as those in the above embodiments are not explained in detail herein.
Referring to fig. 2, the method of the present embodiment may specifically include the following steps:
s210, determining target partitions corresponding to the consumption servers in all the partitions of the distribution server one by one, acquiring the messages to be consumed from the target partitions, and determining message identifiers of the messages to be consumed, wherein the message identifiers represent message consumption tasks to which the messages to be consumed belong, and the distribution server distributes the messages to be consumed to the target partitions according to the message identifiers.
S220, processing the message identifier based on a preset load balancing strategy to obtain a processing identifier.
The load balancing policy may be a preset policy for balancing and distributing loads (i.e., work tasks) to a plurality of operation units for execution. In combination with the application scenarios that may be related to the embodiments of the present invention, specifically, the load balancing policy may be a policy for processing each message identifier, or may be referred to as a policy for disturbing each message identifier, so that the processing identifiers respectively corresponding to each obtained message identifier exhibit normal distribution (i.e., balanced distribution) as much as possible, and when the load balancing policy is mutually matched with the subsequent steps, each message to be consumed may be distributed in each memory queue as much as possible, so as to fully utilize each memory queue, i.e., fully utilize each resource on the consumption server, and improve throughput to the maximum extent.
S230, acquiring the queue number of each memory queue of the consumption server, determining a target memory queue from each memory queue according to the processing identifier and the queue number, and sending the message to be consumed to the target memory queue.
The method includes the steps of obtaining the number of queues of each memory queue of a consumption server, determining to which memory queue a corresponding message to be consumed can be sent according to the number of queues and a disturbed processing identifier, that is, determining to which memory queue the remaining message to be consumed having the same processing identifier as the message to be consumed has been sent, so as to send the message to be consumed to the memory queue (i.e., a target memory queue), so that the messages to be consumed belonging to the same message consumption task can be sent to the same memory queue.
S240, determining target threads corresponding to the target memory queues one by one in the threads of the consumption server, and consuming the messages to be consumed in the target memory queues based on the target threads.
According to the technical scheme of the embodiment of the invention, the message identification is processed through the preset load balancing strategy to obtain the processing identification, and the distribution trend of the processing identification of each message to be consumed is relatively balanced; and then, determining a target memory queue from the memory queues according to the queue number of the memory queues of the consumption server and the scattered processing identifiers, wherein the target memory queue is a memory queue to which each message to be consumed with the same processing identifier is to be sent, so that the effects that the load of each message to be consumed is balanced and each message to be consumed belonging to the same message consumption task is sent to the same memory queue are achieved.
An optional technical solution, processing a message identifier based on a preset load balancing policy to obtain a processing identifier, may include: mapping the message identifier to obtain a digital type mapping identifier with a preset digit number; updating half of the preset digit to the preset digit, and displacing the mapping identifier based on the preset digit to obtain a displacement identifier; and carrying out XOR processing on the mapping identifier and the displacement identifier to obtain a processing identifier.
Since the message identifiers of the messages to be consumed are not necessarily continuous identifiers, for example, it is assumed that the number of queues in the memory queue is 3, some message identifiers are 1, 4, and 7, and no 2, 3, 5, or 6 exists, and at this time, if the target memory queue is determined directly according to the number of queues and the message identifiers, it is possible to distribute all the messages to be consumed corresponding to all the message identifiers to the 1 st memory queue, that is, the 1 st memory queue is used as the target memory queue corresponding to all the message identifiers, and at this time, the problem of load imbalance obviously exists. In order to solve the problem, the message identifier can be mapped to obtain a mapping identifier of a digital type with preset digits, and the specific setting of the preset digits is related to a specific mapping mode; dividing the result of the preset digit by 2 to be used as the preset digit, and displacing the mapping identifier based on the preset digit, wherein the obtained displacement identifier is an identifier disturbed in displacement; and carrying out XOR processing on the mapping identifier and the displacement identifier, namely carrying out XOR processing on the high order and the low order in the mapping identifier, thereby scattering the distribution of each message identifier on the memory queue and achieving the effect of load balancing on the preset digit.
In order to better understand the implementation process of the above technical solution, a hash code () function is taken as a specific mapping manner as an example, and is exemplarily described herein. Mapping the message identifier to a hash value h of a 32-bit numeric type by calling a hashCode () function, i.e., h ═ hashCode (message identifier); among them, the hashCode function can transform an input of arbitrary length (also called pre-mapping) into an output of fixed length through a hash algorithm, and the output is a hash value. And (2) shifting h to the right by 16 bits, wherein the 16 bits are half of 32 bits, and performing exclusive-or operation with h, namely performing exclusive-or operation on the 16 bits of the high bits and the 16 bits of the low bits in h, namely m ═ h ^ (h > > >16), so that the distribution of the message identifiers on the memory queue is scattered, and the effect of load balancing is achieved, namely normal distribution is basically presented on the numerical value of the 32 bits.
An optional technical solution, determining a target memory queue from each memory queue according to the processing identifier and the number of queues, may include: performing subtraction operation on the number of the queues to obtain the subtracted number, and performing AND operation on the subtracted number and the processing identifiers to obtain the queue numbers; or, carrying out a modulus operation on the queue number and the processing identifier to obtain a queue number; and taking the memory queue corresponding to the queue number in each memory queue as a target memory queue. Each memory queue has its own queue number, and the process of determining the target memory queue in each memory queue may also be understood as a process of determining the queue number of the target memory queue. Accordingly, the process of determining the queue number may be to subtract one from the number of the queue to obtain a subtracted number, and perform an and operation on the subtracted number and the processing identifier to obtain the queue number. It should be noted that, since the operation is equivalent to a modulo operation, the queue number may also be obtained by performing a modulo operation on the queue number and the processing identifier. Compared with the modulus operation, the operation is simpler in the computer implementation process. And then, the memory queue corresponding to the queue number in each memory queue is used as a target memory queue, so that the effect of accurately determining the target memory queue is achieved, and each message to be consumed sent to the target memory queue is a message belonging to the same message consumption task.
In order to better understand the implementation process of the above technical solution, the above example is continued as an example, and an exemplary description is provided. Assuming the number n of queues in the memory queue, performing an and operation on m and (n-1) to obtain a queue number i, i is (n-1) & m, and further taking the memory queue corresponding to i as a target memory queue, thereby ensuring that each message to be consumed in the same message consumption task enters the same memory queue.
In summary, i ═ n-1 & (hashCode (message identifier) ^ (hashCode) > >16)), so that the effects of load balancing and entering of each message to be consumed in the same message consumption task into the same memory queue are achieved. Certainly, the deterministic modification that each message to be consumed in the same message consumption task enters the same memory queue can be performed on the basis of the rest of load balancing strategies, which is not specifically limited herein.
EXAMPLE III
Fig. 3 is a flowchart of a message distribution method provided in the third embodiment of the present invention. The present embodiment is applicable to a case where it is guaranteed that messages to be consumed belonging to the same message consumption task are distributed to the same partition in the distribution server, and is particularly applicable to a case where it is guaranteed that messages to be consumed belonging to the same message consumption task are distributed to the same partition in the distribution server, and their high-throughput consumption in the consumption server in turn is guaranteed in accordance with their respective production order. The method can be executed by the message distribution device provided by the embodiment of the invention, the device can be realized by software and/or hardware, and the device can be integrated on a distribution server.
Referring to fig. 3, the method of the embodiment of the present invention specifically includes the following steps:
s310, receiving the message to be consumed sent by the production server after production, and determining a message identifier of the message to be consumed, wherein the message identifier represents a message consumption task to which the message to be consumed belongs.
The production server may be a server for producing the message to be consumed, that is, a server where the producer is located, and may send the message to be consumed produced by the production server to the distribution server. After receiving the message to be consumed, the distribution server may determine a message identifier indicating a message consumption task to which the message to be consumed belongs.
S320, determining target partitions from all partitions of the distribution server according to the message identifiers, distributing the messages to be consumed to the target partitions, enabling the consumption servers corresponding to the target partitions one by one to send the messages to be consumed acquired from the target partitions to target memory queues determined from all memory queues according to the message identifiers, and consuming the messages to be consumed based on the target threads corresponding to the target memory queues one by one in all threads.
In practical applications, the partition (partition) may be a partition under a certain topic (topic), and each message to be consumed may be a message all belonging to the same topic. The distribution server can distribute the messages to be consumed to corresponding partitions according to the message identifications of the messages to be consumed, and the corresponding partitions can be target partitions corresponding to the message identifications in all the partitions, so that all the messages to be consumed belonging to the same message consumption task can be distributed to the same partition, and the messages to be consumed are processed in a piling mode. In other words, after the messages to be consumed belonging to the same message consumption task sequentially arrive at the distribution server, the distribution server can distribute the messages to be consumed to the same partition because the message identifications of the messages to be consumed are the same, so that the messages to be consumed are consumed by the same consumption server. The message consumption process of the consumption server has been described in detail in the above embodiments, and is not described herein again.
It should be noted that the distribution server may be understood as a server where the message queue is located, and the message queue may be an MQ. A cluster formed by at least two distribution servers may be referred to as a message cluster, and in an application scenario of the embodiment of the present invention, it may also be referred to as an asynchronous message cluster. The message cluster may be a highly available message cluster, i.e. may include a master distribution server and a slave distribution server therein, the number of master distribution servers may be at least one, and the number of slave distribution servers may also be at least one. When the production server sends the messages to be consumed to the message cluster, the production server can send the messages to be consumed to at least one distribution server, and each distribution server can be provided with a catalog for recording which messages to be consumed are stored in each distribution server, so that the consumption server can determine which distribution server the messages to be consumed, which are to be acquired, are located in from the catalog of any distribution server, and the messages to be consumed are acquired from the partitions, which are in one-to-one correspondence with the consumption server, on the distribution server.
According to the technical scheme of the embodiment of the invention, the distribution server receives the message to be consumed sent after production by the production server and determines the message identifier for representing the message consumption task to which the message to be consumed belongs; furthermore, the distribution server determines a target partition from each partition according to the message identifier and distributes the message to be consumed to the target partition, namely, the message to be consumed belonging to the same message consumption task is distributed to the same partition, and the message to be consumed belonging to different message consumption tasks is distributed to different partitions. According to the technical scheme, the distribution server distributes the messages to be consumed according to the message identifications of the messages to be consumed, so that the messages to be consumed belonging to the same message consumption task can enter the same partition and further cooperate with the consumption server, so that the messages to be consumed can enter the same memory queue in the same consumption server again and are further consumed by the same thread, and therefore the consumption sequence of the messages to be consumed is guaranteed; meanwhile, the high-throughput effect is achieved by splitting each message to be consumed into the corresponding partitions and fully utilizing each consumption server.
A selectable technical solution, where determining a target partition from partitions of a distribution server according to a message identifier may include: processing the message identifier based on a preset load balancing strategy to obtain a processing identifier; and acquiring the partition number of each partition of the distribution server, and determining a target partition from each partition according to the processing identifier and the partition number.
The load balancing policy may be a preset policy for balancing and distributing loads (i.e., work tasks) to a plurality of operation units for execution. In combination with the application scenarios that may be related to the embodiments of the present invention, specifically, the load balancing policy may be a policy for processing each message identifier, or may be referred to as a policy for disturbing each message identifier, so that the processing identifiers respectively corresponding to each obtained message identifier exhibit normal distribution (i.e., balanced distribution) as much as possible, and when the load balancing policy is mutually matched with subsequent steps, each message to be consumed may be distributed in each partition as much as possible in a balanced manner, so as to fully utilize the consumption servers corresponding to each partition one to one, and improve throughput to the greatest extent.
When the throughput is improved, it is further required to ensure that the messages to be consumed belonging to the same message consumption task can be distributed to the same partition, at this time, the partition number of each partition of the distribution server may be obtained, and it is determined, according to the partition number and the disturbed processing identifier, to which partition the corresponding message to be consumed can be distributed, that is, it is determined to which partition the remaining messages to be consumed having the same processing identifier as the message to be consumed have been distributed, so as to distribute the message to be consumed to the partition (i.e., the target partition). According to the technical scheme, the effects that the loads of the messages to be consumed are balanced, and the messages to be consumed belonging to the same message consumption task are distributed to the same partition are achieved.
It should be noted that, the process identifier obtaining process may be: mapping the message identifier to obtain a digital type mapping identifier with a preset digit number; updating half of the preset digit to the preset digit, and displacing the mapping identifier based on the preset digit to obtain a displacement identifier; and carrying out XOR processing on the mapping identifier and the displacement identifier to obtain a processing identifier. And/or, the determination process of the target partition may be: carrying out subtraction operation on the number of the partitions to obtain the subtraction number, and carrying out AND operation on the subtraction number and the processing identification to obtain the partition number; or, performing a modulus operation on the partition number and the processing identifier to obtain a partition number; and taking the partition corresponding to the partition number in each partition as a target partition. Of course, other schemes may be used to determine the process identifier and/or the target partition, which are not specifically limited herein.
In order to better understand the specific implementation process of the above steps, the following continues to use the application scenario of interfacing the third party living platform on the public number or H5 page as an example, and the implementation process and the coordination process of the message consumption method and the message distribution method in each embodiment of the present invention are exemplarily described.
Exemplarily, as shown in fig. 4, the following focuses on 2 embodiments of the present invention: message consumption splitting guarantees sequential and high throughput logic and a customized load balancing algorithm (i.e., a load balancing policy) is elaborated.
Message consumption splitting guarantee order + high throughput
In order to ensure that all order states of an order can enter the same partition (partition), the same consumer, the same memory queue and the same thread to realize sequential consumption and high throughput effect,
1) when the order states sequentially reach the message queue (Kafka), the order states of the same order are guaranteed to enter the same partition according to the load balancing algorithm 1. The number of partitions can be determined according to the number of consumers (i.e. consumption servers where the consumers are located), the two are equal, and each partition corresponds to a unique consumer. In addition, Kafka is an implementation under JMQ that is the underlying encapsulated content of the latest version of JMQ.
2) The number of threads supporting high throughput can be set by the consumer according to the performance and business requirements of the consumer to perform message consumption together. Then, the message queues with the same number as the threads are set, and each thread has a unique thread queue corresponding to the thread queue. And after the order state sequence reaches the consumer, ensuring that the order states of the same order enter the same consumer and the same memory queue to be consumed by the same thread according to the load balancing algorithm 2 to ensure the consumption sequence.
Second, customized load balancing algorithm
Suppose that partition or memory queue numbers from 1, as shown in FIG. 4 (1, 2, 3)
1) Calling a hashCode () function to map the order identification of the order into a hash value h of a digital type, namely h ═ hashCode (message identification);
2) the h is shifted to the right by 16 bits and then subjected to exclusive or operation with the h, and m is h ^ (h > > >16), so that the distribution of the order mark on the partition or the memory queue is scattered, and the effect of load balancing is achieved;
3) n is the number of the partition or the memory queue, m and (n-1) are subjected to AND operation to obtain a number i, namely i is (n-1) & m, wherein the memory queue or the partition corresponding to i is the memory queue or the partition to which the order state is to be entered, and as all order states of the same order can enter the same partition or the same memory queue.
In summary, i ═ n-1 & (hashCode (order identification) ^ (hashCode) > > 16)).
Example four
Fig. 5 is a block diagram of a message consumption apparatus according to a fourth embodiment of the present invention, which is configured to execute the message consumption method according to any of the foregoing embodiments. The device and the message consumption method of the above embodiments belong to the same inventive concept, and details that are not described in detail in the embodiments of the message consumption device may refer to the embodiments of the message consumption method described above. Referring to fig. 5, the apparatus may be configured in a consumption server, and may specifically include: a first message identification determination module 410, a to-be-consumed message sending module 420, and a to-be-consumed message consuming module 430.
The first message identifier determining module 410 is configured to determine target partitions, which correspond to the consumption servers in each partition of the distribution server one to one, acquire the message to be consumed from the target partitions, and determine a message identifier of the message to be consumed, where the message identifier indicates a message consumption task to which the message to be consumed belongs, and the distribution server distributes the message to be consumed to the target partitions according to the message identifier;
a message to be consumed sending module 420, configured to determine a target memory queue from each memory queue of the consumption server according to the message identifier, and send the message to be consumed to the target memory queue;
and a message to be consumed consumption module 430, configured to determine a target thread corresponding to the target memory queue in each thread of the consumption server, and consume the message to be consumed in the target memory queue based on the target thread.
Optionally, the to-be-consumed message sending module 420 may specifically include:
the first processing identifier obtaining submodule is used for processing the message identifier based on a preset load balancing strategy to obtain a processing identifier; and the target memory queue determining submodule is used for acquiring the queue number of each memory queue of the consumption server and determining the target memory queue from each memory queue according to the processing identifier and the queue number.
On this basis, optionally, the first processing identifier obtaining sub-module may specifically include:
the mapping identifier obtaining unit is used for mapping the message identifier to obtain a mapping identifier of a digital type with preset digits; a displacement identifier obtaining unit, configured to update half of the preset digit to the preset digit, and displace the mapping identifier based on the preset digit to obtain a displacement identifier; and the processing identifier obtaining unit is used for carrying out XOR processing on the mapping identifier and the displacement identifier to obtain a processing identifier.
On this basis, optionally, the target memory queue determination submodule may specifically include:
a queue number obtaining unit, configured to subtract one from the number of queues to obtain a subtracted number, and perform an and operation on the subtracted number and the processing identifier to obtain a queue number; or, carrying out a modulus operation on the queue number and the processing identifier to obtain a queue number; and the target memory queue determining unit is used for taking the memory queue corresponding to the queue number in each memory queue as the target memory queue.
Optionally, the message to be consumed includes an item acquisition status in the item acquisition task, and the item acquisition status includes at least one of a creation status, a status to be paid, a paid status, a shipped status, a in-delivery status, and a received status.
In the message consumption apparatus provided in the fourth embodiment of the present invention, because each message to be consumed in each partition in the distribution server is a message that is distributed to the partition by the distribution server according to its respective message identifier, which may represent a message consumption task to which the message to be consumed belongs, the consumption server determines, from each partition, a target partition that corresponds to itself one to one by using the first message identifier determining module, and acquires the message to be consumed from the target partition, so that each message to be consumed belonging to the same message consumption task may be acquired by the same consumption server; aiming at each message to be consumed, the consumption server determines a target memory queue from each memory queue of the consumption server through a message sending module to be consumed according to the message identification of the consumption server, and sends the message to be consumed to the target memory queue, so that each message to be consumed belonging to the same message consumption task can be sent to the same memory queue; and then, the consumption server determines target threads corresponding to the target memory queues one by one in each thread of the consumption server through the message consumption module to be consumed, and consumes the messages to be consumed in the target memory queues based on the target threads, so that the messages to be consumed belonging to the same message consumption task can be consumed by the same thread. According to the device, the consumption server splits the messages to be consumed according to the message identifications of the messages to be consumed, so that the messages to be consumed belonging to the same message consumption task can enter the same memory queue in the same partition and the same consumption server and are further consumed by the same thread, and therefore the consumption sequence of the messages to be consumed is guaranteed; meanwhile, the consumption server acquires the messages to be consumed which are split into the target partition from the target partition corresponding to the consumption server, and splits the acquired messages to be consumed into the corresponding threads respectively for consumption, so that the multi-partition and multi-thread application achieves the effect of high throughput.
The message consumption device provided by the embodiment of the invention can execute the message consumption method provided by any embodiment of the invention, and has corresponding functional modules and beneficial effects of the execution method.
It should be noted that, in the embodiment of the message consumption device, the included units and modules are merely divided according to the functional logic, but are not limited to the above division as long as the corresponding functions can be implemented; in addition, specific names of the functional units are only for convenience of distinguishing from each other, and are not used for limiting the protection scope of the present invention.
EXAMPLE five
Fig. 6 is a block diagram of a message distribution apparatus according to a fifth embodiment of the present invention, where the apparatus is configured to execute a message distribution method according to any of the foregoing embodiments. The device and the message distribution method of the above embodiments belong to the same inventive concept, and details that are not described in detail in the embodiments of the message distribution device may refer to the embodiments of the message distribution method described above. Referring to fig. 6, the apparatus may be configured to a distribution server, and specifically includes: a second message identification determination module 510 and a message to be consumed distribution module 520.
The second message identifier determining module 510 is configured to receive a message to be consumed pushed by the production server after production, and determine a message identifier of the message to be consumed, where the message identifier indicates a message consumption task to which the message to be consumed belongs;
the message to be consumed distribution module 520 is configured to determine a target partition from each partition of the distribution server according to the message identifier, distribute the message to be consumed to the target partition, so that the consumption server corresponding to the target partition sends the message to be consumed acquired from the target partition to a target memory queue determined from each memory queue according to the message identifier, and consume the message to be consumed based on a target thread corresponding to the target memory queue in each thread.
Optionally, the to-be-consumed message distribution module 520 may specifically include:
the second processing identifier obtaining submodule is used for processing the message identifier based on a preset load balancing strategy to obtain a processing identifier;
and the target partition determining submodule is used for acquiring the partition number of each partition of the distribution server and determining the target partition from each partition according to the processing identifier and the partition number.
In the message distribution device provided by the fifth embodiment of the present invention, the distribution server receives the message to be consumed sent after production by the production server through the second message identifier determining module, and determines the message identifier used for representing the message consumption task to which the message to be consumed belongs; furthermore, the distribution server determines a target partition from each partition according to the message identifier through the message distribution module to be consumed, and distributes the message to be consumed to the target partition, namely, distributes the message to be consumed belonging to the same message consumption task to the same partition, and distributes the message to be consumed belonging to different message consumption tasks to different partitions. According to the device, the distribution server distributes the messages to be consumed according to the message identifications of the messages to be consumed, so that the messages to be consumed belonging to the same message consumption task can enter the same partition and further cooperate with the consumption server, so that the messages can enter the same memory queue in the same consumption server again and are consumed by the same thread, and therefore the consumption sequence of the messages to be consumed is guaranteed; meanwhile, the high-throughput effect is achieved by splitting each message to be consumed into the corresponding partitions and fully utilizing each consumption server.
The message distribution device provided by the embodiment of the invention can execute the message distribution method provided by any embodiment of the invention, and has corresponding functional modules and beneficial effects of the execution method.
It should be noted that, in the embodiment of the message distribution apparatus, each included unit and module are merely divided according to functional logic, but are not limited to the above division as long as the corresponding functions can be implemented; in addition, specific names of the functional units are only for convenience of distinguishing from each other, and are not used for limiting the protection scope of the present invention.
EXAMPLE six
Fig. 7 is a schematic structural diagram of a consumption server according to a sixth embodiment of the present invention, and as shown in fig. 7, the consumption server includes a memory 610, a processor 620, an input device 630, and an output device 640. The number of processors 620 in the consumption server may be one or more, and one processor 620 is taken as an example in fig. 7; the memory 610, processor 620, input device 630, and output device 640 in the consumption server may be connected by a bus or other means, such as by bus 650 in fig. 7.
The memory 610, which is a computer-readable storage medium, may be used to store software programs, computer-executable programs, and modules, such as program instructions/modules corresponding to the message consumption method in the embodiment of the present invention (e.g., the first message identification determination module 410, the message to be consumed transmission module 420, and the message to be consumed consumption module 430 in the message consumption device). The processor 620 executes various functional applications of the consumption server and data processing by executing software programs, instructions, and modules stored in the memory 610, that is, implements the message consumption method described above.
The memory 610 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application program required for at least one function; the storage data area may store data created according to the use of the consumption server, and the like. Further, the memory 610 may include high speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other non-volatile solid state storage device. In some examples, memory 610 may further include memory located remotely from processor 620, which may be connected to devices through a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The input device 630 may be used to receive input numeric or character information and generate key signal inputs related to user settings and function controls of the device. The output device 640 may include a display device such as a display screen.
EXAMPLE seven
Fig. 8 is a schematic structural diagram of a distribution server according to a seventh embodiment of the present invention, and as shown in fig. 8, the distribution server includes a memory 710, a processor 720, an input device 730, and an output device 740. The number of the processors 720 in the distribution server may be one or more, and one processor 720 is taken as an example in fig. 8; the memory 710, processor 720, input device 730, and output device 740 in the distribution server may be connected by a bus or other means, such as by bus 750 in fig. 8.
The memory 710 is used as a computer-readable storage medium for storing software programs, computer-executable programs, and modules, such as program instructions/modules corresponding to the message distribution method in the embodiment of the present invention (for example, the second message identification determination module 510 and the message to be consumed distribution module 520 in the message distribution apparatus). The processor 720 executes various functional applications and data processing of the distribution server by executing software programs, instructions and modules stored in the memory 710, that is, implements the message distribution method described above.
The memory 710 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application program required for at least one function; the storage data area may store data created according to the use of the distribution server, and the like. Further, the memory 710 may include high speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other non-volatile solid state storage device. In some examples, memory 710 may further include memory located remotely from processor 720, which may be connected to devices through a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The input device 730 may be used to receive input numeric or character information and generate key signal inputs related to user settings and function controls of the device. The output device 740 may include a display device such as a display screen.
Example eight
An eighth embodiment of the present invention provides a storage medium containing computer-executable instructions, which when executed by a computer processor, are configured to perform a message consumption method applied to a consumption server, where the method includes:
determining target partitions corresponding to the consumption servers in all partitions of the distribution server one by one, acquiring the messages to be consumed from the target partitions, and determining message identifiers of the messages to be consumed, wherein the message identifiers represent message consumption tasks to which the messages to be consumed belong, and the distribution server distributes the messages to be consumed to the target partitions according to the message identifiers;
determining a target memory queue from each memory queue of the consumption server according to the message identifier, and sending the message to be consumed to the target memory queue;
and determining target threads corresponding to the target memory queues one by one in each thread of the consumption server, and consuming the messages to be consumed in the target memory queues based on the target threads.
Of course, the storage medium provided by the embodiment of the present invention contains computer-executable instructions, and the computer-executable instructions are not limited to the method operations described above, and may also perform related operations in the message consumption method provided by any embodiment of the present invention.
Example nine
An embodiment of the present invention provides a storage medium containing computer-executable instructions, where the computer-executable instructions are executed by a computer processor to perform a message distribution method applied to a distribution server, and the method includes:
receiving a message to be consumed pushed after the production of a production server, and determining a message identifier of the message to be consumed, wherein the message identifier represents a message consumption task to which the message to be consumed belongs;
and determining a target partition from each partition of the distribution server according to the message identifier, distributing the message to be consumed to the target partition, so that the consumption server which corresponds to the target partition one by one sends the message to be consumed acquired from the target partition to a target memory queue determined from each memory queue according to the message identifier, and consumes the message to be consumed based on the target thread which corresponds to the target memory queue one by one in each thread.
Of course, the storage medium provided by the embodiment of the present invention contains computer-executable instructions, and the computer-executable instructions are not limited to the method operations described above, and may also perform related operations in the message distribution method provided by any embodiment of the present invention.
From the above description of the embodiments, it is obvious for those skilled in the art that the present invention can be implemented by software and necessary general hardware, and certainly, can also be implemented by hardware, but the former is a better embodiment in many cases. With this understanding, the technical solutions of the present invention may be embodied in the form of a software product, which can be stored in a computer-readable storage medium, such as a floppy disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a FLASH Memory (FLASH), a hard disk or an optical disk of a computer, and includes instructions for enabling a computer device (which may be a personal computer, a server, or a network device) to execute the methods according to the embodiments of the present invention.
It is to be noted that the foregoing is only illustrative of the preferred embodiments of the present invention and the technical principles employed. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the invention. Therefore, although the present invention has been described in greater detail by the above embodiments, the present invention is not limited to the above embodiments, and may include other equivalent embodiments without departing from the spirit of the present invention, and the scope of the present invention is determined by the scope of the appended claims.