CN109995801B - Message transmission method and device - Google Patents

Message transmission method and device Download PDF

Info

Publication number
CN109995801B
CN109995801B CN201711472720.8A CN201711472720A CN109995801B CN 109995801 B CN109995801 B CN 109995801B CN 201711472720 A CN201711472720 A CN 201711472720A CN 109995801 B CN109995801 B CN 109995801B
Authority
CN
China
Prior art keywords
message
queue
storage
consumption
consumer
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
CN201711472720.8A
Other languages
Chinese (zh)
Other versions
CN109995801A (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 Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information 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 Jingdong Century Trading Co Ltd, Beijing Jingdong Shangke Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN201711472720.8A priority Critical patent/CN109995801B/en
Publication of CN109995801A publication Critical patent/CN109995801A/en
Application granted granted Critical
Publication of CN109995801B publication Critical patent/CN109995801B/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/544Buffers; Shared memory; Pipes
    • 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
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/14Session management
    • H04L67/146Markers for unambiguous identification of a particular session, e.g. session cookie or URL-encoding
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/50Network services
    • H04L67/56Provisioning of proxy services
    • H04L67/568Storing data temporarily at an intermediate stage, e.g. caching

Abstract

The invention discloses a message transmission method and a message transmission device, and relates to the technical field of computers. One embodiment of the method comprises: receiving at least one consumption identification; when the storage queue corresponding to the consumption identification is confirmed to exist, obtaining the message with the same type as the message, and then storing the message into the storage queue; and outputting the message in the storage queue. According to the embodiment, the consumption identification is sent to the message queue, the message queue stores the message into the storage queue constructed according to the consumption identification, and the message is transmitted with the consumer through the storage queue, so that the technical problem that the message mode needs to be predetermined in the prior art is solved, and the use flexibility of the user is improved.

Description

Message transmission method and device
Technical Field
The present invention relates to the field of computers, and in particular, to a method and an apparatus for transmitting a message.
Background
Java Message Service (JMS) is a technical specification of Message-oriented middleware (Message-oriented middleware) in Java EE (Java Platform Enterprise Edition), and the middleware is a Message queue. JMS is used to send and receive messages between two applications, or in a distributed system, to achieve asynchronous message communication.
Currently JMS supports two message modes, one is a point-to-point mode and the other is a publish-subscribe mode. The implementation process of the point-to-point mode is as follows: a user creates a Queue (Queue) in a message Queue; a Producer (Producer) connects to a Queue of a message Queue and then sends a message to the Queue; the Consumer (Consumer) connects to the Queue of the message Queue and then receives the message from the Queue. The implementation process of the publish-subscribe mode is as follows: the user creates a Topic (Topic) in the message queue; the Producer (Producer) connects to the Topic of the message queue and then sends the message to the Topic; the Consumer (Consumer) connects to the Topic of the message queue and then receives the message from the Topic. In the point-to-point mode, messages produced by any one producer will only be consumed by one of several consumers; whereas in the publish-subscribe model, messages produced by any one producer are consumed by all consumers.
In the prior art, when a message is transmitted, a user needs to determine a message mode in advance, and then creates a Queue (point-to-point mode) or a Topic (publish-subscribe mode) in a message Queue according to the message mode; and then the producer, the message queue and the consumer transmit the messages according to the implementation process.
In the process of implementing the invention, the inventor finds that at least the following problems exist in the prior art:
(1) In the prior art, a message mode must be predetermined by a user to transmit a message, and the user may not be able to determine the message mode in actual use;
(2) In the prior art, a message queue cannot dynamically change a message mode in the using process, for example, a message mode cannot be changed from a point-to-point mode to a publish-subscribe mode.
Disclosure of Invention
In view of this, embodiments of the present invention provide a method and an apparatus for transmitting a message, where a consumer sends a consumption identifier to a message queue, the message queue stores a message in a storage queue constructed according to the consumption identifier, and the message is transmitted to the consumer through the storage queue. The technical problem that the message mode must be predetermined in the prior art is solved, and the use flexibility of the user is improved.
To achieve the above object, according to an aspect of an embodiment of the present invention, a message transmission method is provided.
The message transmission method of the embodiment of the invention comprises the following steps: receiving at least one consumption identification; wherein the consumption identification comprises a message type; when the storage queue corresponding to the consumption identification is confirmed to exist, obtaining the message with the same type as the message, and then storing the message into the storage queue; and outputting the message in the storage queue.
Optionally, the consumption identification is a plurality; when the storage queue corresponding to the consumption identifier exists is confirmed, obtaining the message with the same type as the message, and then storing the message into the storage queue, wherein the steps of: when confirming that the consumption identifications are the same and a storage queue corresponding to the consumption identification exists, obtaining a message with the same type as the message from a storage, and then storing the message into the storage queue; and when the consumption identifications are confirmed to be different and storage queues corresponding to the consumption identifications exist, respectively acquiring messages with the same type as the messages from a memory, and then respectively storing the messages into the storage queues.
Optionally, when the consumption identifications are the same, the outputting the message in the storage queue includes: randomly outputting the message to one of the consumers corresponding to the store queue; when the consumption identifications are different, the outputting the message in the storage queue comprises: and respectively outputting the messages in the storage queues to the consumers corresponding to the storage queues.
Optionally, after the step of outputting the message in the storage queue, the method further includes: and destroying the storage queue corresponding to the consumption identification when confirming that the storage queue is not connected with the consumer.
To achieve the above object, according to an aspect of an embodiment of the present invention, there is provided a message transmission apparatus.
An information transmission apparatus according to an embodiment of the present invention includes: a receiving module for receiving at least one consumption identifier; wherein the consumption identification comprises a message type; the storage module is used for acquiring the message with the same type as the message when confirming that the storage queue corresponding to the consumption identifier exists, and then storing the message into the storage queue; and the output module is used for outputting the messages in the storage queue.
Optionally, the consumption identification is a plurality; the storage module is further configured to: when confirming that the consumption identifications are the same and a storage queue corresponding to the consumption identification exists, obtaining a message with the same type as the message from a storage, and then storing the message into the storage queue; and when confirming that the consumption identifications are different and storage queues corresponding to the consumption identifications exist, respectively acquiring messages with the same types as the messages from a storage, and then respectively storing the messages into the storage queues.
Optionally, the output module is further configured to: randomly outputting the message to one of the consumers corresponding to the store queue; and respectively outputting the messages in each storage queue to the consumers corresponding to each storage queue.
Optionally, the apparatus further comprises: and the destroying module is used for destroying the storage queue corresponding to the consumption identification when the storage queue is not connected with the consumer.
To achieve the above object, according to still another aspect of embodiments of the present invention, there is provided an electronic apparatus.
An electronic device of an embodiment of the present invention includes: one or more processors; a storage device, configured to store one or more programs, which when executed by the one or more processors, cause the one or more processors to implement a message transmission method according to an embodiment of the present invention.
To achieve the above object, according to still another aspect of embodiments of the present invention, there is provided a computer-readable medium.
A computer-readable medium of an embodiment of the present invention has stored thereon a computer program that, when executed by a processor, implements a message transmission method of an embodiment of the present invention.
One embodiment of the above invention has the following advantages or benefits: the consumer sends the consumption identification to the message queue and stores the message into the storage queue constructed according to the consumption identification, so that the message transmission of a producer, the message queue and the consumer is realized, the message mode does not need to be determined in advance, and the use flexibility of a user is improved; storing the messages into the storage queues corresponding to the consumption identifications by confirming the difference of the consumption identifications, and then outputting the messages of the storage queues to the consumers, thereby realizing the dynamic change of the message mode of the message queues in the using process; if the consumer needs to change the consumption identifier, the consumer can disconnect the message queue, then reestablish the connection with the message queue and send a new consumption identifier to the message queue, and the operation increases the robustness and reliability of the message queue in actual engineering practice.
Further effects of the above-mentioned non-conventional alternatives will be described below in connection with the embodiments.
Drawings
The drawings are included to provide a better understanding of the invention and are not to be construed as unduly limiting the invention. Wherein:
FIG. 1 is a diagram of a prior art message transmission in a point-to-point mode;
FIG. 2 is a diagram of message transmission in a publish-subscribe model according to the prior art;
fig. 3 is a schematic diagram of the main steps of a message transmission method according to an embodiment of the invention;
fig. 4 is a schematic main flow chart of a message transmission method according to an embodiment of the present invention;
fig. 5 is an information interaction diagram of a message transmission method according to an embodiment of the present invention;
fig. 6 is a schematic diagram of a point-to-point mode of a message transmission method according to an embodiment of the present invention;
FIG. 7 is a schematic diagram of an implementation of a publish-subscribe schema of a message transmission method according to an embodiment of the present invention;
fig. 8 is a schematic diagram of information interaction of a message transmission method changed from a point-to-point mode to a publish-subscribe mode according to an embodiment of the present invention;
fig. 9 is a schematic diagram of information interaction of a message transmission method according to an embodiment of the present invention, which changes from a publish-subscribe mode to a peer-to-peer mode;
fig. 10 is a schematic diagram of the main blocks of a message transmitting apparatus according to an embodiment of the present invention;
FIG. 11 is an exemplary system architecture diagram in which embodiments of the present invention may be employed;
FIG. 12 is a schematic diagram of a computer apparatus suitable for use in an electronic device to implement an embodiment of the invention.
Detailed Description
Exemplary embodiments of the invention are described below with reference to the accompanying drawings, in which various details of embodiments of the invention are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
Terms related to the embodiments of the present invention are explained below.
The producer: a message is created and sent to the application of the message queue.
The consumer: an application that receives the message.
Message: data that is passed between the producer and the consumer.
Message queue: refers to an application program that stores messages during their transmission, and a message Queue may include multiple Queue and topoc.
And (3) queue: queue, a container that buffers messages waiting to be consumed, supports the sending of a message to one of multiple consumers.
Subject matter: topic, a container that buffers messages waiting to be consumed, supports the delivery of a message to multiple consumers.
Fig. 1 is a diagram illustrating a message transmission in a point-to-point mode in the prior art. As shown in fig. 1, the number of producers is 3 (Producer _1, producer _2, and Producer _ 3), the number of consumers is two (Consumer _1 and Consumer _ 2), and a Queue is created in advance in the message Queue. The Producer _1, the Producer _2 and the Producer _3 respectively produce a message 1, a message 2 and a message 3, each Producer respectively establishes connection with the Queue, and then respectively sends the respectively produced messages to the Queue; each Consumer establishes a connection with Queue, and then Consumer _1 takes message 2 from Queue and consumes the message, and Consumer _2 takes message 1 and message 3 from Queue and consumes the two messages. In this message mode, message 1 is consumed only by Consumer _2, message 2 is consumed only by Consumer _1, and message 3 is consumed only by Consumer _2.
Fig. 2 is a diagram illustrating a message transmission in a publish-subscribe mode in the prior art. As shown in fig. 2, the number of producers is 3 (Producer _1, producer _2, and Producer _ 3), the number of consumers is two (Consumer _1 and Consumer _ 2), and one Topic is created in advance in the message queue. The Producer _1, the Producer _2 and the Producer _3 respectively produce a message 1, a message 2 and a message 3, each Producer respectively establishes connection with the Topic, and then respectively sends the respectively produced messages to the Topic; each Consumer establishes a connection with Topic, and then the 3 messages are each sent by Topic to Consumer _1 and Consumer _2, respectively. The message mode is such that message 1 is consumed by both Consumer _1 and Consumer _2, message 2 is consumed by both Consumer _1 and Consumer _2, and message 3 is consumed by both Consumer _1 and Consumer _2.
Fig. 3 is a schematic diagram of the main steps of a message transmission method according to an embodiment of the present invention. As shown in fig. 3, the message transmission method according to the embodiment of the present invention mainly includes the following steps:
step S301: at least one consumption identification is received. The consumer connects to the message queue and then sends a consumption identification to the message queue. The consumption identification is generated by a consumer and comprises a message type and an identification, and the specific structure can be message-collection _1# -ID _1, message-collection _1# -ID _2, message-collection _1# -ID _3and the like; wherein, the message-collection _1 is the message type that the consumer wants to obtain the message, and the ID _1 is the identification. After the message queue receives the consumption identifier, the logging output operation of step S302 and step S303 is performed.
Step S302: and when the storage queue corresponding to the consumption identification is confirmed to exist, obtaining the message with the same type as the message, and then storing the message into the storage queue. The producer produces a message and sends the message to the message queue. After receiving the consumption identification, the message queue checks whether a storage queue corresponding to the consumption identification exists at present, and if so, the message which is sent by the producer and has the same type as the message is stored in the storage queue; if the message type does not exist, a storage queue corresponding to the consumption identification is created, and then the message which is sent by the producer and has the same type as the message is stored in the storage queue. Wherein the store queue is used to temporarily store messages to be sent to a consumer.
Step S303: and outputting the message in the storage queue. And the message queue outputs the messages in the storage queue corresponding to the consumption identification to the consumer. According to the technical scheme of the embodiment of the invention, the message transmission is carried out through the storage queue corresponding to the consumption identifier, and the message mode does not need to be determined in advance before the message transmission is carried out.
Fig. 4 is a schematic main flow chart of a message transmission method according to an embodiment of the present invention. As shown in fig. 4, in the message transmission method according to the embodiment of the present invention, a message-collection Queue (message-collection) for caching messages needs to be created by a user on a console of a message Queue, where the message-collection Queue may implement a Queue function in the prior art or a Topic function, and the message-collection Queue may include multiple storage queues. The method mainly comprises the following steps:
step S401: the producer connects to the message queue and then sends the produced message to the message queue. Each message produced by the producer is accompanied by a message type that corresponds to the name of the message queue's message collection queue created at the console. The message types may be, for example: message-collection _1, message-collection _2. In the embodiment, the producer and the message queue are connected based on a long TCP (Transmission Control Protocol) connection. In a preferred embodiment, the Producer sends a message of message-collection _1 to the message queue for Producer _1, producer _1.
Step S402: the message queue persists the message to memory (such as disk). The message queue stores the received messages into each message set of the memory according to the message types. For example, if the message type is message-collection _1, the message type is placed in a message set named message-collection _1 in the memory; the message type is message-collection _2, and then the message type is put in a message set named message-collection _2 in the memory. In addition, if the number of the messages is small, the step can be skipped, and the messages are directly stored into a storage queue corresponding to the consumption identification; however, if the number of messages is too large, the consumption speed of the consumer is slow, the storage queue is full, when new messages come, the messages cannot be stored any more, and the messages can only be discarded. Therefore, the message queue in the actual engineering application stores all the received messages in the disk.
Step S403: the consumer connects to the message queue and then sends a consumption identification to the message queue. In embodiments, the connection between the consumer and the message queue is based on a long TCP connection. In one embodiment, the Consumer is Consumer _1, the consumption identifier is message-collection _1# -ID _1, consumer _1sends message-collection _1# -ID _1to the message queue.
Step S404: after receiving the consumption identifier, the message queue determines whether a storage queue corresponding to the consumption identifier exists, and if not, step S405 is executed; if so, step S406 is performed. In a preferred embodiment, it is determined whether a storage queue with a name of message-collection _1#, id _1exists, and if not, a storage queue with a name of message-collection _1#, id _1is created.
Step S405: the message queue creates a storage queue corresponding to the consumption identification, and step S406 is executed.
Step S406: the message queue reads the message from the memory according to the message type in the consumption identification and then puts the message into the storage queue. In a preferred embodiment, the message type in the received consumption identifier is message-collection _1, the message queue reads the message from the message set with the name of message-collection _1 in the memory, and then the message is put into the storage queue with the name of message-collection _1# id \1. If the message type message-collection _2 in the received consumption identification is received, reading the message from the message set with the name of message-collection _2 in the memory, and then putting the message into a storage queue with the name of message-collection _2# #ID _1.
Step S407: the message queue sends the messages in the storage queue to the consumer. In a preferred embodiment, the message queue sends messages in the storage queue named message-collection _1#id _1to Consumer _1. In the above steps, both step S401 and step S403 are preparation jobs, and the present invention does not limit the order of implementation of these two steps. However, after step S401 is completed, step S402 is executed; after step S403 is completed, step S404 needs to be executed; after step S402 and step S404 are both completed, step S405 to step S407 are executed.
Fig. 5 is an information interaction diagram of a message transmission method according to an embodiment of the present invention. As shown in fig. 5, producer _1 establishes a connection with the message queue through P1, and sends the message to the message queue through P2; the Consumer _1 establishes connection with the message queue through C1 and sends a message-collection _1# ID _1to the message queue; the message queue stores messages from the Producer _1 to the disk through P3, creates a storage queue with the name of message-collection _1#, id _1through C2, reads messages from the disk through C3, puts the read messages into a storage queue with the name of message-collection _1#, id _1through C4, and sends the messages to the Consumer _1 through C5.
The above embodiment describes the message transmission process by taking a consumer as an example. As can be seen from the above, each message in the storage queue with the name of message-collection _1#id \u1 is only sent to one of all consumers consuming the message-collection _1#id \u1, and is in the peer-to-peer mode. Assuming that another Consumer (Consumer _ 2) connects to the message queue, and then sends a consumption identifier to the message queue (the message type of the consumption identifier is the same as the message type sent by Consumer _1 to the message queue), the message transmission method of the embodiment of the present invention is further described by taking two consumers as an example, specifically, see embodiment one and embodiment one
Example two. In the first and second embodiments, the consumption identifiers are message-collection _1# id _1and message-collection _1# id _2, respectively, and since the processing procedure of the message queue and the Consumer _1 is the same as that of the steps S403 to S407, only the processing procedure of the message queue and the Consumer _2 is described in the two embodiments.
Fig. 6 is a schematic diagram of implementing a point-to-point mode of a message transmission method according to an embodiment of the present invention. As shown in fig. 6, assuming that the subsequent Consumer _2 connects to the message queue and sends a consumption identifier (message-collection _1# id \1) identical to that of the Consumer _1, the processing procedure of the message queue and the Consumer _2 is as follows:
the first embodiment is as follows:
(1) The Consumer _2 is connected with the message queue, and then the message-collection _1# ID \u1 is sent to the message queue;
(2) After the message queue receives the message-collection _1# -ID _1, the two storage queues which have the same consumption identification and are named as the message-collection _1# -ID _1still exist after comparison;
(3) The message queue reads all messages with message-collection _1 message type from the memory and then puts the messages into the storage queue with message-collection _1# id \1. Suppose that three messages, message 1, 2 and 3, are placed into the storage queue with the name message-collection _1#, id _1.
(4) The message queue randomly sends the message in the storage queue with the name of message-collection _1# -ID _1to one of the consumers corresponding to the storage queue. Wherein, the consumer corresponding to the storage queue refers to the consumer whose consumption identification is the same as the name of the storage queue. For example, message 1 and message 2 are sent to Consumer _1, and message 3 is sent to Consumer _2.
As can be seen from the above, each message is sent to only one of all consumers among consumers with the same consumption identification, and the process is a point-to-point message mode.
Fig. 7 is a schematic diagram of an implementation of a publish-subscribe schema of a message transmission method according to an embodiment of the present invention. As shown in fig. 7, assuming that the subsequent Consumer _2 connects the message queue and sends a consumption identifier (message-collection _1# id \2) different from the Consumer _1, the processing procedure of the message queue and the Consumer _2 is as follows:
example two:
(1) The Consumer _2 is connected with the message queue, and then the message-collection _1# ID \2is sent to the message queue;
(2) After receiving the message-collection _1# -ID _2, the message queue judges whether a storage queue with the name of the message-collection _1# -ID _2exists, if the storage queue does not exist, the storage queue is created, and (3) is executed; if yes, directly executing (3);
(3) The message queue reads all messages with the message type of message-collection _1 from the memory, and then the messages are put into a storage queue with the name of message-collection _1# ID \2;
(4) The message queue sends messages in the storage queue named message-collection _1#, id _2to the Consumer _2.
As can be seen from the above, for each consumption identifier sent by a consumer, the message queue creates a storage queue corresponding to the consumption identifier; each message produced by the producer and having the same message type as the message type of the consumption identifier is respectively put into a storage queue with the prefix name of the message type. Through the above operation, it can be ensured that for each message belonging to a certain message type, there is a publish-subscribe mode between consumers of different consumption identities. For example, due to different consumption identifiers, a message is added to a storage queue named message-collection _1# id \u1 and a storage queue named message-collection _1# id \u2, and then the message in the storage queue named message-collection _1# id _1is sent to the Consumer _1 and the message in the storage queue named message-collection _1# id _2is sent to the Consumer _2, which is the publish-subscribe message mode.
In another preferred embodiment of the present invention, it is assumed that there are 4 consumers (consumer 1-consumer 4) connected to the message queue, and the consumption identifications sent to the message queue by consumer 1 and consumer 2 are message-collection _1# id _1, and the consumption identifications sent to the message queue by consumer 3 and consumer 4 are message-collection _1# id _2. When a producer produces a message and sends the message to the message queue, the message is stored in the storage queues with names message-collection _1# id _1and message-collection _1# id _2, respectively. The message queue randomly sends the message in the storage queue with the name of message-collection _1# -ID _1to one of the consumer 1 and the consumer 2 for consumption; the message queue randomly sends the message in the storage queue with the name of message-collection _1# -ID _2to one of the consumer 3 and the consumer 4 for consumption.
In the using process of the message queue, if the point-to-point mode is changed into the publish-subscribe mode, the consumers can use different consumption identifiers (namely, the message types and the identifiers in the consumption identifiers of the consumers are the same and different). And when the message queue finds that the consumption identifications of the consumers are different, the mode is automatically changed into a publish-subscribe mode. The third embodiment is used to describe how the point-to-point mode of the first embodiment is changed to the publish-subscribe mode. Since the connection relationship between the message queue and the provider _1 is not changed, the processing procedure between the message queue and the provider _1 is not changed, so that only the processing procedure between the message queue and the provider _2 is described in the third embodiment.
Example three: assuming that the subsequent Consumer _2 closes the connection with the message queue, then re-establishes the connection with the message queue and sends a consumption identifier (message-collection _1# ID \2) different from that of Consumer _1, the processing procedure of the message queue and Consumer _2 is as follows:
(1) Consumer _2 closes the connection to the message queue. When the application of Consumer _2 is closed, consumer _2 will automatically disconnect from the message queue.
(2) After the message queue finds that Consumer _2 closes the connection with the message queue, all the storage queues currently existing are checked, the storage queue with the name of message-collection _1# -ID \1is still used by the Consumer, and no processing is carried out on the storage queue.
(3) The Consumer _2 reconnects the message queue and then sends a consumption identifier different from the Consumer _1, for example, the consumption identifier sent is message-collection _1# ID _2. It is also possible that the Consumer _2 does not close the connection with the message queue and sends the message-collection _1# _ ID _2directly to the message queue, but in actual engineering practice, this process has robustness, reliability and complexity issues.
(4) After receiving the message-collection _1# -ID _2, the message queue judges whether a storage queue with the name of the message-collection _1# -ID _2exists or not, if not, the storage queue is established, and the step (5) is executed; if so, directly executing (5).
(5) The message queue reads all messages with message-collection _1 type from the memory and then places the messages into a storage queue with message-collection _1# id _2.
(6) The message queue sends messages in the storage queue with the name message-collection _1# id _2to the Consumer _2.
Fig. 8 is a schematic diagram of information interaction of a message transmission method changed from a peer-to-peer mode to a publish-subscribe mode according to an embodiment of the present invention. As shown in fig. 8, in the peer-to-peer mode, the Consumer _1 first establishes a connection with the message queue through C1_1 and sends a message-collection _1# id \u1 to the message queue; then the message queue creates a storage queue with the name of message-collection _1#, ID _1through C2-1, reads all messages with the message type of message-collection _1 from a disk through C1_3, puts the messages read through C1_3 into the storage queue with the name of message-collection _1#, ID _1through C1-4, and finally sends the messages to Consumer _1 through C1_ 5.
When the point mode is changed into the publish-subscribe mode, firstly, the Consumer _2 closes the connection with the message queue through C2_ 0; then, the Consumer _2 establishes connection with the message queue again through the C2_1 and sends a message-collection _1# ID \u2 to the message queue; then the message queue creates a storage queue with the name of message-collection _1#, ID _2through C2-2; secondly, reading all messages with the message type of message-collection _1 from a disk through a message queue C2_3, and then putting the messages read through the message queue C2_3 into a storage queue with the name of message-collection _1# #ID \u2 through a message queue C2-4; finally, the message queue sends the message to Consumer _2 through C2_ 5.
In the using process of the message queue, if the publish-subscribe mode is changed into the point-to-point mode, all consumers can use the same consumption identification. And when the message queue finds that the consumption identifications of the consumers are the same, the message queue automatically changes to a point-to-point mode. How to change the publish-subscribe mode of the second embodiment to the point-to-point mode is described in the fourth embodiment. Since the connection relationship between the message queue and the concumer _1 is not changed, the processing procedure between the message queue and the concumer _1 is not changed, and thus, in the fourth embodiment, only the processing procedure between the message queue and the concumer _2 is described.
Example four: assuming that the subsequent Consumer _2 closes the connection with the message queue, then re-establishes the connection with the message queue and sends the same consumption identifier (message-collection _1# ID _1) as that of Consumer _1, the processing procedure of the message queue and Consumer _2 is as follows:
(1) Consumer _2 closes the connection to the message queue.
(2) After the message queue finds that Consumer _2 closes the connection with the message queue, all the storage queues currently existing are checked, and if the storage queue with the name of message-collection _1# -ID \\ u 2 is not used by any Consumer, the storage queue with the name of message-collection _1# -ID \2is destroyed. In the embodiment, by comparing the name of the storage queue with the consumption identifications of all the consumers connected currently, if the name of the storage queue is different from the consumption identifications of all the consumers, the storage queue is not used by any consumer.
(3) Consumer _2 reconnects the message queue, and then sends a message-collection _1# ID _1to the message queue.
(4) After the message queue receives the message-collection _1# ID _1, the comparison confirms that two storage queues with the same consumption identification and the name of message-collection _1# ID _1still exist.
(5) The message queue reads all messages with message-collection _1 message type from the memory and then puts the messages into the storage queue with message-collection _1# id \1. Suppose that three messages, message 1, 2 and 3, are placed into the storage queue with the name message-collection _1#, id _1.
(6) The message queue randomly sends a message in a storage queue named message-collection _1# ID _1to one of the consumers. For example, message 1 and message 2 are sent to Consumer _1, and message 3 is sent to Consumer _2.
Fig. 9 is a schematic diagram of information interaction of a message transmission method changed from a publish-subscribe mode to a peer-to-peer mode according to an embodiment of the present invention. As shown in fig. 9, when the peer-to-peer mode is changed to the publish-subscribe mode, first, the Consumer _2 closes the connection with the message queue through D1; then the message queue discovers that the storage queue with the name of message-collection _1#, ID _2is not used by the consumer through D2, and destroys the storage queue; then, the Consumer _2 establishes connection with the message queue again through the D3 and sends the message-collection _1# ID _1to the message queue; then, the message queue reads all messages with message-collection _1 message types from the disk through D4, and then the read messages are put into a storage queue with the name of message-collection _1# ID \u1 through D5; finally, the message queue sends message 1 to Consumer _1 via D6, message 1 to Consumer _1 via D7, and message 3 to Consumer _2 via D8.
According to the message transmission method, the consumer sends the consumption identification to the message queue and stores the message into the storage queue constructed according to the consumption identification, so that the message transmission of a producer, the message queue and the consumer is realized, the message mode does not need to be determined in advance, and the use flexibility of a user is improved; storing the messages into the storage queues corresponding to the consumption identifications by confirming the difference of the consumption identifications, and then outputting the messages of the storage queues to the consumers, thereby realizing the dynamic change of the message mode of the message queues in the using process; if the consumer needs to change the consumption identifier, the consumer can disconnect the message queue, then reestablish the connection with the message queue and send a new consumption identifier to the message queue, and the operation increases the robustness and reliability of the message queue in actual engineering practice.
Fig. 10 is a schematic diagram of main blocks of a message transmission apparatus according to an embodiment of the present invention. As shown in fig. 10, the message transmission apparatus 100 according to the embodiment of the present invention mainly includes:
a receiving module 101, configured to receive at least one consumption identifier. The consumer connects to the message queue and then sends a consumption identification to the message queue. The consumption identification is generated by a consumer, and the specific structure can be message-collection _1#, ID _1, message-collection _1#, ID _2, message-collection _1#, ID _3and the like.
And the storage module 102 is configured to, when it is confirmed that the storage queue corresponding to the consumption identifier exists, obtain a message of the same type as the message, and then store the message in the storage queue. The producer produces a message and sends the message to the message queue. After receiving the consumption identification, the message queue checks whether a storage queue corresponding to the consumption identification exists at present, and if so, the message which is sent by the producer and has the same type as the message is stored in the storage queue; if the message type does not exist, a storage queue corresponding to the consumption identification is created, and then the message which is sent by the producer and has the same type as the message is stored in the storage queue.
And the output module 103 is used for outputting the messages in the storage queue. And outputting the message to the consumer by the storage queue corresponding to the consumption identification in the message queue. According to the technical scheme of the embodiment of the invention, the message transmission is carried out through the storage queue corresponding to the consumption identifier, and the message mode does not need to be determined in advance before the message transmission is carried out.
In addition, the message transmission apparatus 100 according to the embodiment of the present invention may further include: and a destroying module (not shown in the figure) for destroying the storage queue corresponding to the consumption identification when the storage queue is confirmed not to be connected with the consumer.
From the above description, it can be seen that, by sending a consumption identifier to a message queue by a consumer and storing a message in a storage queue constructed according to the consumption identifier, message transmission of a producer, the message queue and the consumer is realized without predetermining a message mode, and the flexibility of use of a user is increased; storing the messages into the storage queues corresponding to the consumption identifications by confirming the difference of the consumption identifications, and then outputting the messages of the storage queues to the consumers, thereby realizing the dynamic change of the message mode of the message queues in the using process; if the consumer needs to change the consumption identifier, the consumer can disconnect the message queue, then reestablish the connection with the message queue and send a new consumption identifier to the message queue, and the operation increases the robustness and reliability of the message queue in actual engineering practice.
Fig. 11 illustrates an exemplary system architecture 110 to which a message transmission method or message transmission apparatus of an embodiment of the present invention may be applied.
As shown in fig. 11, the system architecture 110 may include terminal devices 111, 112, 113, a network 114, and a server 115. Network 114 is the medium used to provide communication links between terminal devices 111, 112, 113 and server 115. The network 114 may include various connection types, such as wired, wireless communication links, or fiber optic cables, among others.
The user may use the terminal devices 111, 112, 113 to interact with the server 115 over the network 114 to receive or send messages or the like. Various messaging client applications, such as shopping applications, web browser applications, search applications, instant messaging tools, mailbox clients, social platform software, etc. (examples only) may be installed on the terminal devices 111, 112, 113.
The terminal devices 111, 112, 113 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The server 115 may be a server providing various services, such as a background management server (for example only) providing support for click events generated by users using the terminal devices 111, 112, 113. The background management server may analyze and perform other processing on the received click data, text content, and other data, and feed back a processing result (for example, target push information, product information — just an example) to the terminal device.
It should be noted that the message transmission method provided in the embodiment of the present application is generally executed by the server 115, and accordingly, the message transmission device is generally disposed in the server 115.
It should be understood that the number of terminal devices, networks, and servers in fig. 11 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
The invention also provides an electronic device and a computer readable medium according to the embodiment of the invention.
The electronic device of the present invention includes: one or more processors; a storage device, configured to store one or more programs, which when executed by the one or more processors, cause the one or more processors to implement a message transmission method according to an embodiment of the present invention.
The computer-readable medium of the present invention has stored thereon a computer program which, when executed by a processor, implements a message transmission method of an embodiment of the present invention.
Referring now to FIG. 12, a block diagram of a computer system 120 suitable for use in implementing an electronic device of an embodiment of the invention is shown. The electronic device shown in fig. 12 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiment of the present invention.
As shown in fig. 12, the computer system 120 includes a Central Processing Unit (CPU) 121 that can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM) 122 or a program loaded from a storage section 128 into a Random Access Memory (RAM) 123. In the RAM 123, various programs and data necessary for the operation of the computer system 120 are also stored. The CPU 121, ROM 122, and RAM 123 are connected to each other via a bus 124. An input/output (I/O) interface 125 is also connected to bus 124.
The following components are connected to the I/O interface 125: an input section 126 including a keyboard, a mouse, and the like; an output section 127 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage section 128 including a hard disk and the like; and a communication section 129 including a network interface card such as a LAN card, a modem, or the like. The communication section 129 performs communication processing via a network such as the internet. A drive 130 is also connected to the I/O interface 125 as needed. A removable medium 131 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 130 as necessary, so that a computer program read out therefrom is mounted into the storage section 128 as necessary.
In particular, the processes described above with respect to the main step diagrams may be implemented as computer software programs, according to embodiments of the present disclosure. For example, the disclosed embodiments of the invention include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the main step diagram. In such an embodiment, the computer program may be downloaded and installed from a network through the communication section 129, and/or installed from the removable medium 131. The above-described functions defined in the system of the present invention are executed when the computer program is executed by the Central Processing Unit (CPU) 121.
It should be noted that the computer readable medium shown in the present invention can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present invention, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present invention, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules described in the embodiments of the present invention may be implemented by software or hardware. The described modules may also be provided in a processor, which may be described as: a processor includes a receiving module, a storage module, and an output module. Where the names of these modules do not in some cases constitute a limitation of the module itself, for example, a receiving module may also be described as a "module receiving at least one consumption identification".
As another aspect, the present invention also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be separate and not incorporated into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to comprise: receiving at least one consumption identification; wherein the consumption identification comprises a message type; when the storage queue corresponding to the consumption identification is confirmed to exist, obtaining the message with the same type as the message, and then storing the message into the storage queue; and outputting the message in the storage queue.
From the above description, it can be seen that, by sending a consumption identifier to a message queue by a consumer and storing a message in a storage queue constructed according to the consumption identifier, message transmission of a producer, the message queue and the consumer is realized without predetermining a message mode, and the flexibility of use of a user is increased; storing the messages into the storage queues corresponding to the consumption identifications by confirming the similarities and differences of the consumption identifications, and then outputting the messages of the storage queues to the consumers, so that the dynamic change of the message mode of the message queues in the using process is realized; if the consumer needs to change the consumption identifier, the consumer can disconnect the message queue, then reestablish the connection with the message queue and send a new consumption identifier to the message queue, and the operation increases the robustness and reliability of the message queue in actual engineering practice.
The product can execute the method provided by the embodiment of the invention, and has corresponding functional modules and beneficial effects of the execution method. For technical details that are not described in detail in this embodiment, reference may be made to the method provided by the embodiment of the present invention.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (6)

1. A method for message transmission, comprising:
the message queue receives a plurality of consumption identifications from the consumers; wherein the consumption identification comprises a message type;
when the message queue confirms that a storage queue corresponding to the consumption identification exists, obtaining a message with the same type as the message, and then storing the message into the storage queue;
the message queue outputs the messages in the storage queue; wherein, when the consumption identifications are all the same, the message is randomly output to one of the consumers corresponding to the storage queue; when the consumption identifications are different, the messages in the storage queues are respectively output to the consumers corresponding to the storage queues;
when the storage queue corresponding to the consumption identifier is confirmed to exist, obtaining a message with the same type as the message, and then storing the message into the storage queue, wherein the method comprises the following steps:
when confirming that the consumption identifications are the same and a storage queue corresponding to the consumption identification exists, obtaining a message with the same type as the message from a storage, and then storing the message into the storage queue;
and when the consumption identifications are confirmed to be different and storage queues corresponding to the consumption identifications exist, respectively acquiring messages with the same type as the messages from a memory, and then respectively storing the messages into the storage queues.
2. The method of claim 1, wherein the step of outputting the message in the store queue is followed by: and destroying the storage queue corresponding to the consumption identification when confirming that the storage queue is not connected with the consumer.
3. A message transmission apparatus, implemented by a message queue, comprising:
a receiving module for receiving a plurality of consumption identifications from a consumer; wherein the consumption identification comprises a message type;
the storage module is used for acquiring the message with the same type as the message when confirming that the storage queue corresponding to the consumption identifier exists, and then storing the message into the storage queue;
the output module is used for outputting the messages in the storage queue; wherein the message is randomly output to one of the consumers corresponding to the storage queue when the consumption identifications are all the same; when the consumption identifications are different, the messages in the storage queues are respectively output to the consumers corresponding to the storage queues;
when the storage queue corresponding to the consumption identifier is confirmed to exist, obtaining a message with the same type as the message, and then storing the message into the storage queue, wherein the method comprises the following steps:
when confirming that the consumption identifications are the same and a storage queue corresponding to the consumption identification exists, obtaining a message with the same type as the message from a storage, and then storing the message into the storage queue;
and when the consumption identifications are confirmed to be different and storage queues corresponding to the consumption identifications exist, respectively acquiring messages with the same type as the messages from a memory, and then respectively storing the messages into the storage queues.
4. The apparatus of claim 3, further comprising: and the destroying module is used for destroying the storage queue corresponding to the consumption identification when the storage queue is not connected with the consumer.
5. An electronic device, comprising:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method of claim 1 or 2.
6. A computer-readable medium, on which a computer program is stored, which program, when being executed by a processor, carries out the method of claim 1 or 2.
CN201711472720.8A 2017-12-29 2017-12-29 Message transmission method and device Active CN109995801B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201711472720.8A CN109995801B (en) 2017-12-29 2017-12-29 Message transmission method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201711472720.8A CN109995801B (en) 2017-12-29 2017-12-29 Message transmission method and device

Publications (2)

Publication Number Publication Date
CN109995801A CN109995801A (en) 2019-07-09
CN109995801B true CN109995801B (en) 2022-11-08

Family

ID=67108946

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201711472720.8A Active CN109995801B (en) 2017-12-29 2017-12-29 Message transmission method and device

Country Status (1)

Country Link
CN (1) CN109995801B (en)

Families Citing this family (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110505162B (en) * 2019-08-08 2022-07-26 腾讯科技(深圳)有限公司 Message transmission method and device and electronic equipment
CN110365802B (en) * 2019-08-26 2022-11-15 北京奇艺世纪科技有限公司 Message transmission method, message forwarding equipment and storage medium
CN110674004A (en) * 2019-08-28 2020-01-10 北京奇艺世纪科技有限公司 Queue message recording method, system, electronic equipment and storage medium
CN112711485A (en) * 2019-10-25 2021-04-27 北京沃东天骏信息技术有限公司 Message processing method and device
CN111401819B (en) * 2020-04-08 2023-07-11 上海东普信息科技有限公司 Intersystem data pushing method and system
CN113296977B (en) * 2021-02-24 2023-04-07 阿里巴巴集团控股有限公司 Message processing method and device
CN113961379B (en) * 2021-12-22 2022-04-12 零犀(北京)科技有限公司 Message processing method and device based on man-machine conversation
CN115379012B (en) * 2022-10-25 2023-03-24 航天云网数据研究院(广东)有限公司 Industrial interconnection platform message queue deployment method and device based on identification analysis

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103051521A (en) * 2013-01-09 2013-04-17 浪潮电子信息产业股份有限公司 Retransmitting method of message in cloud environment
CN106021315A (en) * 2016-05-05 2016-10-12 智者四海(北京)技术有限公司 Log management method and system for application program

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101064619B (en) * 2007-05-25 2010-11-17 上海众恒信息产业股份有限公司 Resource management platform having topics distribution function and its method
CN101466109B (en) * 2009-01-14 2011-06-08 北京邮电大学 Communication system and method for WiMAX network management
CN101510857B (en) * 2009-03-27 2012-05-30 腾讯科技(深圳)有限公司 Method and apparatus for processing IM message
CN102215177B (en) * 2011-05-31 2014-07-02 广州华多网络科技有限公司 Method and device for processing system message of instant communication software

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103051521A (en) * 2013-01-09 2013-04-17 浪潮电子信息产业股份有限公司 Retransmitting method of message in cloud environment
CN106021315A (en) * 2016-05-05 2016-10-12 智者四海(北京)技术有限公司 Log management method and system for application program

Also Published As

Publication number Publication date
CN109995801A (en) 2019-07-09

Similar Documents

Publication Publication Date Title
CN109995801B (en) Message transmission method and device
CN110601952A (en) Multi-channel message notification sending method and device
CN109729040B (en) Method, apparatus and computer readable medium for selection of a protocol
CN111427701A (en) Workflow engine system and business processing method
CN111478781B (en) Message broadcasting method and device
CN111831461A (en) Method and device for processing business process
CN108764866B (en) Method and equipment for allocating resources and drawing resources
CN112084042A (en) Message processing method and device
CN110798495B (en) Method and server for end-to-end message push in cluster architecture mode
CN109981546B (en) Method and device for acquiring remote call relation between application modules
US20180343216A1 (en) Context driven modification of attachments in a messaging session
CN112948138A (en) Method and device for processing message
CN113779122B (en) Method and device for exporting data
CN113127561B (en) Method and device for generating service single number, electronic equipment and storage medium
CN114417318A (en) Third-party page jumping method and device and electronic equipment
CN113572704A (en) Information processing method, production end, consumption end and server
CN113760487A (en) Service processing method and device
CN113765983A (en) Site service deployment method and device
CN112099841A (en) Method and system for generating configuration file
CN113760693A (en) Method and apparatus for local debugging of microservice systems
CN116112880B (en) MQ-based high concurrency short message sending method and device
CN113766437B (en) Short message sending method and device
CN109388536B (en) Data collection method and device
CN113709199A (en) Promotion information display method and device
CN113452739A (en) Message processing method and device

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