Disclosure of Invention
The embodiment of the application provides a message pushing method, a message pushing device, electronic equipment and a storage medium, which are used for realizing the consistency of the execution of local transactions and the sending of messages.
In a first aspect, an embodiment of the present application provides a message pushing method, which is applied to a first device, and includes:
sending a first message to a first message queue of second equipment, wherein the first equipment corresponds to a first user, and the first message is used for indicating the second user to execute preset operation;
Executing a first transaction, and generating a second message according to an execution result of the first transaction, wherein the second message is used for indicating whether to push the first message to the second user;
and sending the second message to the first message queue.
In a possible implementation manner of the first aspect, the generating a second message according to an execution result of the first transaction includes:
when the execution result of the first transaction is successful, carrying a first push instruction in the second message, wherein the first push instruction is used for indicating to push the first message to the second user;
and when the execution result of the first transaction is failure, carrying a second push instruction in the second message, wherein the second push instruction is used for indicating that the first message is not pushed to the second user.
In a possible implementation manner of the first aspect, the method further includes:
and when the execution result of the first transaction is successful, sending the first message to a database.
In a possible implementation manner of the first aspect, the sending the first message to the first message queue of the second device includes:
Obtaining identification information of a target area where the other messages are located according to the sending sequence relation between the first message and the other messages, wherein the target area is one area of the first message queue, and the processing sequence and the arrangement sequence of the messages in the target area are consistent;
and storing the first message on the target area according to the identification information of the target area.
In a second aspect, an embodiment of the present application provides a message pushing method, applied to a second device, where the method includes:
inquiring a first message from a first message queue in the second device, wherein the first message is used for indicating a second user to execute preset operation;
inquiring a second message from the first message queue within a preset time, wherein the second message is used for indicating whether to push the first message to the second user;
and determining whether to push the first message to the second user according to the second message.
In a possible implementation manner of the second aspect, the determining whether to push the first message to the second user according to the second message includes:
determining to push the first message to the second user when the second message carries a first push instruction, wherein the first push instruction is used for indicating to push the first message to the second user;
And when the second message carries a second pushing instruction, determining that the first message is not pushed to the second user, wherein the second pushing instruction is used for indicating that the first message is not pushed to the second user.
In a possible implementation manner of the second aspect, the method further includes:
inquiring an execution result of a first transaction from the first equipment when the second message is not inquired from the first message queue within the preset time;
pushing the first message to the second user when the execution result of the first transaction is successful;
and when the execution result of the first transaction is failure, not pushing the first message to the second user.
In a possible implementation manner of the second aspect, the method further includes:
inquiring the first message from a database when the second message is not inquired from the first message queue within the preset time;
pushing the first message to the second user when the first message is queried in the database;
and when the first message is not queried in the database, not pushing the first message to the second user.
In a possible implementation manner of the second aspect, the method further includes:
querying the first message from the database when the first message is not queried in the first message queue;
pushing the queried first message to the second user.
In a possible implementation manner of the second aspect, the second device further includes a second message queue, and the pushing the first message to the second user includes:
sending the first message to the second message queue;
and pushing the first message in the second message queue to the second user when the preset condition is met.
In a possible implementation manner of the second aspect, the first message queue and/or the second message queue includes a first storage area and a second storage area, where the first message is stored in the first storage area and the second storage area, respectively.
In a possible implementation manner of the second aspect, the method further includes:
writing a position offset of the first message in the first message queue into the first message queue when the first message is submitted to the second message queue; and/or
And when the first message is sent to the second user, writing the position offset of the first message in the second message queue into the second message queue.
In a possible implementation manner of the second aspect, the first message is stored in a target tile of the first message queue, where the target tile is a tile of the first message queue, and a processing order of messages in the target tile is consistent with a ranking order.
In a possible implementation manner of the second aspect, the sending the first message to the second message queue includes:
and sending the first message to a patch corresponding to the identification of the target patch in the second message queue according to the identification of the target patch.
In a third aspect, an embodiment of the present application provides a message pushing apparatus, where the message pushing apparatus is applied to a first device, the message pushing apparatus includes: a transmitting unit and a processing unit.
The sending unit is used for sending a first message to a first message queue of the second device, the first device corresponds to a first user, and the first message is used for indicating the second user to execute a preset operation;
The processing unit is used for executing a first transaction and generating a second message according to an execution result of the first transaction, wherein the second message is used for indicating whether to push the first message to the second user or not;
and the sending unit is also used for sending the second message to the first message queue.
In a possible implementation manner of the third aspect, the processing unit is specifically configured to carry a first push instruction in the second message when an execution result of the first transaction is successful, where the first push instruction is used to instruct to push the first message to the second user; and when the execution result of the first transaction is failure, carrying a second push instruction in the second message, wherein the second push instruction is used for indicating that the first message is not pushed to the second user.
In a possible implementation manner of the third aspect, the sending unit is further configured to send the first message to a database when an execution result of the first transaction is successful.
In a possible implementation manner of the third aspect, the sending unit is specifically configured to obtain, according to a sending sequence relationship between the first message and the other messages, identification information of a target tile where the other messages are located, where the target tile is a tile of the first message queue, and a processing sequence and an arrangement sequence of messages in the target tile are consistent; and storing the first message on the target area according to the identification information of the target area.
In a fourth aspect, an embodiment of the present application provides a message pushing apparatus, where the message pushing apparatus is applied to a second device, where the message pushing apparatus may include: a processing unit;
the processing unit is used for inquiring a first message from a first message queue in the second equipment, and the first message is used for indicating a second user to execute preset operation; inquiring a second message from the first message queue within a preset time, wherein the second message is used for indicating whether to push the first message to the second user;
and the processing unit is also used for determining whether to push the first message to the second user according to the second message.
In some embodiments, the processing unit is specifically configured to determine to push the first message to the second user when the second message carries a first push instruction, where the first push instruction is used to instruct to push the first message to the second user; and when the second message carries a second pushing instruction, determining that the first message is not pushed to the second user, wherein the second pushing instruction is used for indicating that the first message is not pushed to the second user.
In some embodiments, the above apparatus further comprises a transmitting unit;
The processing unit is further configured to query an execution result of a first transaction from the first device when the second message is not queried from the first message queue within the preset time;
a sending unit, configured to push the first message to the second user when the execution result of the first transaction is successful; and when the execution result of the first transaction is failure, not pushing the first message to the second user.
In some embodiments, the processing unit is further configured to query the database for the first message when the second message is not queried from the first message queue within the preset time;
the sending unit is further used for pushing the first message to the second user when the first message is queried in the database; and when the first message is not queried in the database, not pushing the first message to the second user.
In some embodiments, the processing unit is further configured to query the first message from the database when the first message is not queried in the first message queue;
and the sending unit is also used for pushing the queried first message to the second user.
In some embodiments, the sending unit is specifically configured to send the first message to the second message queue; and pushing the first message in the second message queue to the second user when the preset condition is met.
In some embodiments, the first message queue and/or the second message queue includes a first storage area and a second storage area, the first storage area and the second storage area having the first message stored therein, respectively.
In some embodiments, the sending unit is further configured to, when submitting the first message to the second message queue, write a position offset of the first message in the first message queue into the first message queue; and/or writing a position offset of the first message in the second message queue into the second message queue when the first message is sent to the second user.
In some embodiments, the first message is stored on a target tile of the first message queue, the target tile is a tile of the first message queue, and a processing order of messages in the target tile is consistent with a ranking order.
In some embodiments, the sending unit is specifically configured to send the first message to a tile corresponding to the identifier of the target tile in the second message queue according to the identifier of the target tile.
In a fifth aspect, embodiments of the present application further provide an electronic device, including a memory and a processor;
the memory is used for storing a computer program;
the processor is configured to execute the computer program to implement the message pushing method according to any one of the first aspect.
In a sixth aspect, embodiments of the present application further provide an electronic device, including a memory and a processor;
the memory is used for storing a computer program;
the processor is configured to execute the computer program to implement the message pushing method according to any one of the second aspect.
In a seventh aspect, embodiments of the present application provide a computer-readable storage medium, the storage medium including computer instructions that, when executed by a computer, cause the computer to implement a message pushing method according to any one of the first or second aspects.
In an eighth aspect, embodiments of the present application provide a computer program product comprising a computer program stored in a readable storage medium, from which at least one processor of a computer can read, the at least one processor executing the computer program causing the computer to implement the message pushing method of any one of the first or second aspects.
According to the message pushing method, the electronic device and the storage medium, the first device pushes the first message to the first message queue of the second device, then the first device executes the first transaction, and generates the second message according to the execution result of the first transaction, wherein the second message is used for indicating whether to push the first message to the second user. The first device sends the generated second message to the first message queue. The second device queries the first message from the first message queue, queries the second message in the first message queue within a preset time, and determines whether to push the first message to the second user according to the second message. In other words, in the embodiment of the present application, the first device sends the first message to the first message queue in advance, and sends the second message to the first message queue according to the execution result of the first transaction, so that the second device can determine whether to send the first message according to the execution result of the first transaction, thereby preventing the problem that the first transaction is successfully executed but the first message is failed to be sent, or the problem that the first transaction is failed to be executed but the first message is successfully sent from being generated, and further ensuring that the execution condition of the first transaction is consistent with the pushing condition of the first message.
Detailed Description
The technical solutions in the embodiments of the present application will be described below with reference to the drawings in the embodiments of the present application.
It should be understood that in embodiments of the present invention, "B corresponding to a" means that B is associated with a. In one implementation, B may be determined from a. It should also be understood that determining B from a does not mean determining B from a alone, but may also determine B from a and/or other information.
In the description of the present application, unless otherwise indicated, "a plurality" means two or more than two.
In addition, in order to clearly describe the technical solutions of the embodiments of the present application, in the embodiments of the present application, the words "first", "second", and the like are used to distinguish the same item or similar items having substantially the same function and effect. It will be appreciated by those of skill in the art that the words "first," "second," and the like do not limit the amount and order of execution, and that the words "first," "second," and the like do not necessarily differ.
In order to facilitate understanding of the embodiments of the present application, the following brief description will be first given to related concepts related to the embodiments of the present application:
a message is understood to be a data, basic unit of communication, consisting of a fixed length header and a variable length body, commonly referred to as the sender of the message and the recipient of the message as the consumer.
Message systems are systems in which a producer places information to be sent into a container (commonly referred to as a Message), stores the container in a Message Queue (Message Queue) in a system public space, and a consumer takes out the Message from the Message Queue and processes the Message.
Messaging systems generally fall into two categories: point-to-point (peer) messaging systems and subscription (Publish) messaging systems. Among other things, point-to-point (peer-to-peer) messaging systems are characterized by supporting unicast, typically based on either polling (polling) or pulling (pull) an accept message; messages sent to a message queue are accepted by one and only one consumer, even if multiple recipients listen to the same message in the same queue; an asynchronous messaging mode of "instant-and-discard" is supported, while a synchronous messaging mode of "request-reply" is supported. The features of a subscription-to-publish (sub/pub) message system support multicasting and unicasting, e.g., kafka as a typical subscription-to-publish (sub/pub) message system that supports multicasting for different consumer groups while supporting unicasting in the same consumer group. In addition, messages posted to a topic may be accepted by multiple consumers; push, pull, polling is supported to accept messages in three ways and has higher decoupling capacity than point-to-point.
Topic (topic) is a classification of messages that a producer sends to a particular topic that consumers subscribe to for consumption or a partition of the topic.
A Message Queue (MQ) is a container that holds messages during their transmission. Message queues are important components in a distributed system, and mainly solve the problems of application coupling, asynchronous messages, flow cutting and the like. The realization of high performance, high availability, scalability and final consistency architecture is an indispensable middleware for large distributed systems.
FIG. 1 is a schematic diagram of an execution flow of a conventional message system, as shown in FIG. 1, assuming that a producer a needs to execute a local transaction, and sends a message to tell a consumer b to execute a related operation after the transaction is executed successfully, the method specifically includes the following steps:
step 1, a producer a executes a local transaction to complete the operation of the local transaction;
step 2, after the local transaction is successfully executed, the producer a sends a message to a message system, and the message system transmits the message to each consumer;
step 3, consumer b consumes the message generated by producer a from the messaging system.
However, if the producer a fails to send the message in step 2, the execution of the local transaction will succeed, but the consumer b cannot receive the message, so that the problem of inconsistent execution of the local transaction and sending of the message is caused.
In order to solve the above technical problems, the embodiments of the present application provide a message pushing method, first, a first device corresponding to a producer (i.e., a first user) pre-stores a first message to be sent in a first message queue of a second device, then, the first device executes a first transaction, generates a second message according to an execution result of the first transaction, and stores the generated second message in the first message queue. The second message is generated according to the execution result of the first transaction, which can reflect the execution condition of the first transaction, so that the second device pulls the second message from the first message queue, and can determine whether to push the first message to the consumer (namely the second user) according to the indication of the second message, thereby ensuring that the push condition of the first message is consistent with the execution result of the first task.
Fig. 2 is a schematic diagram of a messaging system architecture according to an embodiment of the present application, including: a first device 101, a second device 102, a third device 103 and a database 104.
The first device 101 corresponds to a first user, and may be a terminal device used by the first user, for example, a mobile phone, a notebook, a desktop computer, a smart television, a vehicle-mounted device, a wearable device, an industrial device, and the like. Alternatively, the first device 101 may also be a server on the side of the first user, with which the first user is communicatively connected via a client. The first device 101 is communicatively coupled to the second device 102 and may send a first message and a second message to the second device 102.
The second device 102 may be one or more servers, or a cluster of servers, the second device 102 being communicatively connected to the first device 101. Optionally, the second device 102 comprises a messaging system for pushing the first message. The second device 102 further comprises a first message queue into which the first device 101 sends both the generated first message and the second message, from which the second device 102 pulls the first message and the second message.
The third device 103 corresponds to a second user, and may be a terminal device used by the second user, for example, a mobile phone, a notebook, a desktop computer, a smart television, a vehicle-mounted device, a wearable device, an industrial device, or the like. Alternatively, the third device 103 may also be a server on the second user side, with which the second user is communicatively connected via a client. The third device 103 is communicatively coupled to the second device 102 and may consume the first message from the second device 102 or receive the first message sent by the second device 102.
The first device 101, the second device 102, and the third device 103 may perform read and write operations on the database 104, e.g., the first device 101 may submit the first transaction to the database and/or deposit the first message to the database. The second device 102 and the third device 103 may read the first message from the database 104.
It should be noted that fig. 2 is only a schematic diagram of a messaging system architecture provided in the embodiments of the present application, and the positional relationship between the devices shown in the drawings does not constitute any limitation. In some embodiments, the database 104 may be distributed across one server or across multiple servers.
The following describes the technical solutions of the embodiments of the present application in detail through some embodiments. The following embodiments may be combined with each other, and some embodiments may not be repeated for the same or similar concepts or processes.
Fig. 3 is a schematic flow chart of a message pushing method provided in the embodiment of the present application, as shown in fig. 3, where the method in the embodiment of the present application includes:
s301, the first device sends a first message to a first message queue of the second device.
Fig. 4 is a schematic view of an application scenario in an embodiment of the present application, as shown in fig. 4, a first user may be understood as a sender, that is, a producer, of a first message, where the first user communicates with a second device through a first device, where the second device includes a first message queue, and the first user sends the first message to the first message queue of the second device through the first device. The second user may be one or more, which is not limited in this embodiment of the present application.
Specifically, the first device responds to the operation of the first user, generates a first message, and sends the first message to a first message queue of the second device. It should be noted that, the first message is related to the first transaction, and the first message is used to instruct the second user to perform the preset operation. For example, taking the first transaction as an example of paying the electric charge, the first user is an electric charge paying person, the second user is a charging person of the electric company, and the first message is used for indicating the charging person of the electric company to charge in the account of the first user. For example, taking the first transaction as a video subscription, the first user may be a video publisher, and the second user may be a video subscriber, the first message is used to instruct the second user to watch the video uploaded by the first user. It should be noted that the preset operations corresponding to different application scenarios are different.
In the embodiment of the application, before the first device executes the first transaction, the first message is pre-stored in a first message queue of the second device, then the first transaction is executed, and whether the first message is sent to the second user is determined according to the execution result of the first transaction. Compared with the prior art, after the first transaction is executed, the first message is directly sent to the second user through the second device, the embodiment of the application can ensure that the execution condition of the first transaction is consistent with the pushing condition of the first message, and prevent the problems that the execution of the first transaction is successful but the sending of the first message is failed or the execution of the first transaction is failed but the sending of the first message is successful.
S302, the first device executes the first transaction and generates a second message according to the execution result of the first transaction.
Specifically, after the first device sends the first message to the first message queue of the second device, the first device executes the first transaction, and generates a second message according to an execution result of the first transaction, where the second message is used to indicate whether to push the first message to the second user.
In some embodiments, the step S302 includes the following:
in case 1, when the execution result of the first transaction is successful, the first push instruction is carried in the second message, where the first push instruction is used to instruct to push the first message to the second user.
And 2, carrying a second push instruction in the second message when the execution result of the first transaction is failure, wherein the second push instruction is used for indicating that the first message is not pushed to the second user.
In some examples, the correspondence between the push instruction carried by the second message and the push condition of the first message is shown in table 1:
TABLE 1
Push instruction
|
Push case of first message
|
1
|
Push-out
|
0
|
Not push |
As shown in table 1, the first push instruction is 1, the second push instruction is 0, and when the second message carries 1, the second message indicates that the second device may push the first message to the second user, and when the second message carries 0, the second message indicates that the second device does not push the first message to the second user. It should be noted that, table 1 is only an example, and the first push instruction and the second push instruction may also be in other forms, for example, the first push instruction is 0, the second push instruction is 1, or the first push instruction is 01, the second push instruction is 11, etc., which are not limited in the embodiment of the present application.
That is, in the embodiment of the present application, the first device completes execution of the first transaction, and generates the second message according to the execution result of the first transaction. By way of illustration, with continued reference to the above example, taking the first transaction as an example of paying the electric charge, when the first device succeeds in paying the electric charge, the first device carries the first push instruction in the second message, and when the first device fails in paying the electric charge, the first device carries the second push instruction in the second message, so as to further realize that the second message is generated according to whether the electric charge is successfully paid. Taking a first transaction as an example of video subscription, the first device makes and uploads a video, when the video uploading is successful, the first device carries a first push instruction in the second message, and when the video uploading fails, the first device carries the second push instruction in the second message, so that the second message is generated according to the success or failure of the video uploading.
S303, the first device sends the second message to the first message queue.
Specifically, after the first device generates the second message, the second message is sent to the first message queue. The second message corresponds to the first message one by one, and optionally, in order to facilitate matching between the subsequent second message and the first message, the second message may be stored after or before the first message and adjacent to the first message. Optionally, the message header of the second message carries the identifier of the first message, so that the first message corresponding to the second message is determined through the identifier of the first message carried by the second message.
S304, the second device queries the first message from the first message queue in the second device.
Specifically, the first device stores both the first message and the second message in the first message queue of the second device according to the steps S301 to S303. In this way, the second device may query the first message from the first message queue.
S305, the second device queries the second message from the first message queue in the preset time.
It can be known from the above that the second message is sent to the first message queue by the first device after the first message, so the second device may not be able to query the first message queue for the second message immediately after querying the first message from the first message queue, and therefore, the second device may query the first message queue for the second message within a preset time. The preset time is specifically set according to actual needs, and the embodiment of the application does not limit the preset time.
S306, the second device determines whether to push the first message to the second user according to the second message.
After the second device queries the first message and the second message in the first message queue, it determines whether to push the first message to the second user according to the second message. As can be seen from S302, if the second message carries the first push instruction or the second push instruction, the second device parses the second message, and determines whether to push the first message to the second user according to the first push instruction or the second push instruction carried by the second message. Specifically, when the second message carries the first pushing instruction, the second device determines to push the first message to the second user, and pushes the first message to the second user, specifically to a third device corresponding to the second user. When the second message carries the second push instruction, the second device determines not to push the first message to the second user, in which case the second device may discard the obtained first message.
Optionally, after the second device pushes the first message to the second user, the first message is marked in the first message queue to prevent repeated consumption.
According to the message pushing method provided by the embodiment, the first device pushes the first message to the first message queue of the second device, then the first device executes the first transaction, and generates the second message according to the execution result of the first transaction, wherein the second message is used for indicating whether to push the first message to the second user. The first device sends the generated second message to the first message queue. The second device queries the first message from the first message queue, queries the second message in the first message queue within a preset time, and determines whether to push the first message to the second user according to the second message. In other words, in the embodiment of the present application, the first device sends the first message to the first message queue in advance, and sends the second message to the first message queue according to the execution result of the first transaction, so that the second device can determine whether to send the first message according to the execution result of the first transaction, thereby preventing the problem that the first transaction is successfully executed but the first message is failed to be sent, or the problem that the first transaction is failed to be executed but the first message is successfully sent from being generated, and further ensuring that the execution condition of the first transaction is consistent with the pushing condition of the first message.
In some embodiments, the first device may also send the generated first message to the database when the first transaction execution is successful, e.g., the first device saves the first transaction together with the first message to the database when the first transaction execution is successful, or the first device saves only the first message to the database when the first transaction execution is successful, and the first transaction is not saved in the database. At this time, on the basis of the above embodiment, the embodiment of the present application further includes a message pushing method as shown in fig. 5.
Fig. 5 is a schematic flow chart of a message pushing method provided in the embodiment of the present application, as shown in fig. 5, where the method in the embodiment of the present application includes:
s501, the second device queries the first message from the first message queue.
Fig. 6 is a schematic diagram of an application scenario in the embodiment of the present application, where when the first transaction is executed successfully, the first device sends a first message to the second device, and stores a first message in a database. At the same time, the second device and the third device may each read the first message from the database.
However, as shown in fig. 7, although the first device transmits the first message to the first message queue, the first message transmission fails due to a network or the like, and at this time, the second device may not be able to query the first message in the first message queue. In the case that the second device does not inquire about the first message in the first message queue, the following steps S502 and S503 are performed.
S502, when the second device does not inquire the first message in the first message queue, inquiring the first message from the database.
S503, the second device pushes the queried first message to the second user.
Specifically, when the second device does not inquire the first message in the first message queue, the second device inquires the first message from the database, and because the first message is sent to the database by the first device when the first device executes the first transaction successfully, when the second device inquires the first message in the database, the first device executes the first transaction successfully, the second device pushes the inquired first message to the second user, and further when the first transaction is executed successfully, the first message is sent to the second user, and the execution result of the first transaction is ensured to be consistent with the sending condition of the first message.
If the second device queries the first message in the first message queue, the following steps S504 and S505 are performed, or the following steps S504 and S506 are performed, or the following steps S505 and S507 are performed.
S504, the second device queries the second message from the first message queue in the preset time.
If the second device queries the first message queue for a second message, S505 is performed.
S505, inquiring the second message in the first message queue, and determining whether to push the first message to the second user according to the second message.
Specifically, if the second device queries the second message from the first message queue within the preset time, it may determine whether to push the first message to the second user according to the second message, where the specific process is consistent with S306, and the description of S306 is omitted herein.
In some embodiments, as shown in fig. 8, although the first device transmits the second message to the first message queue, the second message transmission may fail due to a network or the like. At this time, there is a possibility that the second device cannot query the second message from the first message queue within a preset time. If the second device does not find the second message in the first message queue, the step of S506 or 507 is performed. The two parallel technical schemes are S506 and S507.
Mode one as S506:
s506, when the second device does not inquire the second message from the first message queue within the preset time, inquiring the execution result of the first transaction from the first device, pushing the first message to the second user when the execution result of the first transaction is successful, and not pushing the first message to the second user when the execution result of the first transaction is failed.
Specifically, the first device provides a reverse check interface for the second device, and when the second device does not inquire the second message from the first message queue within a preset time, the second device inquires an execution result of the first transaction stored in the first device through the reverse check interface. And pushing the first message to the second user when the execution result of the first transaction executed by the first device is found to be successful, and not pushing the first message to the second user when the execution result of the first transaction executed by the first device is found to be failed. Therefore, when the second message is sent in failure, the second device can still determine whether to push the first message according to the execution result of the first transaction, and further, the push of the first message is ensured to be consistent with the execution condition of the first transaction.
Mode two is as S507:
s507, when the second device does not inquire the second message from the first message queue within the preset time, inquiring the first message from the database, pushing the first message to the second user when the first message is inquired in the database, and not pushing the first message to the second user when the first message is not inquired in the database.
Specifically, since the first device stores a first message in the database when the first transaction is successfully executed, when the second device does not query the second message from the first message queue within a preset time, whether the first message exists in the database can be queried, if the first message is queried in the database, the first message is successfully executed by the first device, and the second device pushes the first message to the second user. If the first message is not queried in the database, the first equipment fails to execute the first transaction, the second equipment does not push the first message to the second user, and further the push condition of the first message is ensured to be consistent with the execution condition of the first transaction.
According to the embodiment of the application, when the first equipment fails to send the first message to the first message queue, the second equipment can inquire the first message from the database and push the inquired first message to the second user, so that the fault tolerance of the message system is improved. In addition, when the second device queries the first message in the first message queue but does not query the second message, the second device may obtain an execution result of the first transaction from the first device, and determine whether to push the first message according to the execution result of the first transaction, or the second device queries the first message from the database, and determines whether to push the first message according to the query result of the first message, so as to ensure that the pushing of the first message is consistent with the execution condition of the first transaction.
In some embodiments, as shown in fig. 9, the second device further includes a second message queue in addition to the first message queue, where the pushing, by the second device, the first message to the second user may include:
step A1, the second device sends the first message to the second message queue.
And step A2, pushing the first message in the second message queue to the second user by the second device when the preset condition is met.
Specifically, after the second device obtains the first message from the first message queue, according to the steps of the foregoing embodiment, it is determined that the first message may be pushed to the second user, where the second device does not immediately send the first message to the second user, but stores the first message in the second message queue. And when the preset condition is met, the second device pushes the first message in the second message queue to the second user.
Optionally, the preset condition may be a preset time, for example, when the preset time is reached, the second device pushes the first message in the second message queue to the second user.
Optionally, the preset condition is an arrangement order of the first message in the second message queue, for example, when the second device sequentially reads the first message in the second message queue (where the second message queue further includes other messages), the first message is pushed to the second user.
In some embodiments, the reliability guarantee of the message is improved in two ways:
in a first manner, the first message queue and/or the second message queue in the embodiments of the present application include a first storage area and a second storage area, where the first storage area and the second storage area store first messages respectively, and optionally, the first storage area and the second storage area of the first message queue may also store second messages simultaneously. In this way, when a first message (or a second message) in the first storage area is lost, the first message (or the second message) can be obtained from the second storage area, thereby preventing the first message from being lost from the first message queue and/or the second message queue, and preventing the second message from being lost from the first message queue.
In a second mode, when the second device submits the first message to the second message queue, the second device writes the position offset of the first message in the first message queue into the first message queue. Thus, when one thread of the second device fails to send the first message from the first message queue to the second message queue, the other thread of the second device can send the first message from the first message queue to the second message queue again according to the position offset of the first message marked in the first message queue, so that the sending reliability of the first message is ensured.
And/or the second device writes the position offset of the first message in the second message queue into the second message queue when the first message is sent to the second user. Thus, when one thread of the second device fails to send the first message from the second message queue to the second user, the other thread of the second device can send the first message from the second message queue to the second user again according to the position offset of the first message marked in the second message queue, so that the sending reliability of the first message is ensured.
In some embodiments, the first message queue and the second message queue each include a plurality of tiles, messages on a same tile are ordered in a sequence, and the order of processing the messages on a same tile is consistent with the order of ordering. Based on this, in order to ensure the sequence of the messages, the first device sends the first message to the first message queue of the second device in S301, including:
and B1, the first equipment obtains the identification information of the target fragment where the other messages are located according to the sending sequence relation between the first message and the other messages.
The target area is an area of the first message queue, and the processing sequence and the arrangement sequence of the messages in the target area are consistent. The first device is in communication connection with the second device, and the first device can access a first message queue on the second device to obtain each section of the first message queue, identification information of each section and the like.
And B2, the first equipment stores the first message on the target area according to the identification information of the target area.
Specifically, the first device expects that the sending process between the first message and the other messages guarantees the sequence, for example, expects that the first message is sent before or after the other messages, so that the first device obtains the region where the other messages are located in the first message queue from the second device according to the sending sequence relationship between the first message and the other messages, takes the region as the target region, and further obtains the identification information of the target region. When the first device stores the first message, the first message can be stored on the target area of the first message queue according to the identification information of the target area, so that the first message and other messages are located on the same area, and the arrangement sequence of the first message and other messages on the target area is installed for sending during sending, so that the sequential processing of the messages is realized.
Alternatively, the other message may be a first message sent by the other device to the second device.
On the basis of this embodiment, the sending, by the second device, the first message to the second message queue in the step A1 may include: the second device sends the first message to the corresponding area of the target area in the second message queue according to the mark of the target area, so that the second device is ensured to push the first message to the second user according to the arrangement sequence of the first message in the target area, and the sequential sending of the first message is ensured.
Fig. 10 is a schematic structural diagram of a message pushing device according to an embodiment of the present application. The message pushing device 300 is configured to execute the technical scheme corresponding to the first device in the foregoing method embodiment. The message pushing device 300 may be understood as the first device described above, or as part of the first device (e.g. a chip). As shown in fig. 10, the message pushing device 300 may include: a transmitting unit 310 and a processing unit 320.
A sending unit 310, configured to send a first message to a first message queue of a second device, where the first device corresponds to a first user, and the first message is used to instruct the second user to perform a preset operation;
A processing unit 320, configured to execute a first transaction, and generate a second message according to an execution result of the first transaction, where the second message is used to indicate whether to push the first message to the second user;
the sending unit 310 is further configured to send the second message to the first message queue.
In some embodiments, the processing unit 320 is specifically configured to carry a first push instruction in the second message when the execution result of the first transaction is successful, where the first push instruction is used to instruct to push the first message to the second user; and when the execution result of the first transaction is failure, carrying a second push instruction in the second message, wherein the second push instruction is used for indicating that the first message is not pushed to the second user.
In some embodiments, the sending unit 310 is further configured to send the first message to a database when the execution result of the first transaction is successful.
In some embodiments, the sending unit 310 is specifically configured to obtain, according to a sending order relationship between the first message and the other messages, identification information of a target tile where the other messages are located, where the target tile is a tile of the first message queue, and a processing order and an arrangement order of the messages in the target tile are consistent; and storing the first message on the target area according to the identification information of the target area.
The message pushing device of the embodiment of the present application may be used to execute the technical scheme corresponding to the first device in the embodiment of the method, and its implementation principle and technical effect are similar, and are not repeated here.
Fig. 11 is a schematic structural diagram of a message pushing device according to an embodiment of the present application. The message pushing device 200 is configured to execute the technical scheme corresponding to the second device in the above method embodiment. The message pushing device 200 may be understood as the above-mentioned second device or as part of the second device (e.g. a chip). As shown in fig. 11, the message pushing apparatus 200 may include: a processing unit 210.
A processing unit 210, configured to query a first message from a first message queue in the second device, where the first message is used to instruct the second user to perform a preset operation; inquiring a second message from the first message queue within a preset time, wherein the second message is used for indicating whether to push the first message to the second user;
the processing unit 210 is further configured to determine whether to push the first message to the second user according to the second message.
In some embodiments, the processing unit 210 is specifically configured to determine to push the first message to the second user when the second message carries a first push instruction, where the first push instruction is used to instruct to push the first message to the second user; and when the second message carries a second pushing instruction, determining that the first message is not pushed to the second user, wherein the second pushing instruction is used for indicating that the first message is not pushed to the second user.
In some embodiments, the apparatus further comprises a transmitting unit 220;
the processing unit 210 is further configured to query, when the second message is not queried from the first message queue within the preset time, an execution result of the first transaction from the first device;
a sending unit 220, configured to push the first message to the second user when the execution result of the first transaction is successful; and when the execution result of the first transaction is failure, not pushing the first message to the second user.
In some embodiments, the processing unit 210 is further configured to query the database for the first message when the second message is not queried from the first message queue within the preset time;
the sending unit 220 is further configured to push the first message to the second user when the first message is queried in the database; and when the first message is not queried in the database, not pushing the first message to the second user.
In some embodiments, the processing unit 210 is further configured to query the first message from the database when the first message is not queried in the first message queue;
The sending unit 220 is further configured to push the queried first message to the second user.
In some embodiments, the sending unit 220 is specifically configured to send the first message to the second message queue; and pushing the first message in the second message queue to the second user when the preset condition is met.
In some embodiments, the first message queue and/or the second message queue includes a first storage area and a second storage area, the first storage area and the second storage area having the first message stored therein, respectively.
In some embodiments, the sending unit 220 is further configured to, when submitting the first message to the second message queue, write a position offset of the first message in the first message queue into the first message queue; and/or writing a position offset of the first message in the second message queue into the second message queue when the first message is sent to the second user.
In some embodiments, the first message is stored on a target tile of the first message queue, the target tile is a tile of the first message queue, and a processing order of messages in the target tile is consistent with a ranking order.
In some embodiments, the sending unit 220 is specifically configured to send the first message to a tile corresponding to the identifier of the target tile in the second message queue according to the identifier of the target tile.
The message pushing device of the embodiment of the present application may be used to execute the technical scheme of the second device in the embodiment of the method, and its implementation principle and technical effect are similar, and are not repeated here.
Fig. 12 is a schematic structural diagram of an electronic device according to an embodiment of the present application. The electronic device is configured to execute the message pushing method described in the foregoing embodiment, and specifically refer to the description in the foregoing method embodiment.
The electronic device 400 shown in fig. 12 comprises a memory 401, a processor 402, a communication interface 403. The memory 401, the processor 402, and the communication interface 403 are communicatively connected to each other. For example, the memory 401, the processor 402, and the communication interface 403 may be connected by a network, so as to implement communication connection. Alternatively, the electronic device 400 may also include a bus 404. The memory 401, the processor 402, and the communication interface 403 are communicatively connected to each other via a bus 404. Fig. 12 shows an electronic device 400 in which a memory 401, a processor 402, and a communication interface 403 are connected to each other by a bus 404.
The Memory 401 may be a Read Only Memory (ROM), a static storage device, a dynamic storage device, or a random access Memory (Random Access Memory, RAM). The memory 401 may store a program, and the processor 402 and the communication interface 403 are used to perform the above-described method when the program stored in the memory 401 is executed by the processor 402.
The processor 402 may employ a general purpose central processing unit (Central Processing Unit, CPU), microprocessor, application specific integrated circuit (Application Specific Integrated Circuit, ASIC), graphics processor (graphics processing unit, GPU) or one or more integrated circuits.
The processor 402 may also be an integrated circuit chip with signal processing capabilities. In implementation, the methods of the present application may be performed by integrated logic circuitry in hardware or instructions in software in processor 402. The processor 402 described above may also be a general purpose processor, a digital signal processor (digital signal processing, DSP), an Application Specific Integrated Circuit (ASIC), an off-the-shelf programmable gate array (field programmable gate array, FPGA) or other programmable logic device, discrete gate or transistor logic device, discrete hardware components. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like. The software modules may be located in a random access memory, flash memory, read only memory, programmable read only memory, or electrically erasable programmable memory, registers, etc. as well known in the art. The storage medium is located in the memory 401, and the processor 402 reads the information in the memory 401, and combines with the hardware to implement the method of the embodiment of the present application.
Communication interface 403 enables communication between electronic device 400 and other devices or communication networks using a transceiver module such as, but not limited to, a transceiver.
When the electronic device 400 includes a bus 404, the bus 404 may include a path that communicates information between the various components of the electronic device 400 (e.g., memory 401, processor 402, communication interface 403).
In the above embodiments, it may be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented in software, may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When loaded and executed on a computer, produces a flow or function in accordance with embodiments of the present application, in whole or in part. The computer may be a general purpose computer, a special purpose computer, a computer network, or other programmable apparatus. The computer instructions may be stored in or transmitted from one computer-readable storage medium to another, for example, by wired (e.g., coaxial cable, optical fiber, digital Subscriber Line (DSL)), or wireless (e.g., infrared, wireless, microwave, etc.). The computer readable storage medium may be any available medium that can be accessed by a computer or a data storage device such as a server, data center, etc. that contains an integration of one or more available media. The usable medium may be a magnetic medium (e.g., floppy Disk, hard Disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid State Disk (SSD)), etc.
It will be clear to those skilled in the art that, for convenience and brevity of description, specific working procedures of the above-described systems, apparatuses and units may refer to corresponding procedures in the foregoing method embodiments, and are not repeated herein. In addition, the method embodiments and the apparatus embodiments may be referred to each other, and the same or corresponding content in different embodiments may be referred to each other, which is not described in detail.