CN109408251B - Message sending method and device and message receiving processing method and device - Google Patents

Message sending method and device and message receiving processing method and device Download PDF

Info

Publication number
CN109408251B
CN109408251B CN201811141018.8A CN201811141018A CN109408251B CN 109408251 B CN109408251 B CN 109408251B CN 201811141018 A CN201811141018 A CN 201811141018A CN 109408251 B CN109408251 B CN 109408251B
Authority
CN
China
Prior art keywords
message
asynchronous
sent
task
callback function
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201811141018.8A
Other languages
Chinese (zh)
Other versions
CN109408251A (en
Inventor
周惠坤
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Dragon Punch Storm Technology Co ltd
Original Assignee
Beijing Dragon Punch Storm Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Dragon Punch Storm Technology Co ltd filed Critical Beijing Dragon Punch Storm Technology Co ltd
Priority to CN201811141018.8A priority Critical patent/CN109408251B/en
Publication of CN109408251A publication Critical patent/CN109408251A/en
Application granted granted Critical
Publication of CN109408251B publication Critical patent/CN109408251B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/546Message passing systems or structures, e.g. queues
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/547Remote procedure calls [RPC]; Web services

Abstract

The embodiment of the invention discloses a message sending method and device and a message receiving processing method and device, which can solve the problem that a large amount of processing needs to be carried out in business in the prior art. The message sending method comprises the following steps: if the type of the message to be sent is judged to be asynchronous automatic callback, registering an asynchronous task for the message to be sent, registering an asynchronous callback function for the asynchronous task, recording the asynchronous callback function and the message to be sent in the asynchronous task, and setting the type of the message to be sent as a waiting return type; creating a sub-thread, executing the asynchronous task by using the sub-thread, blocking the sub-thread to wait for a return message of a receiver of the message to be sent after the asynchronous task is successfully executed, calling the asynchronous callback function by using the return message if the return message is received within a preset first time period, and closing the sub-thread after the asynchronous callback function is executed.

Description

Message sending method and device and message receiving processing method and device
Technical Field
The embodiment of the invention relates to the field of computers, in particular to a message sending method and device and a message receiving and processing method and device.
Background
The traditional inter-server communication has multiple modes, including Remote Procedure Call Protocol (RPC) communication and hypertext transfer Protocol (Http) request, where the RPC communication and Http request are both synchronous waiting in the communication of the game server, and a large amount of processing is required in the service for asynchronous scenes.
In view of this, how to design a communication mechanism suitable for game services to avoid the occurrence of a large amount of processing problems in the services in an asynchronous scenario becomes a technical problem to be solved urgently.
Disclosure of Invention
Aiming at the defects and shortcomings of the prior art, the embodiment of the invention provides a message sending method and device, and a message receiving and processing method and device.
In one aspect, an embodiment of the present invention provides a message sending method, including:
if the type of the message to be sent is judged to be asynchronous automatic callback, an asynchronous task is registered for the message to be sent, an asynchronous callback function is registered for the asynchronous task, the asynchronous callback function and the message to be sent are recorded in the asynchronous task, and the type of the message to be sent is set to be a waiting return type, wherein the asynchronous task is used for sending the message to be sent;
creating a sub-thread, executing the asynchronous task by using the sub-thread, blocking the sub-thread to wait for a return message of a receiver of the message to be sent after the asynchronous task is successfully executed, calling the asynchronous callback function by using the return message if the return message is received within a preset first time period, and closing the sub-thread after the asynchronous callback function is executed.
On the other hand, an embodiment of the present invention provides a message sending method, including:
receiving a message sent by a sender, and executing a corresponding service according to the message if judging that the type of the message is a waiting return type, wherein the message comprises the type;
and encapsulating the execution result of the service into a response message and sending the response message to the sender.
In a third aspect, an embodiment of the present invention provides a message sending apparatus, including:
a recording unit, configured to register an asynchronous task for the message to be sent, register an asynchronous callback function for the asynchronous task, record the asynchronous callback function and the message to be sent in the asynchronous task, and set the type of the message to be sent as a waiting-to-return type, where the asynchronous task is used to send the message to be sent;
the creating unit is used for creating a sub-thread, executing the asynchronous task by using the sub-thread, blocking a return message of a receiver waiting for the message to be sent by the sub-thread after the asynchronous task is successfully executed, calling the asynchronous callback function by using the return message if the return message is received within a preset first time period, and closing the sub-thread after the asynchronous callback function is completely executed.
In a fourth aspect, an embodiment of the present invention provides a message reception processing apparatus, including:
the execution unit is used for receiving a message sent by a sender, and executing a corresponding service according to the message if the type of the message is judged to be a waiting return type, wherein the message comprises the type;
and the sending unit is used for encapsulating the execution result of the service into a response message and sending the response message to the sender.
In a fifth aspect, an embodiment of the present invention provides an electronic device, including: a processor, a memory, a bus, and a computer program stored on the memory and executable on the processor;
the processor and the memory complete mutual communication through the bus;
the processor, when executing the computer program, implements the method described above.
In a sixth aspect, an embodiment of the present invention provides a non-transitory computer-readable storage medium, on which a computer program is stored, and the computer program, when executed by a processor, implements the above method.
In the message sending method and apparatus and the message receiving and processing method and apparatus provided by the embodiments of the present invention, if the sender determines that the type of the message to be sent is asynchronous automatic callback, an asynchronous task is registered for the message to be sent, an asynchronous callback function is registered for the asynchronous task, the asynchronous callback function and the message to be sent are recorded in the asynchronous task, the type of the message to be sent is set as a waiting-to-return type, a sub-thread is then created, the sub-thread is used to execute the asynchronous task, that is, the message to be sent is sent to the receiver, after the asynchronous task is successfully executed, the sub-thread blocks a return message of the receiver waiting for the message to be sent, and at the same time, the receiver receives the message sent by the sender, if the type of the message is determined as the waiting-to-return type, executing the corresponding service according to the message, and packaging the execution result of the service into a response message to be fed back to the sender. And then if the sub-thread receives the return message within a preset first time period, calling the asynchronous callback function by using the return message, and closing the sub-thread after the asynchronous callback function is executed.
Drawings
Fig. 1 is a flowchart illustrating an embodiment of a message sending method according to the present invention;
fig. 2 is a flowchart illustrating a message sending method according to another embodiment of the present invention;
FIG. 3 is a flowchart illustrating a message receiving and processing method according to an embodiment of the present invention;
FIG. 4 is a schematic structural diagram of a message sending apparatus according to an embodiment of the present invention;
FIG. 5 is a schematic structural diagram of a message receiving and processing device according to an embodiment of the present invention;
fig. 6 is a schematic physical structure diagram of an electronic device according to an embodiment of the present invention;
fig. 7 is a schematic physical structure diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some embodiments, but not all embodiments, of the present invention. All other embodiments obtained by a person of ordinary skill in the art based on the embodiments of the present invention without any creative effort belong to the protection scope of the embodiments of the present invention.
Referring to fig. 1, the present embodiment discloses a message sending method, including:
s10, if judging that the type of the message to be sent is asynchronous automatic callback, registering an asynchronous task for the message to be sent, registering an asynchronous callback function for the asynchronous task, recording the asynchronous callback function and the message to be sent in the asynchronous task, and setting the type of the message to be sent as a waiting return type, wherein the asynchronous task is used for sending the message to be sent;
in this embodiment, the asynchronous task may be registered in Akka (a toolkit in java language for scheduling execution of tasks and threads).
S11, creating a sub-thread, executing the asynchronous task by using the sub-thread, after the asynchronous task is successfully executed, the sub-thread blocks and waits for a return message of a receiver of the message to be sent, if the return message is received within a preset first time period, the sub-thread calls the asynchronous callback function by using the return message, and after the asynchronous callback function is executed, the sub-thread is closed.
In this embodiment, a child thread may be specifically created in Akka when creating the child thread, and the child thread executing the asynchronous task may specifically be to deliver the message to be sent to a queue designated by rmq (RabbitMQ, which is abbreviated as RabbitMQ, an intermediate component for message communication).
Fig. 2 is a flowchart of another embodiment of the message sending method according to the present invention, and referring to fig. 2, registering an asynchronous callback function for the asynchronous task, recording the asynchronous callback function and the message to be sent in the asynchronous task, and setting the type of the message to be sent as a waiting-to-return type may include:
registering an asynchronous callback function for the asynchronous task, recording the current context environment at the same time, and recording the asynchronous callback function, the current context environment and the message to be sent in the asynchronous task;
setting the type of the message to be sent as a waiting return type, generating a message identifier for the message to be sent (specifically, a Universal Unique Identifier (UUID) can be used to generate the message identifier), setting the identifier of the message to be sent as the message identifier, setting a sending source attribute of the message to be sent, and recording a corresponding relation between the message identifier and the asynchronous task in a memory, wherein the sending source attribute is used for identifying a sending party of the message to be sent;
the invoking, by the child thread, the asynchronous callback function by using the return message may include:
the sub thread searches the asynchronous task corresponding to the message identification by using the message identification in the return message;
and the child thread calls an asynchronous callback function in the asynchronous task by using the return message and the current context environment in the asynchronous task, wherein the return message and the current context environment in the asynchronous task are input parameters of the asynchronous callback function.
In addition, it should be noted that if the asynchronous task fails to execute, i.e. the message transmission fails or times out, whether to perform message retransmission can be determined according to the configuration. For example, the determination may be performed once per second, and if it is found that there is a message in the memory that has not received a return signal for more than a certain period of time, the retransmission is performed, the number of times of retransmission of the message is increased by one during retransmission, and when the number of times of retransmission reaches the set maximum number of times of retransmission, the message is deleted from the memory, and a failure log is recorded in the log. The existing RPC communication and Http request have no unified mode for processing various abnormal conditions, message failure retransmission also needs to be realized in service independently, and the embodiment realizes the bottom layer unified processing under various situations of message transmission failure through a message retransmission mechanism, so that the service layer does not need to consider the failure condition on bottom layer communication.
Of course, besides the message retransmission mechanism, a reply deletion mechanism may also be set, that is, the stored message to be sent corresponding to the return message is deleted after the return message is received.
In addition, if the return message is not received within a preset first time period, the sub-thread generates a first timeout exception, obtains an asynchronous task registered for the message to be sent by searching the message to be sent without receiving the return message, and then calls an asynchronous callback function in the asynchronous task by using the first timeout exception and the current context environment in the asynchronous task.
In the message sending method provided by the embodiment of the present invention, if the sender determines that the type of the message to be sent is asynchronous automatic callback, an asynchronous task is registered for the message to be sent, an asynchronous callback function is registered for the asynchronous task, the asynchronous callback function and the message to be sent are recorded in the asynchronous task, the type of the message to be sent is set as a waiting return type, a sub-thread is then created, the sub-thread is used to execute the asynchronous task, that is, the message to be sent is sent to the receiver, after the asynchronous task is successfully executed, the sub-thread blocks a return message of the receiver waiting for the message to be sent, then if the sub-thread receives the return message within a preset first time period, the asynchronous function is called by using the return message, and the callback is closed after the asynchronous callback function is executed, the whole scheme realizes the message sending process under the asynchronous automatic callback scene at the bottom layer, thereby solving the problem that the prior art needs to carry out a large amount of processing in the game service.
Referring to fig. 2, on the basis of the foregoing method embodiment, the method may further include:
if the type of the message to be sent is judged to be synchronous waiting, registering a synchronous task for the message to be sent (the synchronous task can be specifically registered in Akka when being registered), registering a synchronous callback function for the synchronous task, recording the synchronous callback function and the message to be sent in the synchronous task, and setting the type of the message to be sent as a waiting return type, wherein the synchronous task is used for sending the message to be sent;
executing the synchronization task (specifically, the message to be sent is delivered to a queue designated by rmq), after the synchronization task is successfully executed, blocking a return message of a receiver waiting for the message to be sent, if the return message is received within a preset second time period, calling the synchronization callback function by using the return message, and executing the subsequent logic after the synchronization callback function is executed.
In this embodiment, registering a synchronization callback function for the synchronization task, recording the synchronization callback function and the message to be sent in the synchronization task, and setting the type of the message to be sent as a waiting-to-return type may include:
registering a synchronization callback function for the synchronization task, recording a current context environment at the same time, and recording the synchronization callback function, the current context environment and the message to be sent in the synchronization task;
setting the type of the message to be sent as a waiting return type, generating a message identifier for the message to be sent (specifically, a UUID can be used to generate the message identifier), setting the identifier of the message to be sent as the message identifier, setting a sending source attribute of the message to be sent, and recording a corresponding relationship between the message identifier and the synchronization task, wherein the sending source attribute is used for identifying a sending party of the message to be sent;
wherein said invoking said synchronization callback function with said return message comprises:
searching a synchronous task corresponding to the message identifier by using the message identifier in the returned message;
and calling a synchronization callback function in the synchronization task by using the return message and the current context environment in the synchronization task, wherein the return message and the current context environment in the synchronization task are input parameters of the synchronization callback function.
In the embodiment, the sending process for the synchronous waiting type message can meet the application requirement of the scene needing the synchronous callback mode.
Similarly, if the asynchronous task fails to execute, i.e. the message fails to be sent or times out, whether to retransmit the message can be determined according to the configuration.
In addition, it should be noted that if the return message is not received within a preset second time period, a second timeout exception is generated, and the main thread executes a corresponding logic according to the second timeout exception.
Referring to fig. 2, on the basis of the foregoing method embodiment, the method may further include:
if the type of the message to be sent is judged to be asynchronous callback-free, setting the type of the message to be sent to be a common callback-free type;
and sending the message to be sent to a receiver.
In this embodiment, sending the message to be sent to the receiving party may specifically be to send the message to be sent to a queue designated by rmq. Before the sending the message to be sent to the receiver, the method may further include:
generating a message identifier for the message to be sent (specifically, a UUID may be used to generate the message identifier), setting the identifier of the message to be sent as the message identifier, and setting a sending source attribute of the message to be sent, where the sending source attribute is used to identify a sending party of the message to be sent.
In this embodiment, the sending process for the asynchronous callback-free type message can meet the application requirement of a scene requiring an asynchronous callback-free mode.
Referring to fig. 3, the present embodiment discloses a message receiving and processing method, including:
s20, receiving a message sent by a sender, and if judging that the type of the message is a waiting return type, executing a corresponding service according to the message, wherein the message comprises the type;
in this embodiment, after receiving a message sent by a sender, the message needs to be parsed first to obtain information of the message, such as information of a type, a source, a message identifier, and a message content. After the message is analyzed, in order to record the transmission paths of all messages so that the problem can be quickly found and solved if a business problem occurs in the later period, a log may be recorded, for example, a log containing information of a source, a message identifier, a receiver, and the like may be recorded in the open source software ELK. And if the analyzed type is a waiting return type, executing corresponding service according to the message content.
S21, encapsulating the service execution result into a response message and sending the response message to the sender.
And after the corresponding service is executed, encapsulating the execution result of the service into a response type message and delivering the response type message to the message queue corresponding to the sending source attribute, wherein the identifier of the response message is the identifier of the message.
In the message receiving and processing method provided by the embodiment of the invention, the receiver receives the message sent by the sender, if the type of the message is judged to be the waiting return type, the corresponding service is executed according to the message, and the execution result of the service is packaged into the response message and is fed back to the sender.
On the basis of the foregoing method embodiment, the method may further include:
and if the type of the message is judged to be the common non-return type, executing the corresponding service according to the message.
On the basis of the foregoing method embodiment, the method may further include:
if the type of the message is judged and known to be a response type, and the task registered for the message is found, acquiring the context environment of the task and a callback function registered for the task;
and calling the callback function registered for the task by using the message and the context environment of the task, wherein the message and the context environment of the task are input parameters of the callback function.
In this embodiment, when searching for the task registered for the message, the corresponding relationship between the recorded message identifier and the task is searched for according to the message identifier of the message, so as to obtain the task corresponding to the message, where the task is the task registered for the message.
In addition, it should be noted that if the task registered for the message is not found, a log is recorded and the message is discarded.
Referring to fig. 4, the present embodiment discloses a message transmitting apparatus, including:
a recording unit 10, configured to register an asynchronous task for the message to be sent if it is determined that the type of the message to be sent is asynchronous automatic callback, register an asynchronous callback function for the asynchronous task, record the asynchronous callback function and the message to be sent in the asynchronous task, and set the type of the message to be sent as a waiting-to-return type, where the asynchronous task is used to send the message to be sent;
the creating unit 11 is configured to create a sub-thread, execute the asynchronous task by using the sub-thread, block, after the asynchronous task is successfully executed, a return message of a receiver of the message to be sent, if the return message is received within a preset first time period, the sub-thread calls the asynchronous callback function by using the return message, and close the sub-thread after the asynchronous callback function is executed.
Specifically, if it is determined that the type of the message to be sent is asynchronous automatic callback, the recording unit 10 registers an asynchronous task for the message to be sent, registers an asynchronous callback function for the asynchronous task, records the asynchronous callback function and the message to be sent in the asynchronous task, and sets the type of the message to be sent as a waiting-to-return type, where the asynchronous task is used to send the message to be sent; the creating unit 11 creates a sub-thread, executes the asynchronous task by using the sub-thread, after the asynchronous task is successfully executed, the sub-thread blocks a return message of a receiver waiting for the message to be sent, if the return message is received within a preset first time period, the sub-thread calls the asynchronous callback function by using the return message, and closes the sub-thread after the asynchronous callback function is executed.
In the message sending apparatus provided in the embodiment of the present invention, if the sender determines that the type of the message to be sent is asynchronous automatic callback, an asynchronous task is registered for the message to be sent, an asynchronous callback function is registered for the asynchronous task, the asynchronous callback function and the message to be sent are recorded in the asynchronous task, the type of the message to be sent is set as a waiting return type, a sub-thread is then created, the sub-thread is used to execute the asynchronous task, that is, the message to be sent is sent to the receiver, the sub-thread blocks a return message of the receiver waiting for the message to be sent after the asynchronous task is successfully executed, then if the sub-thread receives the return message within a preset first time period, the asynchronous callback function is called by using the return message, and the sub-thread is closed after the asynchronous callback function is executed, the whole scheme realizes the message sending process under the asynchronous automatic callback scene at the bottom layer, thereby solving the problem that the prior art needs to carry out a large amount of processing in the game service.
The message sending apparatus of this embodiment may be configured to execute the technical solution of the foregoing message sending method embodiment, and the implementation principle and the technical effect are similar, which are not described herein again.
Referring to fig. 5, the present embodiment discloses a message receiving and processing apparatus, including:
an execution unit 20, configured to receive a message sent by a sender, and if it is determined that the type of the message is a waiting return type, execute a corresponding service according to the message, where the message includes the type;
a sending unit 21, configured to encapsulate the execution result of the service into a response message, and send the response message to the sender.
Specifically, the execution unit 20 receives a message sent by a sender, and if it is determined that the type of the message is a waiting return type, executes a corresponding service according to the message, where the message includes the type; the sending unit 21 encapsulates the execution result of the service into a response message and sends the response message to the sender.
In the message receiving and processing device provided by the embodiment of the invention, the receiver receives the message sent by the sender, if the type of the message is judged to be the waiting return type, the corresponding service is executed according to the message, and the execution result of the service is packaged into the response message and is fed back to the sender.
The message receiving and processing apparatus of this embodiment may be configured to execute the technical solution of the foregoing message receiving and processing method embodiment, and the implementation principle and the technical effect are similar, which are not described herein again.
Fig. 6 is a schematic entity structure diagram of an electronic device according to an embodiment of the present invention, and as shown in fig. 6, the electronic device may include: a processor 110, a memory 120, a bus 130, and computer programs stored on the memory 120 and operable on the processor 110;
wherein, the processor 110 and the memory 120 complete the communication with each other through the bus 130;
the processor 110, when executing the computer program, implements the method provided by the above method embodiments, for example, including: if the type of the message to be sent is judged to be asynchronous automatic callback, an asynchronous task is registered for the message to be sent, an asynchronous callback function is registered for the asynchronous task, and the asynchronous callback function and the message to be sent are recorded in the asynchronous task; creating a sub-thread, executing the asynchronous task by using the sub-thread, blocking the sub-thread to wait for a return message of a receiver of the message to be sent after the asynchronous task is successfully executed, calling the asynchronous callback function by using the return message if the return message is received within a preset first time period, and closing the sub-thread after the asynchronous callback function is executed.
An embodiment of the present invention provides a non-transitory computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the method provided by the foregoing method embodiments, and for example, the method includes: if the type of the message to be sent is judged to be asynchronous automatic callback, an asynchronous task is registered for the message to be sent, an asynchronous callback function is registered for the asynchronous task, and the asynchronous callback function and the message to be sent are recorded in the asynchronous task; creating a sub-thread, executing the asynchronous task by using the sub-thread, blocking the sub-thread to wait for a return message of a receiver of the message to be sent after the asynchronous task is successfully executed, calling the asynchronous callback function by using the return message if the return message is received within a preset first time period, and closing the sub-thread after the asynchronous callback function is executed.
Fig. 7 is a schematic entity structure diagram of an electronic device according to an embodiment of the present invention, and as shown in fig. 7, the electronic device may include: a processor 111, a memory 121, a bus 131, and computer programs stored on the memory 121 and executable on the processor 111;
wherein, the processor 111 and the memory 121 complete the communication with each other through the bus 131;
when the processor 111 executes the computer program, the method provided by the foregoing method embodiments is implemented, for example, including: receiving a message sent by a sender, and executing a corresponding service according to the message if judging that the type of the message is a waiting return type, wherein the message comprises the type; and encapsulating the execution result of the service into a response message and sending the response message to the sender.
An embodiment of the present invention provides a non-transitory computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the method provided by the foregoing method embodiments, and for example, the method includes: receiving a message sent by a sender, and executing a corresponding service according to the message if judging that the type of the message is a waiting return type, wherein the message comprises the type; and encapsulating the execution result of the service into a response message and sending the response message to the sender.
As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the application. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
It is noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element. The terms "upper", "lower", and the like, indicate orientations or positional relationships based on the orientations or positional relationships shown in the drawings, and are only for convenience in describing the present invention and simplifying the description, but do not indicate or imply that the referred devices or elements must have a specific orientation, be constructed and operated in a specific orientation, and thus, should not be construed as limiting the present invention. Unless expressly stated or limited otherwise, the terms "mounted," "connected," and "connected" are intended to be inclusive and mean, for example, that they may be fixedly connected, detachably connected, or integrally connected; can be mechanically or electrically connected; they may be connected directly or indirectly through intervening media, or they may be interconnected between two elements. The specific meanings of the above terms in the present invention can be understood by those skilled in the art according to specific situations.
In the description of the present invention, numerous specific details are set forth. It is understood, however, that embodiments of the invention may be practiced without these specific details. In some instances, well-known methods, structures and techniques have not been shown in detail in order not to obscure an understanding of this description. Similarly, it should be appreciated that in the foregoing description of exemplary embodiments of the invention, various features of the invention are sometimes grouped together in a single embodiment, figure, or description thereof for the purpose of streamlining the disclosure and aiding in the understanding of one or more of the various inventive aspects. However, the disclosed method should not be interpreted as reflecting an intention that: that the invention as claimed requires more features than are expressly recited in each claim. Rather, as the following claims reflect, inventive aspects lie in less than all features of a single foregoing disclosed embodiment. Thus, the claims following the detailed description are hereby expressly incorporated into this detailed description, with each claim standing on its own as a separate embodiment of this invention. It should be noted that the embodiments and features of the embodiments in the present application may be combined with each other without conflict. The present invention is not limited to any single aspect, nor is it limited to any single embodiment, nor is it limited to any combination and/or permutation of these aspects and/or embodiments. Moreover, each aspect and/or embodiment of the present invention may be utilized alone or in combination with one or more other aspects and/or embodiments thereof.
Finally, it should be noted that: the above embodiments are only used to illustrate the technical solution of the present invention, and not to limit the same; while the invention has been described in detail and with reference to the foregoing embodiments, it will be understood by those skilled in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some or all of the technical features may be equivalently replaced; such modifications and substitutions do not depart from the spirit and scope of the present invention, and they should be construed as being included in the following claims and description.

Claims (6)

1. A method for sending a message, comprising:
if the type of the message to be sent is judged and known to be asynchronous automatic callback, an asynchronous task is registered for the message to be sent, an asynchronous callback function is registered for the asynchronous task, a current context environment is recorded at the same time, the asynchronous callback function, the current context environment and the message to be sent are recorded in the asynchronous task, and the type of the message to be sent is set to be a waiting return type, wherein the asynchronous task is used for sending the message to be sent;
creating a sub-thread, executing the asynchronous task by using the sub-thread, after the asynchronous task is successfully executed, the sub-thread blocks and waits for a return message of a receiver of the message to be sent, if the return message is received within a preset first time period, the sub-thread calls the asynchronous callback function by using the return message and a current context environment in the asynchronous task, and closes the sub-thread after the asynchronous callback function is executed, wherein the return message and the current context environment in the asynchronous task are input parameters of the asynchronous callback function.
2. The method of claim 1, further comprising:
if the type of the message to be sent is judged to be synchronous waiting, a synchronous task is registered for the message to be sent, a synchronous callback function is registered for the synchronous task, a current context environment is recorded, the synchronous callback function, the current context environment and the message to be sent are recorded in the synchronous task, and the type of the message to be sent is set to be a waiting returning type, wherein the synchronous task is used for sending the message to be sent;
and executing the synchronization task, blocking a return message of a receiver waiting for the message to be sent after the synchronization task is successfully executed, calling the synchronization callback function by using the return message and the current context environment in the synchronization task if the return message is received in a preset second time period, and executing the logic after the synchronization callback function is executed, wherein the return message and the current context environment in the synchronization task are input parameters of the synchronization callback function.
3. The method of claim 1, further comprising:
if the type of the message to be sent is judged to be asynchronous callback-free, setting the type of the message to be sent to be a common callback-free type;
and sending the message to be sent to a receiver.
4. A message transmission apparatus, comprising:
a recording unit, configured to register an asynchronous task for a message to be sent if it is determined that a type of the message to be sent is asynchronous automatic callback, register an asynchronous callback function for the asynchronous task, record a current context environment at the same time, record the asynchronous callback function, the current context environment, and the message to be sent in the asynchronous task, and set the type of the message to be sent as a waiting-to-return type, where the asynchronous task is used to send the message to be sent;
the creating unit is used for creating a sub-thread, executing the asynchronous task by using the sub-thread, after the asynchronous task is successfully executed, the sub-thread blocks and waits for a return message of a receiver of the message to be sent, if the return message is received within a preset first time period, the sub-thread calls the asynchronous callback function by using the return message and a current context in the asynchronous task, and closes the sub-thread after the asynchronous callback function is executed, wherein the return message and the current context in the asynchronous task are input parameters of the asynchronous callback function.
5. An electronic device, comprising: a processor, a memory, a bus, and a computer program stored on the memory and executable on the processor;
the processor and the memory complete mutual communication through the bus;
the processor, when executing the computer program, implements the method of any of claims 1-3.
6. A non-transitory computer-readable storage medium, characterized in that the storage medium has stored thereon a computer program which, when executed by a processor, implements the method of any one of claims 1-3.
CN201811141018.8A 2018-09-28 2018-09-28 Message sending method and device and message receiving processing method and device Active CN109408251B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811141018.8A CN109408251B (en) 2018-09-28 2018-09-28 Message sending method and device and message receiving processing method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811141018.8A CN109408251B (en) 2018-09-28 2018-09-28 Message sending method and device and message receiving processing method and device

Publications (2)

Publication Number Publication Date
CN109408251A CN109408251A (en) 2019-03-01
CN109408251B true CN109408251B (en) 2020-11-03

Family

ID=65465451

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811141018.8A Active CN109408251B (en) 2018-09-28 2018-09-28 Message sending method and device and message receiving processing method and device

Country Status (1)

Country Link
CN (1) CN109408251B (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110825536B (en) * 2019-10-31 2022-08-12 深圳移航通信技术有限公司 Communication method and device between tasks in embedded real-time operating system
CN111082901B (en) * 2019-11-21 2022-05-13 深圳前海环融联易信息科技服务有限公司 Intelligent message sending method and device, computer equipment and storage medium
CN113452602B (en) * 2021-06-21 2023-03-24 网易(杭州)网络有限公司 Message transmission method and device, electronic equipment and storage medium

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106502773A (en) * 2016-10-09 2017-03-15 武汉斗鱼网络科技有限公司 There is data asynchronous processing method and the module of synchronous callback information function
CN107248978A (en) * 2017-05-27 2017-10-13 武汉票据交易中心有限公司 A kind of message method for processing interception and system
CN107678867A (en) * 2017-09-26 2018-02-09 武汉斗鱼网络科技有限公司 A kind of method and device for carrying out remote procedure call
CN108008995A (en) * 2017-12-04 2018-05-08 山东浪潮通软信息科技有限公司 A kind of wait component realization method and device based on call type
CN108399120A (en) * 2017-02-06 2018-08-14 腾讯科技(深圳)有限公司 asynchronous message monitoring method and device

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106502773A (en) * 2016-10-09 2017-03-15 武汉斗鱼网络科技有限公司 There is data asynchronous processing method and the module of synchronous callback information function
CN108399120A (en) * 2017-02-06 2018-08-14 腾讯科技(深圳)有限公司 asynchronous message monitoring method and device
CN107248978A (en) * 2017-05-27 2017-10-13 武汉票据交易中心有限公司 A kind of message method for processing interception and system
CN107678867A (en) * 2017-09-26 2018-02-09 武汉斗鱼网络科技有限公司 A kind of method and device for carrying out remote procedure call
CN108008995A (en) * 2017-12-04 2018-05-08 山东浪潮通软信息科技有限公司 A kind of wait component realization method and device based on call type

Also Published As

Publication number Publication date
CN109408251A (en) 2019-03-01

Similar Documents

Publication Publication Date Title
US20230319534A1 (en) Cross-resource subscription for m2m service layer
CN107087033B (en) Message pushing method and device, storage medium and computer equipment
CN109408251B (en) Message sending method and device and message receiving processing method and device
KR20190085108A (en) Run code on demand with localized device controller
CN113630372A (en) Cloud edge coordination system for edge computing
CN106657299B (en) Attention anchor online reminding method and system
CN110413425B (en) Third-party message callback method, device, server and storage medium
US9854068B2 (en) System and method for providing a dynamic invocation and service interface for use in a middleware or other environment
CN111245934A (en) Feedback method, device and equipment for file transmission and storage medium
CN111258723B (en) Transaction processing method, device, system, medium and equipment of distributed system
US9456325B2 (en) Transmission of a multimedia message doubled with the transmission of a text message
WO2023093039A1 (en) Inter-process communication method and system
CN107977260B (en) Task submitting method and device
CN114253748B (en) Message processing system and message processing method
CN107172112B (en) Computer file transmission method and device
US8370443B2 (en) Reliable messaging using publish subscribe mechanism
WO2021093671A1 (en) Task processing method, system, apparatus and device, and computer readable storage medium
CN109905459B (en) Data transmission method and device
CN107819855A (en) A kind of message distributing method and device
CN113992740B (en) Middleware based on autonomous control and data transmission method
US8332498B2 (en) Synchronized relay messaging and coordinated network processing using SNMP
CN115174472B (en) Message forwarding processing method and related device
EP3284243A1 (en) Methods, devices and system for obtaining http message statuses
CN110022332B (en) Hypertext transfer security protocol proxy method, device, equipment and medium
CN114816785A (en) Service data processing method and device, electronic equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant