In-cluster message notification method, receiving method and device
The message notification service list is generated by the registration center, and messages are broadcasted directly between micro servers, solving the high maintenance cost problem caused by the message notification dependence on middleware in the micro service environment, and achieving efficient and reliable message notification.
Patent Information
- Application Number
- CN202210224854.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-09
- Publication Date
- 2024-12-24
- Estimated Expiration
- 2042-03-09
AI Technical Summary
In a microservice environment, message notification in the cluster depends on each message middleware, resulting in high maintenance and access costs.
The message notification service list is generated by the registration center. Each micro server broadcasts messages to other micro servers according to the list, realizes message notification, and ensures the reliability of message delivery through timed updates and retry mechanisms.
Reliance on message middleware is reduced, maintenance and access costs are reduced, and the reliability and efficiency of message notifications are improved.
Smart Images

Figure CN114615284B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the technical field of cloud computing, and in particular to a cluster message notification method, a receiving method and a device. Background Art
[0002] In the current microservice environment, message notifications within a cluster rely on various message middleware, such as message queues, or can be implemented with the help of specific mechanisms, or message synchronization is performed through scheduled data synchronization. However, the existing technology has at least the following problems: when functions such as message cluster management and high availability need to be implemented in a microservice environment, for the access of lightweight message notifications, message notifications within a cluster rely on various message middleware, which has high maintenance and access costs. Summary of the invention
[0003] In view of the problems existing in the prior art, the embodiments of the present disclosure provide a cluster message notification method, a receiving method and a device.
[0004] In a first aspect, the present disclosure provides a method for message notification within a cluster, comprising: each microserver broadcasts a message to at least one microserver included in the message service notification list according to a message notification service list obtained from a registration center; wherein the message notification service list is generated by the registration center according to each of the microservers and their corresponding address information.
[0005] According to a cluster message notification method provided by the present disclosure, the method also includes: updating the current message notification service list in each micro server according to the message notification service list regularly pushed by the registration center; and / or each micro server regularly visits the registration center to re-acquire the updated message notification service list.
[0006] According to a method for in-cluster message notification provided by the present disclosure, the message includes a message subject and a message body carrying message content; the message subject is used by a microserver receiving the message to filter multiple monitored messages based on locally preset focus topics.
[0007] According to a cluster message notification method provided by the present disclosure, the message also includes a message ID; before broadcasting the message to at least one microserver included in the message service notification list, it also includes: judging whether the current message has been sent according to the message ID of the current message, and ending the sending of the current message if it has been sent.
[0008] According to a cluster message notification method provided by the present disclosure, when the current message is not sent, before broadcasting the message to at least one microserver included in the message service notification list, it also includes: confirming that the microserver sending the current message has registered for the message notification service with the registration center.
[0009] According to a cluster message notification method provided by the present disclosure, after broadcasting a message to at least one microserver included in the message service notification list, it also includes: obtaining the message sending result; after confirming that the sending result is a failure, starting the synchronous retry sending of the message; or, storing the failed message in an abnormal message sending queue, and taking out the failed message from the abnormal message sending queue according to a preset time interval, and asynchronously starting the broadcast retry sending again.
[0010] In a second aspect, the present disclosure provides a method for receiving messages within a cluster, comprising: each microserver monitors a message broadcasted by at least one microserver included in the message service notification list according to a message notification service list obtained from a registration center; wherein,
[0011] The message notification service list is generated by the registration center according to each of the micro servers and their corresponding address information.
[0012] According to a method for receiving messages within a cluster provided by the present disclosure, the message includes a message subject and a message body for carrying message content; the method also includes matching the message subject of the message acquired through monitoring according to a locally preset focus topic, and acquiring the message body of the message under the focus topic.
[0013] According to a method for receiving messages within a cluster provided by the present disclosure, the message also includes a message ID; after obtaining the message body of the message under the concerned topic, the method also includes recording the message ID associated with the message body.
[0014] According to a method for receiving messages within a cluster provided by the present disclosure, after obtaining the message body of the message under the topic of interest, it also includes: processing the message according to the content of the message body; if it is determined that the message processing is unsuccessful, storing the message in an abnormal message processing queue, and periodically taking it out from the abnormal message processing queue and performing the message processing operation again.
[0015] In a third aspect, the present disclosure also provides an intra-cluster message notification device, which is applied to a cluster including a registration center and multiple microservers, and the device includes a broadcast module, wherein the broadcast module is used for each of the microservers to broadcast a message to at least one microserver included in the message service notification list according to the message notification service list obtained from the registration center; wherein the message notification service list is generated by the registration center according to each of the microservers and their corresponding address information.
[0016] In a fourth aspect, the present disclosure also provides a device for receiving messages within a cluster, which is applied to a cluster including a registration center and multiple microservers. The device includes a monitoring module, wherein the monitoring module is used for each of the microservers to monitor the messages broadcast by at least one microserver included in the message service notification list according to the message notification service list obtained from the registration center; wherein the message notification service list is generated by the registration center according to each of the microservers and their corresponding address information.
[0017] In a fifth aspect, the present disclosure further provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of any of the above-mentioned intra-cluster message notification methods are implemented.
[0018] In a sixth aspect, the present disclosure further provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of any of the above-mentioned methods for receiving messages within a cluster are implemented.
[0019] In a seventh aspect, the present disclosure further provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of any of the above-described intra-cluster message notification methods.
[0020] In an eighth aspect, the present disclosure further provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of any of the above-described methods for receiving messages within a cluster.
[0021] In a ninth aspect, the present disclosure further provides a computer program product, including a computer program, which, when executed by a processor, implements the steps of any of the above-mentioned intra-cluster message notification methods.
[0022] In a tenth aspect, the present disclosure further provides a computer program product, including a computer program, which, when executed by a processor, implements the steps of any of the above-mentioned methods for receiving messages within a cluster.
[0023] The present disclosure provides a method and device for in-cluster message notification, reception and transmission, in which each microserver broadcasts a message to at least one microserver included in the message service notification list according to a message notification service list obtained from a registration center; wherein the message notification service list is generated by the registration center according to each of the microservers and their corresponding address information. The microserver can directly broadcast a message to at least one microserver included in the message service notification list according to the message notification service list, without relying on various message middleware or using special mechanisms to implement message notification, and without having to synchronize messages through timed data synchronization, thereby reducing maintenance costs and access costs. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] In order to more clearly illustrate the technical solutions in the present disclosure or the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present disclosure. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0025] Figure 1 It is a system architecture diagram of the method for notification, reception and transmission of messages within a cluster provided by the present disclosure;
[0026] Figure 2 It is a flowchart of the method for in-cluster message notification provided by the present disclosure;
[0027] Figure 3a This is a flowchart of the steps for obtaining a message notification service list in the intra-cluster message notification method provided by the present disclosure;
[0028] Figure 3b It is a flowchart of a specific embodiment of the intra-cluster message notification method provided by the present disclosure;
[0029] Figure 4 It is a structural diagram of the intra-cluster message notification device provided by the present disclosure;
[0030] Figure 5a It is a flowchart of a method for receiving messages within a cluster provided by the present disclosure;
[0031] Figure 5b It is a flowchart of a specific embodiment of the intra-cluster message notification method provided by the present disclosure;
[0032] Figure 6 It is a structural diagram of a device for receiving messages within a cluster provided by the present disclosure;
[0033] Figure 7 It is a schematic diagram of the structure of an electronic device provided by the present disclosure. DETAILED DESCRIPTION
[0034] In order to make the purpose, technical solution and advantages of the embodiments of the present disclosure clearer, the technical solution in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are part of the embodiments of the present disclosure, rather than all of the embodiments. Based on the embodiments in the embodiments of the present disclosure, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the embodiments of the present disclosure.
[0035] Microservices are small services that consist of a single application. Each microservice has its own process, which can communicate with other microservices through lightweight communication mechanisms, such as application programming interfaces based on the Hypertext Transfer Protocol.
[0036] Microservice architecture is an architecture that splits applications (especially large applications, such as e-commerce systems) into several microservices. For example, classic architectures such as Spring Cloud and Dubbo are less invasive. Compared with the traditional monolithic architecture that concentrates all functional services in one container, the microservice architecture achieves business decoupling by decomposing functions into discrete services. Each business team maintains the microservices corresponding to their respective businesses, which reduces maintenance complexity and improves maintenance efficiency. Moreover, when a single microservice fails, other microservices can continue to work, which improves system stability.
[0037] In the current microservice architecture, cluster message notifications within the cluster rely on various message middleware, such as:
[0038] (1) Implement message notification through MQ message queue and Redis message queue;
[0039] (2) Use a watcher mechanism similar to Zookeeper to implement message notification;
[0040] (3) Message synchronization is performed through scheduled data synchronization.
[0041] Although the above solutions all implement the message notification function within the cluster, the introduction of message queues increases the complexity of the entire microservice architecture system. For example, the message queue that needs to be introduced must have high availability and be able to provide ready-made support, rather than manually implementing it by writing code; it is necessary to consider the data storage method in the message queue, such as the storage location (disk or database, etc.), synchronous storage or asynchronous storage; how each microservice obtains data in the message queue, how to avoid repeated consumption of messages, and how to ensure that the messages are absolutely ordered.
[0042] That is to say, due to the introduction of various message middleware, the cooperation of functions such as message cluster management is required, which has high access cost and maintenance cost for message access (especially lightweight message access).
[0043] Reference Figure 1 , is a system architecture diagram of the method for notifying, receiving and transmitting messages within a cluster disclosed in the present invention. Figure 1 The system architecture shown includes a registration center 12 and a plurality of micro servers 14 .
[0044] In actual application, the microserver 14 is usually a computing device, such as a server, a personal computer, or other terminals, which can be a physical machine or a virtual machine after virtualization. Each microserver 14 includes one or more processors, memories, and communication interfaces, and each component is connected through a bus. Different microservices are deployed on each microserver 14 to implement different functions. Of course, the microserver 14 can also implement a microservice function with the help of a cluster formed by multiple computing devices.
[0045] The registration center 12 is also a computing device, which can be a physical computer or a service cluster composed of multiple servers. The registration center 12 can be a virtual cluster server that occupies only a part of a computer or a part or all of multiple computers. In the present disclosure, the registration center 12 records the mapping relationship between microservers and service addresses. A microservice 14 as a message producer can broadcast message notifications to other microservices through the above mapping relationship obtained from the registration center 12. Correspondingly, other microservers 14 as message consumers can also monitor message notifications through the above mapping relationship obtained from the registration center.
[0046] The present disclosure provides a method for notifying a message within a cluster. The method is described from the perspective of a microserver as a message producer, and specifically includes:
[0047] Each micro server broadcasts a message to at least one micro server included in the message service notification list according to the message notification service list obtained from the registration center; wherein the message notification service list is generated by the registration center according to each micro server and its corresponding address information.
[0048] Reference Figure 2 , the above method can be performed by the following steps:
[0049] Step S201: Obtain a message notification service list from a registration center.
[0050] In this step, the message notification service list includes all micro servers and their corresponding addresses that have been registered in the registration center when the micro server is acquired.
[0051] Step S203: broadcast a message to at least one micro server included in the message service notification list according to the message notification service list.
[0052] Specifically, broadcast refers to a microserver sending a message to one or more microservers. In a specific implementation, the message may be sent to all microservers on the message notification service list in the cluster except itself.
[0053] The cluster message notification method provided by the embodiment of the present disclosure broadcasts a message to at least one microserver included in the message service notification list according to the message notification service list obtained from the registration center by each microserver; wherein the message notification service list is generated by the registration center according to each microserver and its corresponding address information. The microserver can directly broadcast the message to at least one microserver included in the message service notification list according to the message notification service list, without relying on various message middleware such as MQ messages, Redis message queues, or watcher mechanisms similar to Zookeeper to implement message notifications, and without having to synchronize messages through scheduled data synchronization, thereby reducing maintenance costs and access costs.
[0054] In a preferred embodiment, referring to Figure 3a , the message notification service list can be obtained by following the steps below:
[0055] Step S2011, initializing the message notification service;
[0056] Step S2013, obtaining the address of the registration center;
[0057] Step S2015: Register the message notification service with the registration center based on the address of the registration center.
[0058] It is well known to those skilled in the art that, during registration, it is also necessary to obtain the message sending protocol pre-stored by the registration center, or the message sending configuration information.
[0059] In a preferred embodiment, the registration message notification service in step S2015 specifically includes:
[0060] Step S20151, sending the address of the current micro server;
[0061] Step S20153: Obtain a message notification service list formed by the registration center based on the address provided by each microservice in the cluster.
[0062] In a specific implementation, taking the i-th microserver registering the message notification service with the registration center as an example, it is explained how the i-th microserver registers the message notification service. First, before the i-th microserver registers the message notification service, it can be understood that i-1 microservers have already registered the message notification service with the registration center. The i-th microserver obtains the address of the registration center and sends its corresponding address, that is, the address corresponding to the i-th microserver, to the registration center based on the address of the registration center. After receiving the address corresponding to the i-th microserver, the registration center forms a message notification service list based on the address corresponding to the i-th microserver and the address corresponding to the i-1 microservers received previously. At this time, the message notification service list may include i microserver numbers and the address corresponding to each microserver in a specific implementation. The registration center sends the message notification service list to the i-th microserver based on the address corresponding to the i-th microserver sent by the i-th microserver. At the same time, it is known to those skilled in the art that when registering, it is also necessary to obtain the message sending protocol pre-stored by the registration center, or the message sending configuration information, to support communication between each microserver.
[0063] In an optional embodiment, the intra-cluster message notification method further includes:
[0064] The current message notification service list in each micro server is updated regularly.
[0065] Specifically, since the microserver broadcasts messages according to the microservers included in the message notification service list, if the microserver that has previously obtained the message notification service list does not update the message notification service list for a long time, the newly added microserver that has been registered with the registration center does not exist in the message notification service list obtained by the microserver, and information cannot be sent and received between the two microservers. Or when the microserver no longer processes the corresponding microservice or the microserver fails, sending messages to the microserver or receiving messages sent by the microserver will cause a waste of resources. Therefore, it is necessary to periodically update the current message notification service list in each microserver in the cluster registered with the registration center.
[0066] In a preferred embodiment, the current message notification service list in each micro server is updated regularly, which can be:
[0067] The current message notification service list in each micro server is updated according to the message notification service list regularly pushed by the registration center.
[0068] Specifically, the registration center can periodically push the latest message notification service list to each microserver according to the corresponding address of each microserver in the latest message notification service list to ensure that each microserver in the message notification service list can broadcast to at least one microserver in the message notification service list.
[0069] In a preferred embodiment, the current message notification service list in each micro server is updated periodically, and each micro server periodically accesses the registration center to re-acquire the updated message notification service list.
[0070] Specifically, after the micro server obtains the message notification service list, the micro server can be set to periodically access the registration center to re-acquire the updated message notification service list, such as accessing the registration center once every 5 minutes to obtain the updated message notification service list.
[0071] In a specific embodiment, the above two methods can also be used simultaneously to periodically update the current message notification service list in each microserver, so as to update the current message notification service list in each microserver more timely, that is, the periodic update of the current message notification service list in each microserver includes updating the current message notification service list in each microserver according to the message notification service list regularly pushed by the registration center, and also includes each microserver periodically accessing the registration center to re-acquire the updated message notification service list.
[0072] In one embodiment, the message includes a message subject and a message body that carries the message content; the message subject is used by the micro server receiving the message to filter the monitored multiple messages based on the locally preset focus topics.
[0073] The micro server receiving the message filters the multiple messages monitored based on the local preset focus topics to ensure that the information of the local preset focus topics is processed, while the information of the non-local preset focus topics monitored by it is not processed.
[0074] In addition to the message subject and the message body that carries the message content, the message also includes a message ID. Since the message ID is unique, it is easy to know whether the message to be broadcast has been sent. Figure 3b In a specific embodiment, this can be achieved through the following steps:
[0075] Step S3011, message content initialization, setting message ID, message subject and message content.
[0076] Step S3012: Determine whether the current message has been sent based on the message ID of the current message.
[0077] Specifically, if the current message has not been sent, then if it has been sent, the sending of the current message is terminated. If the current message has not been sent, step S3013 is executed.
[0078] Step S3013: confirm that the micro server that sends the current message has registered for the message notification service with the registration center.
[0079] Specifically, if the microserver that sends the current message has not registered for the message notification service with the registration center, the microserver first registers for the message notification service with the registration center before sending the message.
[0080] Step S3014: broadcast a message to at least one micro server included in the message service notification list according to the message notification service list obtained from the registration center.
[0081] Step S3015: Get the message sending result.
[0082] Specifically, there are two message sending results, one is message sending success, and the other is message sending failure. If the message sending result is message sending success, the sending of the current message is terminated.
[0083] Step S3016: After confirming that the sending result is a failure, start message sending retry.
[0084] The message sending retry can be synchronous retry sending; or, it can be storing the failed message in the abnormal message sending queue, taking out the failed message from the abnormal message sending queue according to a preset time interval, and asynchronously starting broadcast retry sending again. Or the above two methods can be used together to achieve it.
[0085] Specifically, the meaning of synchronization is that the sending result is confirmed to be a failure, and resending is started immediately. Correspondingly, the meaning of asynchronous is that the message that confirms that the sending result is a failure is first stored in the abnormal message sending queue, and the message that sends the error is started to be resent according to the preset time. In the specific implementation, the synchronous retry sending of the message can also be started first. In the case of the synchronous retry sending failure, the failed message is stored in the abnormal message sending queue, and the failed message is taken out from the abnormal message sending queue according to the preset time interval, and the broadcast retry sending is started again asynchronously. In this way, if only a short message cannot be sent, the synchronous retry sending is better in real time. If the message cannot be sent for a long time during the implementation, the continuous synchronous retry sending is futile. The failed message can be stored in the abnormal message sending queue, and the failed message is taken out from the abnormal message sending queue according to the preset time interval, and the broadcast retry sending is started again asynchronously. In this way, the combined application is more reasonable for resource application while ensuring that each message can be sent.
[0086] The following describes an intra-cluster message notification device provided by an embodiment of the present disclosure. The intra-cluster message notification device described below and the intra-cluster message notification method described above can refer to each other.
[0087] Reference Figure 4 The embodiment of the present disclosure provides a message notification device within a cluster, which is arranged in a microserver of a message sender, that is, a message producer, and includes a broadcast module 40, wherein the broadcast module 40 is used for each microserver to broadcast a message to at least one microserver included in a message service notification list according to a message notification service list obtained from a registration center; wherein the message notification service list is generated by the registration center according to each microserver and its corresponding address information.
[0088] Specifically, the message notification service list includes all micro servers and their corresponding addresses that have been registered in the registration center when the micro server is acquired.
[0089] In the cluster message notification device provided by the embodiment of the present disclosure, the broadcast module 40 broadcasts the message to at least one microserver included in the message service notification list through each microserver according to the message notification service list obtained from the registration center; wherein the message notification service list is generated by the registration center according to each microserver and its corresponding address information. The microserver can directly broadcast the message to at least one microserver included in the message service notification list according to the message notification service list, without relying on various message middleware such as MQ messages, Redis message queues, or watcher mechanisms similar to Zookeeper to implement message notifications, and without having to synchronize messages through scheduled data synchronization, thereby reducing maintenance costs and access costs.
[0090] In a preferred embodiment, the message notification service list can be obtained by: initializing the message notification service, obtaining the address of the registration center, and registering the message notification service with the registration center based on the address of the registration center. It is known to those skilled in the art that when registering, it is also necessary to obtain the message sending protocol pre-stored by the registration center, or the message sending configuration information.
[0091] In a preferred embodiment, registering for a message notification service specifically includes: sending the address of the current micro-server, and obtaining a message notification service list formed by a registration center based on the address provided by each micro-service in the cluster.
[0092] In an optional embodiment, the intra-cluster message notification device further includes:
[0093] The updating module 42 is used to periodically update the current message notification service list in each micro server.
[0094] Specifically, since the microserver broadcasts messages according to the microservers included in the message notification service list, if the microserver that has previously obtained the message notification service list does not update the message notification service list for a long time, the newly added microserver that has been registered with the registration center does not exist in the message notification service list obtained by the microserver, and information cannot be sent and received between the two microservers. Or when the microserver no longer processes the corresponding microservice or the microserver fails, sending messages to the microserver or receiving messages sent by the microserver will cause a waste of resources. Therefore, it is necessary to periodically update the current message notification service list in each microserver in the cluster registered with the registration center.
[0095] In a preferred embodiment, the updating module 42 is used to regularly update the current message notification service list in each micro server. The regular update may be used to update the current message notification service list in each micro server according to the message notification service list regularly pushed by the registration center.
[0096] Specifically, the registration center can periodically push the latest message notification service list to each microserver according to the corresponding address of each microserver in the latest message notification service list to ensure that each microserver in the message notification service list can broadcast to at least one microserver in the message notification service list.
[0097] In a preferred embodiment, the updating module 42 is used to periodically update the current message notification service list in each micro server, and each micro server periodically accesses the registration center to re-acquire the updated message notification service list.
[0098] Specifically, after the micro server obtains the message notification service list, the micro server can be set to periodically access the registration center to re-acquire the updated message notification service list, such as accessing the registration center once every 5 minutes to obtain the updated message notification service list.
[0099] In a specific embodiment, the above two methods can also be used simultaneously to periodically update the current message notification service list in each microserver, so as to update the current message notification service list in each microserver more timely, that is, the periodic update of the current message notification service list in each microserver includes updating the current message notification service list in each microserver according to the message notification service list regularly pushed by the registration center, and also includes each microserver periodically accessing the registration center to re-acquire the updated message notification service list.
[0100] In one embodiment, the message includes a message subject and a message body that carries the message content; the message subject is used by the micro server receiving the message to filter the monitored multiple messages based on the locally preset focus topics.
[0101] The micro server receiving the message filters the monitored multiple messages based on the locally preset topics of interest to ensure that the information of the locally preset topics of interest is processed while the monitored information of non-locally preset topics of interest is not processed.
[0102] In addition to the message subject and the message body carrying the message content, the message also includes a message ID. Since the message ID is unique, it is convenient to know whether the message to be broadcasted has been sent. In a specific embodiment, the broadcast module 40 specifically includes:
[0103] The judging unit 401 is used to judge whether the current message has been sent according to the message ID of the current message.
[0104] Specifically, if the current message has not been sent, then if it has been sent, the sending of the current message is terminated. If the current message has not been sent, the confirmation unit 403 is executed.
[0105] The confirmation unit 403 is used to confirm that the micro server sending the current message has registered for the message notification service with the registration center.
[0106] Specifically, if the microserver that sends the current message has not registered for the message notification service with the registration center, the microserver first registers for the message notification service with the registration center before sending the message.
[0107] The broadcast unit 405 is configured to broadcast a message to at least one micro server included in the message service notification list according to the message notification service list obtained from the registration center.
[0108] The acquisition unit 407 is used to acquire the message sending result.
[0109] Specifically, there are two message sending results, one is message sending success, and the other is message sending failure. If the message sending result is message sending success, the sending of the current message is terminated.
[0110] The resending unit 409 is used to start message sending retry after confirming that the sending result is a failure.
[0111] The message sending retry can be synchronous retry sending; or, it can be storing the failed message in the abnormal message sending queue, taking out the failed message from the abnormal message sending queue according to a preset time interval, and asynchronously starting broadcast retry sending again. Or the above two methods can be used together to achieve it.
[0112] Specifically, the meaning of synchronization is that the sending result is confirmed to be a failure, and resending is started immediately. Correspondingly, the meaning of asynchronous is that the message that confirms that the sending result is a failure is first stored in the abnormal message sending queue, and the message that sends the error is started to be resent according to the preset time. In the specific implementation, the synchronous retry sending of the message can also be started first. In the case of the synchronous retry sending failure, the failed message is stored in the abnormal message sending queue, and the failed message is taken out from the abnormal message sending queue according to the preset time interval, and the broadcast retry sending is started again asynchronously. In this way, if only a short message cannot be sent, the synchronous retry sending is better in real time. If the message cannot be sent for a long time during the implementation, the continuous synchronous retry sending is futile. The failed message can be stored in the abnormal message sending queue, and the failed message is taken out from the abnormal message sending queue according to the preset time interval, and the broadcast retry sending is started again asynchronously. In this way, the combined application is more reasonable for resource application while ensuring that each message can be sent.
[0113] The embodiment of the present disclosure also provides a method for receiving messages within a cluster. The embodiment describes the method for receiving messages within a cluster from the perspective of a microserver as a message receiver. Specifically, the method includes:
[0114] Each micro server monitors the messages broadcasted by at least one micro server included in the message service notification list according to the message notification service list obtained from the registration center; wherein the message notification service list is generated by the registration center according to each micro server and its corresponding address information.
[0115] Reference Figure 5a , the method can be performed by the following steps:
[0116] Step S501: Obtain a message notification service list from a registration center.
[0117] The message notification service list in this step includes all micro servers and their corresponding addresses that have been registered in the registration center when the micro server is acquired.
[0118] Step S503: According to the message notification service list, monitor the message broadcasted by at least one micro server included in the message service notification list.
[0119] The monitoring in this step means always paying attention to whether there are broadcast messages from micro-servers other than itself in the message notification service list.
[0120] The method for receiving messages within a cluster provided by the embodiment of the present disclosure uses a microserver as an information receiving end as an execution subject, and each microserver monitors the messages broadcast by at least one microserver included in the message service notification list according to the message notification service list obtained from the registration center; wherein the message notification service list is generated by the registration center according to each microserver and its corresponding address information. The microserver can implement message notification by monitoring the messages broadcast by at least one microserver included in the message service notification list, without relying on various message middleware such as MQ messages, Redis message queues, or watcher mechanisms similar to Zookeeper, and without having to synchronize messages through scheduled data synchronization, thereby reducing maintenance costs and access costs.
[0121] In an optional embodiment, the message includes a message subject and a message body for carrying message content; and the intra-cluster message receiving method further includes:
[0122] According to the local preset concerned topic, the message subject of the message acquired by monitoring is matched, and the message body of the message under the concerned topic is acquired.
[0123] Specifically, when the message only includes a message subject and a message body for carrying the message content, matching the message subjects of the messages obtained by monitoring according to the local preset focus topic can filter out the messages corresponding to the local preset focus topic from the messages obtained by monitoring, that is, the messages that the micro server needs to process.
[0124] Furthermore, in addition to the message subject and the message body carrying the message content, the message also includes a message ID. After obtaining the message body of the message under the concerned topic, the method for receiving messages within the cluster also includes:
[0125] Record the message ID associated with the message body.
[0126] Specifically, when the message includes a message subject, a message ID and a message body for carrying the message content, the message ID is used to identify whether a duplicate message is sent. After determining that the message has not been obtained except this time, the message subject of the message obtained by monitoring is matched according to the local preset focus topic. The messages obtained by monitoring can be filtered out to find the messages corresponding to the local preset focus topic, that is, the messages that the microserver needs to process.
[0127] Further, refer to Figure 5b In a preferred embodiment, the method for receiving messages within a cluster specifically includes:
[0128] Step S511: Initialize the message notification service.
[0129] Step S513: Based on the acquired registration center address, register the message notification service with the registration center to obtain a message notification service list.
[0130] The message notification service list in this step includes all micro servers and their corresponding addresses that have been registered in the registration center when the micro server is acquired.
[0131] Step S515: Match the message subject of the message obtained by monitoring the message notification service list according to the local preset focus topic, obtain the message body of the message under the focus topic, and record the message ID associated with the message body.
[0132] The message ID in this step is used to identify whether there is a duplicate message sent. After determining that the message has not been obtained except this time, the message subject of the message obtained by monitoring is matched according to the local preset focus topic. The messages corresponding to the local preset focus topic can be filtered out from the messages obtained by monitoring, that is, the messages that the micro server needs to process.
[0133] Step S517: Process the message according to the content of the message body.
[0134] The processing in this step refers to obtaining the message content carried by the message body based on the message body.
[0135] Step S519: If it is determined that the message processing is unsuccessful, the message is stored in the abnormal message processing queue, and is taken out from the abnormal message processing queue at a regular interval and the message processing operation is performed again.
[0136] Specifically, if the message processing is unsuccessful, the message content carried by the message body cannot be obtained. Regularly taking out the message from the abnormal message processing queue and executing the message processing operation again ensures that the message to be processed will not be discarded or not processed due to processing failure. The following describes the intra-cluster message receiving device provided by the embodiment of the present disclosure. The intra-cluster message receiving device described below and the intra-cluster message receiving method described above can be referred to each other.
[0137] Reference Figure 6 The embodiment of the present disclosure also provides a message receiving device within a cluster, which is arranged in a micro server of a message receiver, and includes a monitoring module 60, wherein the monitoring module 60 is used for each micro server to monitor the message broadcasted by at least one micro server included in the message service notification list according to the message notification service list obtained from the registration center; wherein the message notification service list is generated by the registration center according to each micro server and its corresponding address information.
[0138] Specifically, monitoring means always paying attention to whether there are broadcast messages from microservers other than itself in the message notification service list.
[0139] In the cluster message receiving device provided by the embodiment of the present disclosure, the monitoring module 60 monitors the messages broadcast by at least one microserver included in the message service notification list according to the message notification service list obtained from the registration center by each microserver; wherein the message notification service list is generated by the registration center according to each microserver and its corresponding address information. The microserver can implement message notification by monitoring the messages broadcast by at least one microserver included in the message service notification list without relying on various message middleware such as MQ messages, Redis message queues, or watcher mechanisms similar to Zookeeper, and does not need to synchronize messages through scheduled data synchronization, thereby reducing maintenance costs and access costs.
[0140] In an optional embodiment, the message includes a message subject and a message body for carrying message content; the intra-cluster message receiving device further includes:
[0141] The matching module 62 is used to match the message subject of the monitored message according to the locally preset concerned subject, and obtain the message body of the message under the concerned subject.
[0142] Specifically, when the message only includes a message subject and a message body for carrying the message content, matching the message subjects of the messages obtained by monitoring according to the local preset focus topic can filter out the messages corresponding to the local preset focus topic from the messages obtained by monitoring, that is, the messages that the micro server needs to process.
[0143] Based on any of the above embodiments, the message includes a message subject, a message ID, and a message body for carrying message content; after obtaining the message body of the message under the concerned topic, the intra-cluster message receiving device further includes:
[0144] The recording module 64 is used to record the message ID associated with the message body.
[0145] Specifically, when the message includes a message subject, a message ID and a message body for carrying the message content, the message ID is used to identify whether a duplicate message is sent. After determining that the message has not been obtained except this time, the message subject of the message obtained by monitoring is matched according to the local preset focus topic. The messages obtained by monitoring can be filtered out to find the messages corresponding to the local preset focus topic, that is, the messages that the microserver needs to process.
[0146] Based on any of the above embodiments, after obtaining the message body of the message under the concerned topic, the method further includes:
[0147] The processing module 66 is used to process the message according to the content of the message body.
[0148] Specifically, processing refers to obtaining the message content carried by the message body based on the message body.
[0149] The exception module 68 is used to store the message in an abnormal message processing queue if it is determined that the message processing is unsuccessful, and to take the message out of the abnormal message processing queue at a fixed time and perform the message processing operation again.
[0150] Specifically, if the message processing is unsuccessful, the message content carried by the message body cannot be obtained.
[0151] In a preferred embodiment, the intra-cluster message receiving device further comprises: an initialization module, wherein the initialization module is used to initialize the message notification service. It should be noted that the initialization module is executed when the message notification service list is obtained for the first time.
[0152] Figure 7 An example of a physical structure diagram of an electronic device is shown in FIG. Figure 7 As shown, the electronic device may include: a processor 710, a communication interface 720, a memory 730 and a communication bus 740, wherein the processor 710, the communication interface 720, and the memory 730 communicate with each other through the communication bus 740. The processor 710 may call the logic instructions in the memory 730 to execute the intra-cluster message notification method or the intra-cluster message receiving method described in the above embodiments.
[0153] In addition, the logic instructions in the above-mentioned memory 730 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on such an understanding, the technical solution of the embodiment of the present disclosure is essentially or the part that contributes to the prior art or the part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present disclosure. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.
[0154] On the other hand, the present disclosure also provides a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium, and the computer program includes program instructions. When the program instructions are executed by a computer, the computer can execute the intra-cluster message notification method or the intra-cluster message receiving method provided by the above-mentioned methods.
[0155] On the other hand, the present disclosure further provides a non-transitory computer-readable storage medium having a computer program stored thereon, which is implemented when the computer program is executed by a processor to execute the above-mentioned intra-cluster message notification method or intra-cluster message receiving method.
[0156] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Those of ordinary skill in the art may understand and implement it without creative effort.
[0157] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0158] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present disclosure, rather than to limit them. Although the present disclosure has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present disclosure.
Claims
1. A method for notifying a message within a cluster, characterized in that: include: Each micro server broadcasts a message to at least one micro server included in the message notification service list according to the message notification service list obtained from the registration center; wherein, The message notification service list is generated by the registration center according to each of the micro servers and their corresponding address information; the message notification service list includes all micro servers and their corresponding addresses that have been registered in the registration center when the micro server is acquired.
2. The method for in-cluster message notification according to claim 1, characterized in that: The method further comprises: Update the current message notification service list in each micro server according to the message notification service list regularly pushed by the registration center; and / or Each of the micro servers periodically accesses the registration center to reacquire an updated message notification service list.
3. The method for in-cluster message notification according to claim 1 or 2, characterized in that: The message includes a message subject and a message body carrying the message content; The message topic is used by the micro server receiving the message to filter the monitored multiple messages based on the locally preset focus topics.
4. The method for in-cluster message notification according to claim 3, characterized in that: The message also includes a message ID; Before broadcasting the message to at least one micro server included in the message notification service list, the method further includes: According to the message ID of the current message, it is determined whether the current message has been sent, and if it has been sent, the sending of the current message is terminated.
5. The method for in-cluster message notification according to claim 4, characterized in that: In the case that the current message is not sent, before broadcasting the message to at least one micro server included in the message notification service list, the method further includes: Confirm that the micro server that sends the current message has registered for a message notification service with the registration center.
6. The method for in-cluster message notification according to claim 1, characterized in that: After broadcasting the message to at least one micro server included in the message notification service list, the method further includes: Get the message sending result; After confirming that the sending result is a failure, start the synchronous retry sending of the message; or, store the failed sending message in the abnormal message sending queue, and take out the failed sending message from the abnormal message sending queue according to a preset time interval, and start the broadcast retry sending asynchronously again.
7. A method for receiving messages within a cluster, characterized in that: include: Each micro server monitors the message broadcasted by at least one micro server included in the message notification service list according to the message notification service list obtained from the registration center; wherein, The message notification service list is generated by the registration center according to each of the micro servers and their corresponding address information; the message notification service list includes all micro servers and their corresponding addresses that have been registered in the registration center when the micro server is acquired.
8. The method for receiving messages within a cluster according to claim 7, characterized in that: The message includes a message subject and a message body for carrying message content; The method further includes matching the message subject of the message acquired through monitoring according to the locally preset concerned subject, and acquiring the message body of the message under the concerned subject.
9. The method for receiving messages within a cluster according to claim 8, characterized in that: The message also includes a message ID; After obtaining the message body of the message under the concerned topic, the method further includes recording the message ID associated with the message body.
10. The method for receiving messages within a cluster according to claim 8, characterized in that: After obtaining the message body of the message under the concerned topic, the method further includes: Processing the message according to the content of the message body; If it is determined that the message processing is unsuccessful, the message is stored in an abnormal message processing queue, and is periodically taken out of the abnormal message processing queue and the message processing operation is performed again.
11. A message notification device within a cluster, characterized in that: Applied to a cluster including a registration center and multiple micro servers, the device includes: A broadcast module, used for each of the micro servers to broadcast a message to at least one micro server included in the message notification service list according to the message notification service list obtained from the registration center; wherein, The message notification service list is generated by the registration center according to each of the micro servers and their corresponding address information; the message notification service list includes all micro servers and their corresponding addresses that have been registered in the registration center when the micro server is acquired.
12. A message receiving device within a cluster, characterized in that: Applied to a cluster including a registration center and multiple micro servers, the device includes: A monitoring module is used for each of the micro servers to monitor the messages broadcast by at least one micro server included in the message notification service list according to the message notification service list obtained from the registration center; wherein, The message notification service list is generated by the registration center according to each of the micro servers and their corresponding address information; the message notification service list includes all micro servers and their corresponding addresses that have been registered in the registration center when the micro server is acquired.
13. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the following is achieved: The steps of the intra-cluster message notification method according to any one of claims 1 to 6; or The steps of the method for receiving a message within a cluster as claimed in any one of claims 7 to 10.
14. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, it realizes: The steps of the intra-cluster message notification method according to any one of claims 1 to 6; or The steps of the method for receiving a message within a cluster as claimed in any one of claims 7 to 10.
15. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, it realizes: The steps of the intra-cluster message notification method according to any one of claims 1 to 6; or The steps of the method for receiving a message within a cluster as claimed in any one of claims 7 to 10.
