CN116954934A - Message processing method, device, equipment, system and readable storage medium - Google Patents
Message processing method, device, equipment, system and readable storage medium Download PDFInfo
- Publication number
- CN116954934A CN116954934A CN202210379656.3A CN202210379656A CN116954934A CN 116954934 A CN116954934 A CN 116954934A CN 202210379656 A CN202210379656 A CN 202210379656A CN 116954934 A CN116954934 A CN 116954934A
- Authority
- CN
- China
- Prior art keywords
- message
- queue
- preset
- routing field
- 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.)
- Pending
Links
- 238000003672 processing method Methods 0.000 title claims abstract description 18
- 238000003860 storage Methods 0.000 title claims abstract description 12
- 238000009826 distribution Methods 0.000 claims abstract description 76
- 238000000034 method Methods 0.000 claims abstract description 45
- 238000012544 monitoring process Methods 0.000 claims abstract description 12
- 238000012545 processing Methods 0.000 claims description 27
- 238000004891 communication Methods 0.000 claims description 22
- 238000012986 modification Methods 0.000 abstract description 4
- 230000004048 modification Effects 0.000 abstract description 4
- 238000010586 diagram Methods 0.000 description 8
- 238000013461 design Methods 0.000 description 7
- 230000018109 developmental process Effects 0.000 description 7
- 230000008569 process Effects 0.000 description 7
- 230000005540 biological transmission Effects 0.000 description 4
- 230000008878 coupling Effects 0.000 description 3
- 238000010168 coupling process Methods 0.000 description 3
- 238000005859 coupling reaction Methods 0.000 description 3
- 230000006870 function Effects 0.000 description 3
- RWSOTUBLDIXVET-UHFFFAOYSA-N Dihydrogen sulfide Chemical compound S RWSOTUBLDIXVET-UHFFFAOYSA-N 0.000 description 2
- 230000011218 segmentation Effects 0.000 description 2
- 238000012546 transfer Methods 0.000 description 2
- 101100366043 Caenorhabditis elegans sms-2 gene Proteins 0.000 description 1
- 230000009286 beneficial effect Effects 0.000 description 1
- 230000000694 effects Effects 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 238000000605 extraction Methods 0.000 description 1
- 230000007246 mechanism Effects 0.000 description 1
- 230000004044 response Effects 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
- 238000012360 testing method Methods 0.000 description 1
- 230000007704 transition Effects 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements 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/46—Multiprogramming arrangements
- G06F9/54—Interprogram communication
- G06F9/546—Message passing systems or structures, e.g. queues
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F2209/00—Indexing scheme relating to G06F9/00
- G06F2209/54—Indexing scheme relating to G06F9/54
- G06F2209/547—Messaging middleware
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F2209/00—Indexing scheme relating to G06F9/00
- G06F2209/54—Indexing scheme relating to G06F9/54
- G06F2209/548—Queue
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Computer And Data Communications (AREA)
Abstract
The application provides a message processing method, a device, equipment, a system and a readable storage medium, relating to the technical field of micro-services, wherein the method comprises the following steps: and acquiring a message, determining a target queue in a preset message queue according to the routing field, and writing the message into the target queue to push the message to a message distribution processor monitoring the target queue. According to the technical scheme, the routing field is added in the message to indicate the message type, and the message is pushed to the corresponding target queue according to the routing field, so that the distribution of multiple message types can be flexibly realized, the modification of program codes and the reintroduction of a software development kit are not needed, and the efficiency of message distribution is improved.
Description
Technical Field
The present application relates to the field of micro-service technologies, and in particular, to a method, an apparatus, a device, a system, and a readable storage medium for processing a message.
Background
Micro services advocate the division of a single application into a small set of services, with the services being coordinated and coordinated with each other to provide the final value to the user. Each service runs in an independent process, and the service communicate with each other by adopting a lightweight communication mechanism. There are typically many messaging and distribution requirements that need to be handled between applications and at the user's end.
In the prior art, the distribution and the reception of the messages are processed by each service by self, and the distribution and the reception of the messages are realized by configuring program codes on the side of a message producer and introducing corresponding software development kits (Software Development Kit, SDK) on the side of a message consumer.
However, in this manner in the prior art, if a new message type needs to be added or multiple different types of messages need to be concurrent during message distribution, modification of program codes and reintroduction of a software development kit need to be performed, so that message distribution is not flexible enough and distribution efficiency is low.
Disclosure of Invention
The application provides a message processing method, a device, equipment, a system and a readable storage medium, which are used for solving the problems of inflexible distribution and low distribution efficiency of the existing message.
In a first aspect, the present application provides a message processing method, applied to a message production center in a micro service system, the method comprising:
obtaining a message, wherein the message at least comprises message content, a routing field for indicating the type of the message and event information for indicating a message consumer;
determining a target queue in a preset message queue according to the routing field;
Writing the message to the target queue to push the message to a message distribution processor listening to the target queue, the message distribution processor for sending the message content to the message consumer.
In one possible design of the first aspect, the determining, according to the routing field, a target queue in a preset message queue includes:
detecting whether the routing field contains a preset identifier or not;
if the routing field does not contain the preset identification, searching a queue matched with the routing field in the preset message queue as the target queue.
In another possible design of the first aspect, the determining, according to the routing field, a target queue in a preset message queue includes:
if the routing field contains a preset identifier, acquiring the position of the preset identifier in the routing field;
dividing the routing field into at least two subfields according to the position of the preset identifier in the routing field;
and searching a queue matched with each subfield in the preset message queue to serve as the target queue.
In yet another possible design of the first aspect, the method further comprises:
responding to a new adding request of the message type, and acquiring a new adding field, wherein the new adding field is used for identifying the newly added message type;
and adding the newly added field into the routing field, wherein the newly added field and the routing field are separated by a preset identifier.
In yet another possible design of the first aspect, the method further comprises:
determining a new added queue matched with the new added field in the preset message queue according to the new added field;
and adding a newly added message distribution processor, wherein the newly added message distribution processor is used for monitoring the newly added queue to acquire the message written into the newly added queue.
In yet another possible design of the first aspect, the micro service system further includes a preset application programming interface, the message production center is connected to at least two message producers through the preset application programming interface, and the obtaining the message includes:
and receiving the message messages pushed by each message producer through the preset application programming interface.
In yet another possible design of the first aspect, the method further comprises:
Receiving a push state fed back by the message distribution processor, wherein the push state is used for indicating whether the message distribution processor pushes the message content to the message consumer;
and updating the state of the message according to the push state.
In a second aspect, the present application provides a message processing method, applied to a message distribution processor in a micro server system, the method comprising:
when a target queue in a preset message queue is monitored to write a message, acquiring the message, wherein the message at least comprises message content, a routing field for indicating the type of the message and event information for indicating a message consumer;
inquiring from a message subscription registry to obtain the message consumer according to the event information, wherein the message subscription registry comprises registration information of at least one message consumer;
pushing the message content to the message consumer.
In a third aspect, the present application provides a message processing apparatus comprising:
the message acquisition module is used for acquiring a message, wherein the message at least comprises message content, a routing field for indicating the type of the message and event information for indicating a message consumer;
The queue determining module is used for determining a target queue in a preset message queue according to the routing field;
and the message writing module is used for writing the message into the target queue so as to push the message to a message distribution processor for monitoring the message queue, and the message distribution processor is used for sending the message content to the message consumer.
In a fourth aspect, the present application provides a message processing apparatus comprising:
the acquisition module is used for acquiring the message when the message is written in a target queue in the preset message queue, wherein the message at least comprises message content, a routing field for indicating the message type and event information for indicating a message consumer;
the inquiring module is used for inquiring from a message subscription registry to obtain the message consumer according to the event information, wherein the message subscription registry comprises registration information of at least one message consumer;
and the pushing module is used for pushing the message content to the message consumer.
In a fifth aspect, the present application provides a message processing apparatus comprising: a memory, a processor, and a communication interface for communicating with other devices;
The memory stores computer-executable instructions;
the processor executes the computer-executable instructions stored in the memory to cause the message processing device to perform the method described above.
In a sixth aspect, the present application provides a message processing apparatus comprising: a memory, a processor, and a communication interface for communicating with other devices;
the memory stores computer-executable instructions;
the processor executes the computer-executable instructions stored in the memory to cause the message processing device to perform the method described above.
In a seventh aspect, the present application provides a micro-service system comprising: a message production center in data communication with at least one message producer, and at least one message distribution processor in communication with at least one message consumer, each message distribution processor listening to a message queue;
the message production center is used for receiving the message of each message producer and writing the message into a message queue matched with the routing field according to the routing field in the message;
the message distribution processor is used for acquiring message messages in the monitored message queue, inquiring from the message subscription registration center according to event information in the message messages to obtain target message consumers, and pushing message contents in the message messages to the target message consumers.
In an eighth aspect, the present application provides a readable storage medium having stored therein computer instructions which, when executed by a processor, are adapted to carry out a method as described above.
The message processing method, the device, the equipment, the system and the readable storage medium provided by the application can flexibly realize the distribution of various message types without modifying program codes and reintroducing software development kits by adding the routing field in the message to indicate the message type and pushing the message to the corresponding target queue according to the routing field, thereby improving the efficiency of message distribution.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the application and together with the description, serve to explain the principles of the application;
fig. 1 is a schematic diagram of a scenario of a message processing method according to an embodiment of the present application;
fig. 2 is a schematic flow chart of a first embodiment of a message processing method according to an embodiment of the present application;
fig. 3 is a schematic flow chart of a second embodiment of a message processing method according to the embodiment of the present application;
FIG. 4 is a schematic diagram of a micro-service system according to an embodiment of the present application;
Fig. 5 is a schematic structural diagram of a first embodiment of a message processing apparatus according to an embodiment of the present application;
fig. 6 is a schematic structural diagram of a second embodiment of a message processing apparatus according to an embodiment of the present application.
Specific embodiments of the present application have been shown by way of the above drawings and will be described in more detail below. The drawings and the written description are not intended to limit the scope of the inventive concepts in any way, but rather to illustrate the inventive concepts to those skilled in the art by reference to the specific embodiments.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present application more apparent, the technical solutions of the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application, and it is apparent that the described embodiments are some embodiments of the present application, but not all embodiments of the present application. All other embodiments, which can be made by those skilled in the art based on the embodiments of the application without making any inventive effort, are intended to be within the scope of the application.
First, the terms involved in the present application will be explained:
message queues:
message Queue (MQ) is a middleware for data transfer, a Message consumer subscribes to a certain Message Queue, and a Message producer creates a Message and then issues the Message to the Message Queue, and finally the Message Queue sends the Message to the Message consumer.
Message producer:
a message producer refers to the party that places data into a message queue.
Message consumers:
a message consumer refers to a party that fetches data from a message queue.
Fig. 1 is a schematic diagram of a scenario of a message processing method according to an embodiment of the present application, as shown in fig. 1, taking a common order system as an example, a user may transact related communication services, such as transacting broadband services, on an APP of a mobile phone 10, where service logic that may be generated after the user clicks a "confirm transact" button includes: generating business documents, sending short message notification, sending mailbox notification and the like. Under the architecture of the micro-service system, since the whole mobile phone APP is divided into a plurality of services, the services coordinate and cooperate with each other to provide final value for users, in this scenario, the distribution and reception of messages between the services are involved, for example, a message producer (for example, the service 11) is responsible for generating a business document and distributing the business document to a message consumer (for example, the service 12), and the message consumer is responsible for sending mail notification after receiving the business document. In the related art, in the process of message distribution, it is common for the service 11 to directly call the service 12 for data transmission, for example, the service 11 calls an interface or a method of the service 12 to distribute a business document to the service 12. In this way, when a newly added message consumer needs to monitor a message of the service 11 (for example, the newly added message consumer is the service 13 and is responsible for sending a short message notification), the message producer is often required to modify a code or configuration, and the message consumer also needs to introduce a corresponding software development kit, which is not beneficial to the stability, expansibility and loosely coupled architecture design of the entire micro-service system.
In view of the above problems, the message processing method, device, equipment, system and readable storage medium according to the embodiments of the present application divide the routing field by using the preset identifier, so as to deliver the message to the target queue of the preset message queue, and when the message type is added, the type can be added by directly connecting with the preset identifier, so that the stability, expansibility and low coupling of the system are improved, and when the service of accessing to the monitoring message is added, the configuration or code of the message producer is not required to be modified. Meanwhile, a message subscription registry is provided to fill in the service ip, port, url and monitored publisher ID and event of each message consumer, so that when the message consumer is newly added, the publisher does not need to modify codes and configuration, the stability of the system is improved, the coupling degree among the services is reduced, and the flexibility is improved. The message distribution processor can also distribute the message content to the corresponding message consumers by means of the information of each message consumer in the message subscription registration center, so that batch pushing of the messages is realized.
The technical scheme of the application is described in detail through specific embodiments. It should be noted that the following embodiments may be combined with each other, and the same or similar concepts or processes may not be described in detail in some embodiments.
Fig. 2 is a schematic flow chart of a message processing method according to an embodiment of the present application, where the method may be applied to a message production center in a micro-service system. For example, a message production center may communicate with a plurality of message producers to obtain messages produced by the respective message producers. As shown in fig. 2, the method specifically may include the following steps:
s201, obtaining a message.
The message at least comprises message content, a routing field for indicating the type of the message and event information for indicating the message consumer. In this embodiment, the message is written in a programming language, and in some other embodiments, the message may be portable in other languages.
The message format of the message may be, for example, as follows:
{"routing":"sms.email.event1",
"state_key":"key",
"body":{
"content_type":"text",
"msg":"hello22323",
"title": "test push 1",
"email":{
"account":"account@com.cn",
"password":"word",
"cc":[
"account@com.cn"],
"email_to":[
"account@com.cn"],
"email_attachment":[
"1620294849-11.jpg",
"1620299192-background free, png" ],
"sms":{"sms_to":["18620010839"]},
"event":{
"event_id":"taskStart",
"tenant_id":"airflow",
"publisher":"app_extraction",
"publish_time":"2021-08-11 12:00:01"}}}
the value "sms.email.event1" of "routing" is a routing field, the value "hello22323" of "msg" may be a message content, the value of "event" is event information, and specifically may include the value of "tenant_id" and the value of "tenant_id" are corresponding message consumers.
In this embodiment, the routing field "sms.email.event1" includes a preset identifier "," through which the routing field may be divided into three subfields "sms", "email" and "event", where the message types indicated by the different subfields are different. For example, "sms" indicates a short message and "email" indicates a mail.
For example, the message production center may obtain message messages pushed by more than two message producers, for example, different message producers implement pushing of the message messages according to a unified interface, and message messages pushed to the message production center by different message producers are different.
S202, determining a target queue in a preset message queue according to the routing field.
In this embodiment, the preset message queue may be a rabitmq queue, which includes a switch and a queue. Wherein, the switch is used for routing the message to a certain queue according to a certain rule, different switches can have different routing rules (a plurality of switches can be included in the RabbitMQ queue, each switch can be responsible for a plurality of queues), and the queues are used for storing the message.
The preset message queue may include more than two queues, and the queue matched with the routing field may be selected as the target queue according to the routing field.
For example, the routing field may be divided into a plurality of subfields, and the preset routing rule may be that each subfield corresponds to one target queue respectively. In other embodiments, the entire routing field may be directly associated with one target queue.
S203, writing the message into the target queue to push the message to the message distribution processor of the monitoring target queue.
Wherein the message distribution processor is configured to send the message content to a message consumer. A message distribution processor listens to a target queue, and a message distribution processor can push message content contained in a message in the target queue to a plurality of message consumers associated therewith.
According to the embodiment of the application, the routing field is added in the message to indicate the message type, and the message is pushed to the corresponding target queue according to the routing field, so that the distribution of various message types can be flexibly realized, the modification of program codes and the reintroduction of software development kits are not needed, and the efficiency of message distribution is improved.
In some embodiments, the step S202 may be specifically implemented by the following steps:
detecting whether a preset identifier is contained in a routing field;
if the routing field does not contain the preset identification, searching a queue matched with the routing field in the preset message queue as a target queue.
Illustratively, in this embodiment, the preset identifier is "," and in other embodiments, the preset identifier may be in other forms. The predetermined message queue (i.e. the above-mentioned rabitmq) includes a plurality of queues, each of which matches a different value (e.g. a character) according to a predetermined routing rule, and if the message packet includes a value matching the target queue, the message packet is written into the target queue.
In this embodiment, taking the routing field "a, b, c, d" as an example, it does not include the preset identifier ".", there may be only one corresponding target queue, i.e. the target queue 1.
The embodiment of the application can determine whether the message types are multiple by searching whether the routing field contains the preset identifier or not, and each message type can find the corresponding target queue so as to write the message delivery into the target queue, thereby realizing the concurrence of multiple message types.
In some embodiments, the step S202 may be specifically implemented by the following steps:
if the routing field contains the preset identifier, acquiring the position of the preset identifier in the routing field;
dividing the routing field into at least two subfields according to the position of the preset identifier in the routing field;
and searching a queue matched with each subfield in a preset message queue to serve as a target queue.
In this embodiment, the routing field is exemplified by "sms.email.event1" described above, which includes two preset identifiers ".", and the entire routing field can be divided into three subfields, "sms", "email" and "event" by the two preset identifiers.
Wherein each subfield has a matching queue, and the message is written into the matching queue of each subfield.
In this embodiment, when the preset identifier is used to segment the routing field, there is no problem of the sequence of the sub-fields after the segmentation, for example, taking the routing field as "a.b.c", if the segmentation is not performed according to the preset identifier, the queue corresponding to the routing field "a.b.c" is the target queue 2, the message packet will be written into the target queue 2, and similarly, if the sequence is adjusted, for example, the routing field becomes "b.a.c" or "c.a.b", the corresponding queue may become the target queue 3 or the target queue 4. I.e. the corresponding target queues are different if not partitioned according to the preset identification ".", different alphabetic orders in the routing field.
If the division is performed according to the preset identifier "," the routing field "a.b.c" or the routing field "b.a.c" or "c.a.b" is divided into three subfields "a", "b" and "c", the queue corresponding to the subfield "a" is the target queue 5, the queue corresponding to the subfield "b" is the target queue 6, and the queue corresponding to the subfield "c" is the target queue 7.
The embodiment of the application indicates the message type contained in the routing field by using the preset identifier' ″ number, and meanwhile, the message production center cuts the message and writes the cut message into the target queue corresponding to the sub-field, thereby realizing the consistency of the type a.b.c and c.a.b.
In some embodiments, the above method may further comprise the steps of:
in response to a new request for the message type, a new field is acquired and added to the routing field.
The newly added field is used for identifying the newly added message type, and the newly added field and the route field are separated through a preset identifier. For example, the new added field may be "event2", and the new route field obtained by adding the new added field to the route field is "sms.email.event1.event2".
In this embodiment, if the newly added field is "event2", the identified message type is event, if the newly added field is "email2", the identified message type is mail, and if the newly added field is "sms2", the identified message type is short message.
When the newly added field is added to the routing field, the message is written into the target queue and is additionally written into the queue matched with the newly added field.
The embodiment of the application can indicate four message types by directly adding the message push types at the' number interval on the basis of the original routing field a.b.c. to obtain a.b.c.d. without modifying codes, thereby improving the expandability and realizing the transmission of multiple message channels of one message.
On the basis of the above embodiments, in some embodiments, the above method may further include the steps of:
and determining a new added queue matched with the new added field in the preset message queue according to the new added field, and adding a new added message distribution processor.
The newly added message distribution processor is used for monitoring the newly added queue to acquire the message written into the newly added queue.
In this embodiment, after the newly added message distribution processor monitors the message, the message content in the message is pushed to each associated message consumer. Specifically, event information, such as event id, publisher and tenant id information, in the message is taken out, a service consumer list subscribed to the publisher and the time is queried, and then the value "hello22323" of "msg" in the message is respectively pushed to monitoring interfaces of all consumers, so that the process of distributing the message is completed.
According to the embodiment of the application, the message distribution and processing are realized in a pluggable mode through the newly added message distribution processor, the newly added message distribution processor does not influence the trained service, and the stability and expansibility are improved.
In some embodiments, the message messages are all pushed to the message producer by the message producer, and when the number of message producers is more than two, the message producer in the micro server system can be connected with each message producer through the preset application programming interface to obtain the message messages pushed by each message producing group. The method may thus comprise the steps of: and receiving the message messages pushed by each message producer through a preset application programming interface.
In this embodiment, the message production center may provide a state transition application programming interface (Representational State Transfer Application Programming Interface, restful API) for message creation, message retransmission, message status update, and querying as a preset application programming interface. Different message producers push message messages to a message production center according to a unified preset application programming interface.
The embodiment of the application realizes the message registration, monitoring and distribution in a restful api mode through a unified preset application programming interface, is completely irrelevant to a program language, realizes the non-invasive mode access to a message production center, does not need to modify codes and introduce a software development kit, and is more flexible and convenient.
In some embodiments, the above method may further comprise the steps of:
and receiving the push state fed back by the message distribution processor, and updating the state of the message according to the push state.
Wherein the push state is used to instruct the message distribution processor whether to push the message content to the message consumer.
In this embodiment, the message distribution processor may feed back the push status to the message production center through the preset application program interface. The message production center can record and update the push state (such as successful/unsuccessful push) of each message, and can also be used for a third party to query the push state through the preset application program interface.
Fig. 3 is a schematic flow chart of a second embodiment of a message processing method according to an embodiment of the present application, where the method may be applied to a message distribution processor in a micro service system. As shown in fig. 3, the method specifically may include the following steps:
S301, when a target queue in a preset message queue is monitored to write a message, the message is acquired.
S302, inquiring from the message subscription registry to obtain the message consumer according to the event information.
S303, pushing the message content to a message consumer.
The message comprises at least message content, a routing field for indicating the message type and event information for indicating the message consumer, and the message subscription registry comprises registration information of at least one message consumer.
In this embodiment, the event information may be the value of the "event" described above, which includes the event id, the publisher and the tenant id information, and the message distribution processor may query the service consumer list subscribed to the publisher and the time through the query message subscription registry to determine the message consumer.
Wherein the message subscription registry provides forms and is configured with registration information that can be used to implement message consumer specified listening messages, events, and message producers. The filled form information mainly comprises: the subscribed APP ID, the subscribed event ID, the information of the message consumer's own service instance name, service address, port number, etc.
Illustratively, the data format of the form may be:
wherein, the value "APP ID1" of "subscore_app ID" represents the ID of the subscribed APP, the value [ "event1", "event2" ] of "subscore_event ID" represents the subscribed time ID, the value "my_app ID" of "my_app ID" represents the service instance name of the message consumer itself, the value "127.0.0.1" of "my_host" represents the service address, and the value "8080" of "my_port" represents the port.
The embodiment of the application fills in the service ip, port, url and monitored publisher ID and event of the message consumer through the message subscription registry, so that the message producer does not need to modify codes and configuration when the consumer is newly added, the stability of the system is improved, the coupling degree among the services is reduced, and the flexibility is improved.
Fig. 4 is a schematic diagram of a micro service system according to an embodiment of the present application, where, as shown in fig. 4, the micro service system includes at least one message production center and one message distribution processor, the message production center is in data communication with at least one message producer, the message distribution processor is in communication with at least one message consumer, and each message distribution processor listens to a message queue;
The message production center is used for receiving the message of each message producer and writing the message into a message queue matched with the routing field according to the routing field in the message;
the message distribution processor is used for acquiring the message in the monitored message queue, inquiring from the message subscription registration center according to the event information in the message, obtaining the target message consumer and pushing the message content in the message to the target message consumer.
Wherein the message production center provides a restful api for message creation, message retransmission, message status update and query. Different message producers uniformly push message messages to a message production center according to a uniform restful api interface, and the message production center writes the message messages into a target queue in a preset message queue according to a preset identifier in a routing field in the message messages according to the routing field in the message messages, so that the message messages are distributed, and multiple types of messages can be sent by supporting one interface call. Each message distribution processor listens to its own queue individually and delivers it to the message consumer.
Wherein the message distribution processor listens to its own queues. When new message content exists in the queue, message pushing is received, and message distribution is performed after the message pushing is processed. The logic of message distribution is that event information is taken out from message messages pushed by a message production center, event id, publisher and tenant id information is obtained, service consumer lists subscribing the publisher and the time are queried through a message subscription registration center, then message contents are respectively pushed to monitoring interfaces of all consumers, and then message distribution is completed, and a message distribution processor synchronizes message pushing states to the message production center.
The following are examples of the apparatus of the present application that may be used to perform the method embodiments of the present application. For details not disclosed in the embodiments of the apparatus of the present application, please refer to the embodiments of the method of the present application.
Fig. 5 is a schematic structural diagram of a first embodiment of a message processing apparatus according to an embodiment of the present application, which may be integrated on a server, as shown in fig. 5, and may include a message acquisition module 51, a queue determining module 52, and a message writing module 53.
The message obtaining module 51 is configured to obtain a message. The queue determining module 52 is configured to determine a target queue from the preset message queues according to the routing field. The message writing module 53 is configured to write the message to the target queue to push the message to the message distribution processor of the listening message queue.
The message distribution processor is used for sending the message content to the message consumer.
In some embodiments, the queue determining module may specifically be configured to:
detecting whether a preset identifier is contained in a routing field;
If the routing field does not contain the preset identification, searching a queue matched with the routing field in the preset message queue as a target queue.
Optionally, in some embodiments, the queue determining module may specifically be configured to:
if the routing field contains the preset identifier, acquiring the position of the preset identifier in the routing field;
dividing the routing field into at least two subfields according to the position of the preset identifier in the routing field;
and searching a queue matched with each subfield in a preset message queue to serve as a target queue.
In some embodiments, the apparatus further includes a field adding module configured to:
responding to a new adding request of the message type, and acquiring a new adding field;
the newly added field is added to the routing field.
The newly added field is used for identifying the newly added message type, and the newly added field and the route field are separated through a preset identifier.
In some embodiments, the apparatus further includes a processor add-on module configured to:
determining a new added queue matched with the new added field in a preset message queue according to the new added field;
an newly added message distribution processor is added.
The newly added message distribution processor is used for monitoring the newly added queue to acquire the message written into the newly added queue.
In some embodiments, the microservice system further includes a preset application programming interface, the message production center is connected with at least two message producers through the preset application programming interface, and the message acquisition module may specifically be configured to receive message messages pushed by each message producer through the preset application programming interface.
In some embodiments, the apparatus further includes an update module configured to:
receiving a push state fed back by a message distribution processor;
and updating the state of the message according to the push state.
Wherein the push state is used to instruct the message distribution processor whether to push the message content to the message consumer.
Fig. 6 is a schematic structural diagram of a second embodiment of a message processing apparatus according to an embodiment of the present application, where the apparatus may be applied to a server, and as shown in fig. 6, the message processing apparatus may include an obtaining module 61, a querying module 62, and a pushing module 63.
The obtaining module 61 is configured to obtain a message when it is monitored that a target queue in the preset message queues is written with the message. The query module 62 is configured to query the message subscription registry for message consumers based on the event information. The push module 63 is used to push message content to message consumers.
The message comprises at least message content, a routing field for indicating the message type and event information for indicating the message consumer, and the message subscription registry comprises registration information of at least one message consumer.
The device provided by the embodiment of the application can be used for executing the method in the embodiment, and the implementation principle and the technical effect are similar, and are not repeated here.
It should be noted that, it should be understood that the division of the modules of the above apparatus is merely a division of a logic function, and may be fully or partially integrated into a physical entity or may be physically separated. And these modules may all be implemented in software in the form of calls by the processing element; or can be realized in hardware; the method can also be realized in a form of calling software by a processing element, and the method can be realized in a form of hardware by a part of modules. For example, the acquisition module may be a processing element that is set up separately, may be implemented in a chip of the above apparatus, or may be stored in a memory of the above apparatus in the form of program code, and the functions of the above acquisition module may be called and executed by a processing element of the above apparatus. The implementation of the other modules is similar. In addition, all or part of the modules can be integrated together or can be independently implemented.
The embodiment of the application also provides a message processing device, which comprises: at least one processor, a memory, a bus, and a communication interface. The message processing device may be, for example, a message production center as described above.
Wherein: the processor, communication interface and memory communicate with each other via the bus. And the communication interface is used for communicating with other devices. The communication interface includes a communication interface for data transmission. The processor is configured to execute the computer instructions stored in the memory, and may specifically perform the relevant steps performed by the message production center in the foregoing embodiment.
The processor may be a central processor. The one or more processors included in the electronic device may be the same type of processor, such as one or more CPUs; but may also be different types of processors such as one or more CPUs and one or more ASICs.
And the memory is used for storing computer instructions. The memory may comprise high speed RAM memory or may also comprise non-volatile memory, such as at least one disk memory.
The embodiment of the application also provides a message processing device, which comprises: at least one processor, a memory, a bus, and a communication interface. The message processing device may be, for example, a message distribution processor as described above.
Wherein: the processor, communication interface and memory communicate with each other via the bus. And the communication interface is used for communicating with other devices. The communication interface includes a communication interface for data transmission. A processor for executing the computer instructions stored in the memory, and in particular for executing the relevant steps executed by the message distribution processor in the above embodiments.
The processor may be a central processor. The one or more processors included in the electronic device may be the same type of processor, such as one or more CPUs; but may also be different types of processors such as one or more CPUs and one or more ASICs.
And the memory is used for storing computer instructions. The memory may comprise high speed RAM memory or may also comprise non-volatile memory, such as at least one disk memory.
The present embodiment also provides a readable storage medium having stored therein computer instructions which, when executed by at least one processor of an electronic device, perform the message processing methods provided in the various embodiments described above.
The present embodiment also provides a program product comprising computer instructions stored in a readable storage medium. The computer instructions may be read from a readable storage medium by at least one processor of an electronic device, and executed by the at least one processor, cause the electronic device to implement the message processing methods provided by the various embodiments described above.
In the present application, "at least one" means one or more, and "a plurality" means two or more. "and/or", describes an association relationship of an association object, and indicates that there may be three relationships, for example, a and/or B, and may indicate: a alone, a and B together, and B alone, wherein a, B may be singular or plural. The character "/" generally indicates that the front and rear associated objects are an "or" relationship; in the formula, the character "/" indicates that the front and rear associated objects are a "division" relationship. "at least one of" or the like means any combination of these items, including any combination of single item(s) or plural items(s). For example, at least one (one) of a, b, or c may represent: a, b, c, a-b, a-c, b-c, or a-b-c, wherein a, b, c may be single or plural.
It will be appreciated that the various numerical numbers referred to in the embodiments of the present application are merely for ease of description and are not intended to limit the scope of the embodiments of the present application. In the embodiment of the present application, the sequence number of each process does not mean the sequence of the execution sequence, and the execution sequence of each process should be determined by the function and the internal logic, and should not limit the implementation process of the embodiment of the present application in any way.
Finally, it should be noted that: the above embodiments are only for illustrating the technical solution of the present application, and not for limiting the same; although the application has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical scheme described in the foregoing embodiments can be modified or some or all of the technical features thereof can be replaced by equivalents; such modifications and substitutions do not depart from the spirit of the application.
Claims (14)
1. A message processing method for use in a message production center in a micro-service system, the method comprising:
obtaining a message, wherein the message at least comprises message content, a routing field for indicating the type of the message and event information for indicating a message consumer;
determining a target queue in a preset message queue according to the routing field;
writing the message to the target queue to push the message to a message distribution processor listening to the target queue, the message distribution processor for sending the message content to the message consumer.
2. The method of claim 1, wherein determining a target queue from among a predetermined message queue based on the routing field comprises:
detecting whether the routing field contains a preset identifier or not;
if the routing field does not contain the preset identification, searching a queue matched with the routing field in the preset message queue as the target queue.
3. The method according to claim 2, wherein determining a target queue from the predetermined message queue according to the routing field comprises:
if the routing field contains a preset identifier, acquiring the position of the preset identifier in the routing field;
dividing the routing field into at least two subfields according to the position of the preset identifier in the routing field;
and searching a queue matched with each subfield in the preset message queue to serve as the target queue.
4. The method according to claim 1, wherein the method further comprises:
responding to a new adding request of the message type, and acquiring a new adding field, wherein the new adding field is used for identifying the newly added message type;
And adding the newly added field into the routing field, wherein the newly added field and the routing field are separated by a preset identifier.
5. The method according to claim 4, wherein the method further comprises:
determining a new added queue matched with the new added field in the preset message queue according to the new added field;
and adding a newly added message distribution processor, wherein the newly added message distribution processor is used for monitoring the newly added queue to acquire the message written into the newly added queue.
6. The method of claim 1, wherein the microservice system further comprises a preset application programming interface through which the message production center is connected to at least two message producers, the obtaining a message comprising:
and receiving the message messages pushed by each message producer through the preset application programming interface.
7. The method according to claim 1, wherein the method further comprises:
receiving a push state fed back by the message distribution processor, wherein the push state is used for indicating whether the message distribution processor pushes the message content to the message consumer;
And updating the state of the message according to the push state.
8. A message processing method for use in a message distribution processor in a micro server system, the method comprising:
when a target queue in a preset message queue is monitored to write a message, acquiring the message, wherein the message at least comprises message content, a routing field for indicating the type of the message and event information for indicating a message consumer;
inquiring from a message subscription registry to obtain the message consumer according to the event information, wherein the message subscription registry comprises registration information of at least one message consumer;
pushing the message content to the message consumer.
9. A message processing apparatus, comprising:
the message acquisition module is used for acquiring a message, wherein the message at least comprises message content, a routing field for indicating the type of the message and event information for indicating a message consumer;
the queue determining module is used for determining a target queue in a preset message queue according to the routing field;
and the message writing module is used for writing the message into the target queue so as to push the message to a message distribution processor for monitoring the message queue, and the message distribution processor is used for sending the message content to the message consumer.
10. A message processing apparatus, comprising:
the acquisition module is used for acquiring the message when the message is written in a target queue in the preset message queue, wherein the message at least comprises message content, a routing field for indicating the message type and event information for indicating a message consumer;
the inquiring module is used for inquiring from a message subscription registry to obtain the message consumer according to the event information, wherein the message subscription registry comprises registration information of at least one message consumer;
and the pushing module is used for pushing the message content to the message consumer.
11. A message processing apparatus, comprising: a memory, a processor, and a communication interface for communicating with other devices;
the memory stores computer-executable instructions;
the processor executing computer-executable instructions stored in the memory to cause a message processing apparatus to perform the method of any one of claims 1-7.
12. A message processing apparatus, comprising: a memory, a processor, and a communication interface for communicating with other devices;
The memory stores computer-executable instructions;
the processor executing computer-executable instructions stored in the memory causes the message processing device to perform the method of claim 8.
13. A micro-service system, comprising: a message production center in data communication with at least one message producer, and at least one message distribution processor in communication with at least one message consumer, each message distribution processor listening to a message queue;
the message production center is used for receiving the message of each message producer and writing the message into a message queue matched with the routing field according to the routing field in the message;
the message distribution processor is used for acquiring message messages in the monitored message queue, inquiring from the message subscription registration center according to event information in the message messages to obtain target message consumers, and pushing message contents in the message messages to the target message consumers.
14. A readable storage medium having stored therein computer instructions which, when executed by a processor, are adapted to carry out the method of any one of claims 1-8.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210379656.3A CN116954934A (en) | 2022-04-12 | 2022-04-12 | Message processing method, device, equipment, system and readable storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210379656.3A CN116954934A (en) | 2022-04-12 | 2022-04-12 | Message processing method, device, equipment, system and readable storage medium |
Publications (1)
Publication Number | Publication Date |
---|---|
CN116954934A true CN116954934A (en) | 2023-10-27 |
Family
ID=88455145
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202210379656.3A Pending CN116954934A (en) | 2022-04-12 | 2022-04-12 | Message processing method, device, equipment, system and readable storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN116954934A (en) |
-
2022
- 2022-04-12 CN CN202210379656.3A patent/CN116954934A/en active Pending
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US9985917B2 (en) | Managing notification messages | |
CN108196961B (en) | Asynchronous message processing method, terminal, system and storage medium | |
CN112527525B (en) | Distributed event bus processing method, terminal and medium based on message queue | |
US7801941B2 (en) | Apparatus and method for exchanging data between two devices | |
US8028085B2 (en) | Optimizing message transmission and delivery in a publisher-subscriber model | |
US6816881B1 (en) | Method and apparatus for inter-application communication in wireless networks | |
CN109995801B (en) | Message transmission method and device | |
US20090144357A1 (en) | Use of template messages to optimize a software messaging system | |
US20150256504A1 (en) | Distributed synchronization data in a message management service | |
US20140115081A1 (en) | Method, apparatus and system for sharing a microblog message | |
CN110753129A (en) | Message transmission method, system, device, equipment and computer readable storage medium | |
CN111917843A (en) | Message pushing method, computer equipment and storage medium | |
US11171899B2 (en) | System for delivering notification messages across different notification media | |
JP7503152B2 (en) | Mail processing method, device, equipment and medium | |
CN115022318B (en) | Message publishing method and system based on micro-service architecture | |
CN112291325A (en) | Message processing method and device and computer system | |
CN116954934A (en) | Message processing method, device, equipment, system and readable storage medium | |
US20150074208A1 (en) | Exposed group of recipients for text message | |
US11924271B2 (en) | Preventing duplicative file processing | |
US20230336509A1 (en) | Efficiently handling retained messages in a system with bridged message brokers | |
CN114449031B (en) | Information acquisition method, device, equipment and storage medium | |
CN112492019B (en) | Message pushing method and device, electronic equipment and storage medium | |
CN115480934A (en) | Distributed data processing method, device, equipment and storage medium | |
CN114500417A (en) | Communication message transmission method, message processing hardware and storage medium | |
CN113868687A (en) | Task processing progress management 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 |