Method and device for expanding and shrinking capacity based on message-oriented middleware
By injecting the listening container and global configuration container into the message middleware, adjusting the number of consumers in real time, solving the problem of inaccurate and time-consuming expansion and expansion in the existing technology, and achieving efficient and accurate expansion and expansion and expansion effects.
Patent Information
- Application Number
- CN202510033650.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-09
- Publication Date
- 2025-06-03
AI Technical Summary
When the prior art expands or reduces the capacity of the message middleware, it is difficult to achieve accurate and efficient adjustments, resulting in wasted resources or inability to meet real-time requirements, and the need to restart the service increases time.
By pre-injecting the listening container and the global configuration container in the message middleware, the total number of messages in the message queue is listened in real time, and the number of consumers currently configured is modified according to the real-time consumer count, so as to achieve accurate adjustments.
It realizes accurate and efficient expansion or reduction of message middleware, avoids waste of resources and dissatisfaction with real-time requirements, and reduces the time-consuming process during expansion and reduction.
Smart Images

Figure CN120091064A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of data processing, and in particular, to a method for scaling up and down based on a message middleware, a device for scaling up and down based on a message middleware, an electronic device, and a computer-readable storage medium. Background Art
[0002] Message middleware (such as RabbitMq) is mainly used for asynchronous communication between different application programs.
[0003] Before using the message middleware, it is necessary to configure the number of consumers in the message middleware. The number of consumers is the maximum number of messages that can be processed simultaneously in the message middleware per unit time. The higher the number of consumers, the more message communications the message middleware can provide per unit time. Once the number of consumers of the message middleware is configured, if subsequent adjustment is required, that is, scaling up or down the message middleware, then it is necessary to reconfigure the number of consumers of the message middleware, and then restart the service where the message middleware is located.
[0004] To implement scaling up or down of the message middleware, it is necessary to modify the number of consumers and restart the service. If the number of consumers is not modified accurately, it will either cause the message middleware to occupy too many resources, resulting in resource waste, or cause insufficient scaling up or excessive scaling down of the message middleware, unable to meet the real-time demand for the number of consumers. In addition, after modifying the number of consumers, it is also necessary to restart the service, which increases the time-consuming for scaling up or down the message middleware and reduces the efficiency of scaling up or down the message middleware. It can be seen that accurate and efficient scaling up or down of the message middleware is a problem that needs to be solved currently. Summary of the Invention
[0005] The purpose of the embodiments of this application is to provide a method for scaling up and down based on a message middleware, a device for scaling up and down based on a message middleware, an electronic device, and a computer-readable storage medium, which can achieve accurate and efficient scaling up or down of the message middleware.
[0006] To solve the above technical problems, the embodiments of this application provide the following technical solutions:
[0007] The first aspect of the present application provides a scaling method based on a message middleware. The method is applied to the message middleware, and a listening container and a global configuration container are pre-injected into the message middleware. The listening container is used to monitor the message queues in the message middleware, and the global configuration container is used to obtain the currently configured number of consumers in the message middleware and perform hot modification on the currently configured number of consumers. The method includes: obtaining the total number of messages in the message queue in the message middleware through the listening container, and determining the total number of messages as the real-time number of consumers in the message middleware; obtaining the currently configured number of consumers in the message middleware through the global configuration container; if the real-time number of consumers does not match the currently configured number of consumers, adjusting the currently configured number of consumers according to the real-time number of consumers through the global configuration container.
[0008] Compared with the prior art, the scaling method based on the message middleware provided by the first aspect of the present application obtains the real-time number of consumers in the message middleware through the listening container. When the real-time number of consumers does not match the currently configured number of consumers, the global configuration container adjusts the currently configured number of consumers in the memory according to the real-time number of consumers, which can not only accurately adjust the number of consumers in the message middleware, but also achieve hot modification of the number of consumers, and perform accurate and efficient expansion or contraction of the message queues in the message middleware.
[0009] In some variant embodiments of the first aspect of the present application, the message middleware includes multiple message queues, and each message queue is correspondingly configured with a number of consumers; obtaining the currently configured number of consumers in the message middleware through the global configuration container includes: obtaining the target message monitored by the listening container; determining the target message queue corresponding to the target message; obtaining the target number of consumers corresponding to the target message queue in the message middleware through the global configuration container; and determining the target number of consumers as the currently configured number of consumers of the target message queue in the message middleware.
[0010] Each message queue has a corresponding number of consumers. According to the number of messages currently received by the message middleware, the number of consumers of the corresponding message queue is adjusted, so that the adjustment of the number of consumers in the message middleware is more refined, and the accuracy of scaling the message middleware is further improved.
[0011] In some variant embodiments of the first aspect of the present application, before obtaining the target number of consumers corresponding to the target message queue in the message middleware through the global configuration container, the method further includes: determining the message queues currently in use in the message middleware; if the target message queue is included in the currently in-use message queues, then obtaining the target number of consumers corresponding to the target message queue in the message middleware through the global configuration container; if the target message queue is not included in the currently in-use message queues, then ending the adjustment of the number of consumers.
[0012] Adjusting only the number of consumers of the message queue currently in use in the message middleware can avoid ineffective adjustment of the number of consumers and improve the efficiency of dynamic scaling of the message middleware.
[0013] In some modified implementation manners of the first aspect of the present application, obtaining the total number of messages in the message queue of the message middleware through a monitoring container includes: obtaining, through the monitoring container, a first quantity of messages received by the message middleware within a preset period and a second quantity of messages sent out, where the preset period is positively correlated with the message processing speed of the message queue; and determining the total number of messages in the message queue of the message middleware based on the first quantity, the second quantity, and the existing number of messages in the message queue.
[0014] Since the messages in the message queue are dynamically changing, counting the number of messages in the message queue takes a certain amount of time. After the total number of messages in the message queue is counted, the messages in the message queue may have changed, and the current total number of messages may not correspond to the counted total number of messages. However, by obtaining the number of messages received and sent by the monitoring container within the preset period and determining the total number of messages in the message queue of the message middleware, the counting of the total number of messages can be advanced, and the current total number of messages in the message queue can be determined in real time and accurately.
[0015] In some modified implementation manners of the first aspect of the present application, adjusting the currently configured number of consumers according to the real-time number of consumers through a global configuration container includes: when the real-time number of consumers is greater than the currently configured number of consumers, determining the maximum number of consumers corresponding to the message middleware; if the real-time number of consumers exceeds the maximum number of consumers, modifying the currently configured number of consumers to the maximum number of consumers through the global configuration container; and if the real-time number of consumers does not exceed the maximum number of consumers, modifying the currently configured number of consumers to the real-time number of consumers through the global configuration container.
[0016] In the case of expansion, limiting the upper limit of the increase in the number of consumers to the limit of the message middleware, that is, not exceeding the maximum number of consumers, can avoid excessive expansion of the message middleware, achieve expansion, ensure the normal operation of the message middleware, and improve the processing efficiency of messages in the message middleware.
[0017] In some modified embodiments of the first aspect of the present application, the global configuration container adjusts the currently configured number of consumers according to the number of real-time consumers, including: determining the target consumer number range corresponding to the number of real-time consumers, where the message middleware corresponds to multiple consumer number ranges, and each consumer number range includes multiple consecutive consumer numbers; determining the target number of the target consumer number range; if the number of real-time consumers is less than or equal to the target number, the global configuration container adjusts the currently configured number of consumers to the target number of consumers, and the target number of consumers is the sum of the number of real-time consumers and the preset number of consumers; if the number of real-time consumers is greater than the target number, the global configuration container adjusts the currently configured number of consumers to the maximum number of the target consumer number range.
[0018] The number of consumers is divided into different ranges, and the corresponding range is found for the number of real-time consumers, and then the maximum number of consumers in the range is used to modify the currently configured number of consumers. When the currently configured number of consumers is the same as the maximum number of consumers in the corresponding range of the number of real-time consumers, there is no need to modify the number of consumers, reducing the number of times of modifying the number of consumers. Without significantly reducing the accuracy of the scaling of the message middleware, the efficiency of the scaling of the message middleware can be improved.
[0019] In some modified embodiments of the first aspect of the present application, a timing scheduler is also pre-injected into the message middleware, and the timing scheduler is connected to the listening container and the global configuration container; obtaining the total number of messages in the message queue in the message middleware through the listening container, including: in response to the start instruction triggered by the timing scheduler according to the preset period, obtaining the total number of messages in the message queue in the message middleware through the listening container; feeding back the obtained information to the timing scheduler, and the obtained information is used to indicate that the total number of messages in the message queue in the message middleware has been obtained; obtaining the currently configured number of consumers in the message middleware through the global configuration container, including: in response to the continue obtaining instruction triggered by the timing scheduler based on the obtained information, obtaining the currently configured number of consumers in the message middleware through the global configuration container.
[0020] By sequentially controlling the timing scheduler to obtain the total number of messages through the listening container and obtain the currently configured number of consumers through the global configuration container, and only obtaining the currently configured number of consumers after determining that the total number of messages has been obtained, it can avoid the situation of obtaining the currently configured number of consumers when the total number of messages acquisition fails, reduce the acquisition of invalid information, and improve the efficiency of the scaling of the message middleware.
[0021] The second aspect of the present application provides a scaling device based on a message middleware. The device is applied to the message middleware, and a listening container and a global configuration container are pre-injected into the message middleware. The listening container is used to monitor the message queues in the message middleware, and the global configuration container is used to obtain the currently configured number of consumers in the message middleware and perform hot modification on the currently configured number of consumers. The device includes: a first acquisition module, configured to obtain the total number of messages in the message queues in the message middleware through the listening container, and determine the total number of messages as the real-time number of consumers in the message middleware; a second acquisition module, configured to obtain the currently configured number of consumers in the message middleware through the global configuration container; and a configuration module, configured to, if the real-time number of consumers does not match the currently configured number of consumers, adjust the currently configured number of consumers according to the real-time number of consumers through the global configuration container.
[0022] The third aspect of the present application provides an electronic device, which includes: a processor, a memory, and a bus; wherein, the processor and the memory communicate with each other through the bus; and the processor is configured to call program instructions in the memory to execute the method in the first aspect.
[0023] The fourth aspect of the present application provides a computer-readable storage medium, which includes: a stored program; wherein, when the program runs, it controls the device where the storage medium is located to execute the method in the first aspect.
[0024] The scaling device based on the message middleware provided in the second aspect of the present application, the electronic device provided in the third aspect, and the computer-readable storage medium provided in the fourth aspect have the same or similar beneficial effects as the scaling method based on the message middleware provided in the first aspect. Description of the Drawings
[0025] By reading the following detailed description with reference to the drawings, the above and other objects, features, and advantages of the exemplary embodiments of the present application will become easy to understand. In the drawings, several embodiments of the present application are shown in an exemplary rather than restrictive manner, and the same or corresponding reference numerals represent the same or corresponding parts, wherein:
[0026] Figure 1 It is a schematic diagram of the scenario architecture of the scaling method based on the message middleware in the embodiment of the present application Figure 1 ;
[0027] Figure 2 It is a schematic diagram of the process of the scaling method based on the message middleware in the embodiment of the present application Figure 1 ;
[0028] Figure 3 It is a schematic diagram of the scenario architecture of the scaling method based on the message middleware in the embodiment of the present application Figure 2 ;
[0029] Figure 4 Schematic flow of the scaling method based on message middleware in the embodiments of the present application Figure 2 ;
[0030] Figure 5 Schematic structure of the scaling device based on message middleware in the embodiments of the present application Figure 1 ;
[0031] Figure 6 Schematic structure of the scaling device based on message middleware in the embodiments of the present application Figure 2 ;
[0032] Figure 7 Schematic diagram of the structure of the electronic device in the embodiments of the present application. Detailed implementation manners
[0033] Hereinafter, the exemplary embodiments of the present application will be described in more detail with reference to the accompanying drawings. Although the exemplary embodiments of the present application are shown in the drawings, it should be understood that the present application can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided so that the present application can be more thoroughly understood and the scope of the present application can be fully conveyed to those skilled in the art.
[0034] It should be noted that, unless otherwise specified, the technical terms or scientific terms used in the present application should have the ordinary meanings understood by those skilled in the art to which the present application belongs.
[0035] Currently, for scaling up or down a message middleware, it is necessary to manually determine the number of consumers after adjustment, then manually modify the number of consumers configured in the message middleware, and then restart the service where the message middleware is located. On the one hand, the business levels and experiences of the personnel determining the number of consumers are different, and the determined numbers of consumers are also different, which may result in the adjustment of the number of consumers not being able to accurately meet the actual situation of the message middleware. On the other hand, after modifying the number of consumers, restarting the service of the message middleware takes a certain amount of time. In this way, the accuracy and real-time performance of the scaling of the message middleware are reduced.
[0036] In view of this, an embodiment of the present application provides a method for scaling in and out based on a message middleware, a device for scaling in and out based on a message middleware, an electronic device, and a computer-readable storage medium. A listening container and a global configuration container are pre-injected into the message middleware. The listening container is used to obtain the real-time number of consumers in the message middleware, and when the real-time number of consumers is different from the number of consumers currently configured in the message middleware, the global configuration container is used to reconfigure the number of consumers in the message middleware according to the real-time consumers, achieving precise adjustment of the number of consumers in the message middleware. Moreover, through the global configuration container, hot modification of the number of consumers can be achieved without restarting the service, shortening the duration of scaling in and out of the message middleware. That is, precise and efficient scaling in and out of the message middleware is realized.
[0037] First, the application scenario of the method for scaling in and out based on a message middleware provided by an embodiment of the present application is described.
[0038] Figure 1 For the scenario architecture diagram of the method for scaling in and out based on a message middleware in an embodiment of the present application Figure 1 , see Figure 1 As shown, the architecture may include: a message middleware. That is to say, the method for scaling in and out based on a message middleware is applied to the message middleware.
[0039] In the message middleware, there is a message queue. Moreover, in the message middleware, a listening container and a global configuration container are also pre-injected.
[0040] The message queue is the place where the message is stored in the message middleware after the message middleware receives the message and before it sends out the message. After the message middleware receives the message, it first stores the message in the message queue, and follows the principle of first in first out, and sequentially obtains the message from the message queue and processes, forwards, etc. the message.
[0041] In practical applications, the message middleware may be RabbitMq. The specific type of the message middleware is not limited here.
[0042] The listening container is used to monitor the message queue in the message middleware. The listening container can specifically monitor various information in the message queue. For example: the listening container monitors the specific content, quantity, enqueue time, and dequeue time of the messages in the message queue, etc.
[0043] In some embodiments, when the message middleware is RabbitMq, the listening container is a Rabbit listening container. The listening container can be applicable to the message middleware. The specific type of the listening container is not limited here.
[0044] The global configuration container, namely GlobalConfig, is used to obtain the number of current configured consumers in the message middleware and perform hot modification on the number of current configured consumers. That is to say, if it is necessary to obtain the number of current configured consumers in the message middleware, it can be directly obtained from the global configuration container without searching for it in other configuration information of the message middleware. And if it is necessary to modify the number of current configured consumers, the number of current configured consumers can be directly modified in the global configuration container, and the global configuration container can make the message middleware run according to the modified number of consumers without restarting the service where the message middleware is located. That is to say, after injecting the global configuration container into the message middleware, all operations related to the consumer number configuration can be performed through the global configuration container. The global configuration container here is the same as the conventional global configuration container, and both can manage and hot modify configuration parameters.
[0045] It should be noted here that injecting the listening container and the global configuration container into the message middleware is the same as the specific method of injecting containers in conventional application software. Listening to the message queue in the message middleware through the listening container is the same as the specific method of listening to the target object through the listening container in the conventional way, which will not be elaborated here.
[0046] During the operation of the message middleware, the listening container listens to the total number of messages in the message queue of the message middleware, and then determines the real-time number of consumers in the message queue. The global configuration container obtains the number of current configured consumers in the message middleware. The message middleware compares the real-time number of consumers with the number of current configured consumers, and when the real-time number of consumers is different from the number of current configured consumers, determines the adjusted number of consumers based on the real-time number of consumers, and sends the adjusted number of consumers to the global configuration container. After receiving the adjusted number of consumers, the global configuration container modifies the number of current configured consumers to the adjusted number of consumers in the memory. Since updating the memory code of the running process can be done without restarting the device to achieve hot modification, therefore, the global configuration container adjusting the number of consumers in the memory also does not require restarting the message middleware, thus achieving hot modification of the number of consumers. In this way, the accurate and efficient adjustment of the number of consumers is completed, and the accurate and efficient expansion or contraction of the message queue in the message middleware is achieved.
[0047] Next, the method for expanding and contracting capacity based on the message middleware provided by the embodiments of the present application will be described in detail.
[0048] Figure 2 For the flow diagram of the method for expanding and contracting capacity based on the message middleware in the embodiments of the present application Figure 1 , see Figure 2 As shown, this method may include S21 - S25.
[0049] S21: Obtain the total number of messages in the message queue in the message middleware by listening to the container, and determine the total number of messages as the number of real-time consumers in the message middleware.
[0050] In the message queue, every time a message enters, the total number of messages in the message queue increases by 1 (i.e., increments by 1). Every time a message is extracted, the total number of messages in the message queue decreases by 1 (i.e., decrements by 1).
[0051] The listening container can listen to the number of newly added messages and the number of dequeued messages in the message queue, and then add the total number of messages in the message queue counted last time to the number of newly added messages and subtract the number of dequeued messages to obtain the current total number of messages in the message queue. Alternatively, the listening container can also obtain all the current messages in the message queue and then count the number of the obtained messages to get the current total number of messages in the message queue. Of course, the listening container can also obtain the current total number of messages in the message queue through other information related to the message outside the message queue.
[0052] The total number of messages can represent the number of messages currently stored in the message queue. The number of consumers, on the other hand, represents the number of messages that the message middleware can process per unit time. If the total number of messages is higher while the number of consumers configured in the message middleware is lower, the messages in the message queue of the message middleware will continue to pile up, resulting in abnormal operation of the message middleware. If an appropriate number of consumers is configured in the message middleware, the continuous backlog of messages in the message queue can be avoided. Therefore, the current total number of messages in the message queue can be used as a consideration factor for the number of real-time consumers corresponding to the message middleware, so as to accurately perform dynamic expansion or contraction of the message middleware.
[0053] S22: Obtain the number of currently configured consumers in the message middleware through the global configuration container.
[0054] After injecting the global configuration container into the message middleware, the configuration work of various parameters including the number of consumers in the message middleware can be carried out in the global configuration container. For obtaining the number of currently configured consumers in the message middleware, it can also be directly obtained from the global configuration container.
[0055] When specifically obtaining, the message middleware first needs to determine the storage location of the number of consumers in the global configuration container. When injecting the global configuration container into the message middleware, after the injector injects and configures the global configuration container, the injector will inform the message middleware of the location configured for the number of consumers. The message middleware stores this location information. When it is necessary to obtain the number of consumers through the global configuration container, it can directly lock the specific location in the global configuration container according to this location information, so as to obtain the number of currently configured consumers in the message middleware at this location.
[0056] In some other embodiments, when the global configuration container injects the message middleware, it only uses the global configuration container to configure the number of consumers. Then, the message middleware does not need to store any location information. When it is necessary to obtain the number of consumers through the global configuration container, the parameters are directly obtained from the global configuration container, and the obtained parameters are the currently configured number of consumers.
[0057] S23: Determine whether the real-time number of consumers matches the currently configured number of consumers. If so, execute S24; if not, execute S25.
[0058] Here, the matching can mean that the numerical values are the same, or it can mean that the difference in quantity is within a preset range.
[0059] If the real-time number of consumers is the same as the currently configured number of consumers, it can be determined that the real-time number of consumers matches the currently configured number of consumers. If the real-time number of consumers is different from the currently configured number of consumers, it can be determined that the real-time number of consumers does not match the currently configured number of consumers.
[0060] Or, if the difference in the real-time number of consumers and the currently configured number of consumers is less than or equal to the preset threshold, it means that the difference in the real-time number of consumers and the currently configured number of consumers is not large and is within the preset range, and it can be determined that the real-time number of consumers matches the currently configured number of consumers. If the difference in the real-time number of consumers and the currently configured number of consumers is greater than the preset threshold, it means that the difference in the real-time number of consumers and the currently configured number of consumers is large and exceeds the preset range, and it can be determined that the real-time number of consumers does not match the currently configured number of consumers. The preset threshold can be flexibly set according to actual needs, and the embodiments of the present application do not make special explanations.
[0061] S24: End the adjustment of the number of consumers.
[0062] When the real-time number of consumers matches the currently configured number of consumers, it means that the currently configured number of consumers in the message middleware can normally process the current messages in the message queue, and there is no need to expand or contract the message middleware, and the number of consumers configured in the message middleware is no longer adjusted.
[0063] S25: Adjust the currently configured number of consumers according to the real-time number of consumers through the global configuration container.
[0064] When the number of real-time consumers does not match the number of currently configured consumers, it indicates that the number of currently configured consumers in the message middleware cannot process the current messages in the message queue properly. If the number of real-time consumers is greater than the number of currently configured consumers, it means that the currently configured consumers in the message middleware cannot process the current messages in the message queue smoothly, and the messages in the message queue will continue to accumulate. If the number of real-time consumers is less than the number of currently configured consumers, it means that the currently configured consumers in the message middleware can quickly process the current messages in the message queue, and there are still some unused consumer numbers, resulting in waste of resources. At this time, it is necessary to expand or contract the capacity of the message middleware, and adjust the number of currently configured consumers according to the number of real-time consumers through the global configuration container.
[0065] On the one hand, the number of currently configured consumers can be modified to the number of real-time consumers.
[0066] On the other hand, according to the historical adjustment situation of the number of consumers, the number of real-time consumers can also be adjusted, and then the adjusted number of consumers is used to replace the currently configured number of consumers. For example: if the number of consumers has been increased continuously several times in the historical situation, at this time, the number of real-time consumers can be multiplied by a preset multiple greater than 1, and then the obtained number of consumers is used to replace the currently configured number of consumers. Another example: if the number of consumers has been decreased continuously several times in the historical situation, at this time, the number of real-time consumers can be multiplied by a preset multiple greater than 0 and less than 1, and then the obtained number of consumers is used to replace the currently configured number of consumers.
[0067] After determining the number of real-time consumers or the adjusted number of consumers, the global configuration container can delete the currently configured number of consumers in the memory where the message middleware runs, and then write the number of real-time consumers or the adjusted number of consumers. In this way, the hot modification of the number of consumers is realized, and thus the accurate and efficient dynamic expansion or contraction of the message queue in the message middleware is achieved.
[0068] As can be seen from the above content, the method for expanding and contracting the capacity based on the message middleware provided by the embodiments of the present application obtains the number of real-time consumers in the message middleware through the listening container. When the number of real-time consumers does not match the number of currently configured consumers, the global configuration container adjusts the number of currently configured consumers in the memory according to the number of real-time consumers. This not only enables the number of consumers in the message middleware to be accurately adjusted, but also realizes the hot modification of the number of consumers, and accurately and efficiently expands or contracts the message queue of the message middleware.
[0069] As an elaboration and extension of the Figure 2 method shown above, the embodiments of the present application also provide a method for expanding and contracting the capacity based on the message middleware.
[0070] Figure 3Schematic diagram of the scenario architecture of the scaling method based on the message middleware in the embodiment of the present application Figure 2 , see Figure 3 As shown, in the message middleware, in addition to including a message queue, a listening container, and a global configuration container, a timed scheduler is also pre-injected.
[0071] The timed scheduler, that is, ScheduledThreadPoolExecutor, is connected to the listening container and the global configuration container, and can start the listening container regularly to monitor the total number of messages in the message queue, and start the global configuration container to reconfigure the current configured number of consumers.
[0072] For the message queue, the number can also be multiple. After the message is sent to the message middleware, the message middleware can send the message to the corresponding message queue for storage according to the specific content of the message and the specific type of the message queue. For each message queue, its corresponding number of consumers can be configured.
[0073] Figure 4 Schematic diagram of the process of the scaling method based on the message middleware in the embodiment of the present application Figure 2 , see Figure 4 As shown, the method may include:
[0074] S41: In response to the start instruction triggered by the timed scheduler according to the preset period, obtain the total number of messages in the message queue in the message middleware through the listening container, and determine the total number of messages as the real-time number of consumers in the message middleware.
[0075] In the timed scheduler, it can be set in advance. Specifically, it is set to trigger the start instruction according to the preset period. The preset period can be 1s, 10s, 1h, etc., and can be determined according to actual needs. The start instruction is sent directly to the listening container. After receiving the start instruction, the listening container can start to monitor the total number of messages in the message queue. For the specific content of the start instruction, it is not limited here, and it can be pre-agreed between the timed scheduler and the listening container.
[0076] After the timing scheduler triggers the start instruction according to the preset period, it sends the start instruction to the listening container. After receiving the start instruction, the listening container determines that the start instruction is correct through the specific content of the start instruction (for example: determining that the start instruction contains a preset identifier, or determining that the specific description of the start instruction conforms to the preset syntax), and after determining that the start instruction is not maliciously sent through the sending object of the start instruction (for example: determining that the start instruction is sent by the timing scheduler), it can start listening to the total number of messages in the message queue, and then send the monitored total number of messages to the corresponding module in the message middleware (this module is the execution subject in the embodiment of the present application). Once the listening container determines that there is a problem with the start instruction it receives, it will no longer start listening to the total number of messages to ensure the information security in the message middleware.
[0077] Of course, the listening container can also directly start listening after receiving the start instruction to improve the efficiency of obtaining the total number of messages, and thus improve the efficiency of scaling the message middleware.
[0078] During the listening process, in addition to directly listening to the message queue, the listening container can also listen to the message reception situation of the message middleware to determine the total number of messages in the message queue.
[0079] Specifically, the above step S41 may include:
[0080] Step A1: Obtain the first quantity of messages received by the message middleware and the second quantity of messages sent out by the message middleware within a preset time period through the listening container. The preset time period is positively correlated with the message processing speed of the message queue.
[0081] The listening container can listen to the message receiving interface and the sending interface of the message middleware to obtain the number of messages received and the number of messages sent out by the message middleware within a preset time period.
[0082] Here, the preset time period can be a period of time or an instantaneous time. When the value of the preset time period is greater than 0, the preset time period is a period of time, that is, the listening container needs to listen to the number of messages received and sent by the message middleware within a period of time. When the value of the preset time period is equal to 0, the preset time period is an instantaneous time, that is, the listening container needs to listen to the number of messages received and sent by the message middleware in real time. The specific value of the preset time period can be determined according to the actual message processing speed of the message queue or the actual demand for scaling.
[0083] The faster the message processing speed of the message queue, the faster the messages entering the message middleware can be processed and sent out, and the lower the probability of obvious changes in the number of messages in the message queue. Consequently, the longer the preset period is set, the fewer the number of invalid statistics can be reduced, thereby improving the scaling efficiency of the message middleware. The slower the message processing speed of the message queue, the greater the probability that the messages entering the message middleware are backlogged in the message queue. Therefore, the shorter the preset period is set, the total number of messages in the message queue can be counted faster, so as to quickly expand the capacity of the message middleware and solve the problem of message backlog in the message queue as soon as possible, fully ensuring the normal operation of the message middleware.
[0084] Regarding the scaling of the message middleware, if the real-time requirement is high, the preset period can be set to be less than the preset duration. If it is necessary to ensure that the service where the message middleware is located has sufficient resources for use, the preset period can be set to be greater than or equal to the preset duration.
[0085] Step A2: Based on the first quantity, the second quantity, and the number of messages already in the message queue, determine the total number of messages in the message queue in the message middleware.
[0086] The first quantity represents the number of messages currently received by the message middleware. The second quantity represents the number of messages currently sent by the message middleware. Subtracting the second quantity from the first quantity gives the number of messages currently accumulated by the message middleware. Then, adding the number of messages already in the message queue actually gives the total number of messages in the current message queue of the message middleware.
[0087] S42: Feed back the acquisition information to the timing scheduler, and the acquisition information is used to indicate that the total number of messages in the message queue in the message middleware has been acquired.
[0088] After the monitoring container monitors the total number of messages in the message queue, it can feed back the acquisition information to the timing scheduler. In practical applications, the acquisition information can be any information pre-agreed between the monitoring container and the timing scheduler, such as: the total number of messages acquired, the specific value of the total number of messages, etc. The specific content of the acquisition information is not limited here.
[0089] After the timing scheduler confirms the acquisition information, it generates a continue acquisition instruction and sends the continue acquisition instruction to the global configuration container so that the global configuration container can obtain the number of current consumers configured in the message middleware.
[0090] S43: In response to the continue acquisition instruction triggered by the timing scheduler based on the acquisition information, obtain the number of current consumers configured in the message middleware through the global configuration container.
[0091] In order to make the scaling of the message middleware more accurate, a corresponding number of consumers can be configured for each message queue in the message middleware to precisely control the message processing processes of each message queue. Thus, based on the current message reception situation of the message middleware, it is only necessary to adjust the number of consumers corresponding to the corresponding message queue.
[0092] Specifically, the above step S43 may include:
[0093] Step B1: Obtain the target message monitored by the monitoring container.
[0094] Step B2: Determine the target message queue corresponding to the target message.
[0095] Step B3: Obtain the target number of consumers configured for the target message queue in the message middleware through the global configuration container.
[0096] Step B4: Determine the target number of consumers as the number of consumers currently configured for the target message queue in the message middleware.
[0097] That is to say, when performing scaling, instead of confirming and adjusting the number of consumers corresponding to each message queue, the number of consumers of the message queue corresponding to the message currently received by the message middleware (different messages will be assigned to different message queues due to different factors such as types) is confirmed or adjusted.
[0098] For example, assume that there are 2 message queues in the message middleware. Message queue 1 is used to store type-a messages, and message queue 2 is used to store type-b messages. The correspondence between type-a messages - message queue 1 and type-b messages - message queue 2 is pre-stored in the message middleware. In response to the continue acquisition instruction sent by the timing scheduler, the message middleware obtains message a1 monitored when obtaining the total number of previously monitored messages from the monitoring container. Through the data characteristics of message a1, it is determined that message a1 is a type-a message. Then, in the pre-stored correspondence between message types and message queues, the message queue corresponding to type-a messages is found, that is, message queue 1. Furthermore, the number of consumers currently configured for message queue 1 is obtained from the global configuration container, and this number of consumers is used as the currently to-be-adjusted number of consumers.
[0099] In some cases, one or more message queues in the message middleware are currently unavailable for some reason. The number of consumers corresponding to these message queues will be deleted when unavailable, or provided to other message queues. These message queues do not need to be adjusted for the number of consumers anymore. To avoid invalid modification of the number of consumers, it is possible to confirm whether the message queue is in use before obtaining the number of consumers corresponding to the message queue.
[0100] Specifically, before the above step B3, the method may further include:
[0101] Step B301: Determine the message queues currently in use in the message middleware.
[0102] Step B302: Determine whether the target message queue is included in the currently used message queues. If so, execute Step B3; if not, execute Step B303.
[0103] Step B303: End the adjustment of the number of consumers.
[0104] That is to say, before obtaining the number of consumers currently corresponding to the target message queue, first determine the message queues currently in use in the message middleware and match the target message queue among the currently used message queues. If the same queue is matched, it means that the target message queue is currently in use in the message middleware, and the number of consumers corresponding to the target message queue can be obtained, so as to determine whether the number of consumers needs to be adjusted. If no same queue is matched, it means that the target message queue is not currently in use in the message middleware, and it may have become unusable or been deactivated. At this time, no longer continue to obtain the number of consumers corresponding to the target message queue, nor determine whether the number of consumers needs to be adjusted, that is, end the adjustment of the number of consumers. Because the target message queue is not in use, adjusting the corresponding number of consumers has no practical significance and will also consume resources.
[0105] For the target message, it is possible that an error occurred during its generation, and it was originally intended to be sent to other message queues. Therefore, while ending the adjustment of the number of consumers, a prompt message for confirming whether the content of the target message is correct can also be generated and output to improve the accuracy of message sending.
[0106] During the process of determining the currently used message queues, the time point when each message queue in the message middleware stored the message last can be determined. If the duration from the time point to the current moment is greater than the preset duration, it means that the corresponding message queue has not stored messages for a long time, that is, it has not been used, and it can be determined that the message queue is not currently in use. Deleting such message queues from all the message queues in the message middleware will obtain the message queues currently in use in the message middleware.
[0107] Alternatively, after determining the time point when each message queue in the message middleware stored the message last, if the duration from the time point to the current moment is less than or equal to the preset duration, it means that the corresponding message queue has stored messages recently, that is, it is being used, and it can be determined that the message queue is currently in use. Integrating such message queues from all the message queues in the message middleware will obtain the message queues currently in use in the message middleware.
[0108] The currently used message queue is determined. After determining that the target message queue belongs to the currently used message queue, the number of consumers corresponding to the target message queue can be continuously obtained through the global configuration container and used as the number of consumers currently configured in the message middleware. Combining with the real-time number of consumers of the message middleware obtained previously, it can be determined whether the number of consumers in the message middleware needs to be adjusted.
[0109] S44: Determine whether the real-time number of consumers matches the currently configured number of consumers. If so, execute S45; if not, execute S46.
[0110] S45: End the adjustment of the number of consumers.
[0111] The specific implementation manners of steps S44 and S45 here are the same as those of steps S23 and S24 in the foregoing embodiment. For relevant descriptions, reference can be made to the foregoing embodiment and will not be elaborated here.
[0112] S46: Adjust the currently configured number of consumers according to the real-time number of consumers through the global configuration container.
[0113] If the real-time number of consumers is less than the currently configured number of consumers, the configured number of consumers in the message middleware can be modified to the real-time number of consumers.
[0114] If the real-time number of consumers is greater than the currently configured number of consumers, it is also necessary to consider the maximum number of consumers that the message middleware can withstand to avoid the modified number of consumers exceeding the maximum number of consumers that the message middleware can withstand, so as to ensure the normal operation of the message middleware while achieving dynamic and accurate capacity expansion.
[0115] Specifically, the above step S46 may include:
[0116] Step C1: When the real-time number of consumers is greater than the currently configured number of consumers, determine the maximum number of consumers corresponding to the message middleware.
[0117] Step C2: Determine whether the real-time number of consumers exceeds the maximum number of consumers. If so, execute step C3; if not, execute step C4.
[0118] Step C3: Modify the currently configured number of consumers to the maximum number of consumers through the global configuration container.
[0119] Step C4: Modify the currently configured number of consumers to the real-time number of consumers through the global configuration container.
[0120] The maximum number of consumers here refers to the number of messages that can be processed simultaneously when the message middleware is running at full load. The maximum number of consumers can be determined after the message middleware is deployed and can be obtained specifically from the configuration file of the device where the message middleware is located.
[0121] When it is determined that the real-time number of consumers exceeds the maximum number of consumers, the currently configured number of consumers will not be modified to the real-time number of consumers to avoid overloading the message middleware. Instead, the currently configured number of consumers will be modified to the maximum number of consumers of the message middleware, ensuring the normal operation of the message middleware while achieving dynamic and precise capacity expansion and improving message processing efficiency.
[0122] Of course, after adjusting the currently configured number of consumers to the maximum number of consumers, the messages in the message queue will start to accumulate. If the message middleware receives a large number of messages for a long time, the message queue may experience severe backlog. To solve this problem, some idle resources used for services in the service where the message middleware is located can be temporarily borrowed by the message middleware. During the borrowing period, the configured maximum number of consumers will be increased by a corresponding proportion according to the amount of borrowed resources. The more resources are borrowed, the greater the proportion of increase for the configured maximum number of consumers. For example: if the currently configured maximum number of consumers is 100, and the service borrows 1G of resource volume, and the corresponding increase proportion for 1G of resource volume is 0.1, then the currently configured maximum number of consumers can be increased by 0.1, that is, on the basis of the original configured maximum number of consumers 100, an additional 10 (100×0.1) consumers are added, and the currently configured number of consumers is 110. If the service borrows 2G of resource volume, and the corresponding increase proportion for 2G of resource volume is 0.2, then the currently configured maximum number of consumers can be increased by 0.2, that is, on the basis of the original configured maximum number of consumers 100, an additional 20 (100×0.2) consumers are added, and the currently configured number of consumers is 120. The corresponding relationship between the borrowed resource volume and the increase proportion can be configured according to the actual situation and is not limited here. After a preset duration or after the message backlog problem in the message queue is solved, the borrowed resources will be returned to the service, and then the increased number of consumers will be adjusted to the maximum number of consumers.
[0123] In addition to restricting the configured number of consumers, the number of adjustments to the number of consumers can also be restricted to avoid frequent fine-tuning from occupying resources and improve the scaling efficiency of the message middleware.
[0124] Specifically, the above step S46 may include:
[0125] Step D1: Determine the target consumer number range corresponding to the real-time consumer number. The message middleware corresponds to multiple consumer number ranges, and each consumer number range includes multiple consecutive consumer numbers.
[0126] In the message middleware, all consumer numbers can be divided into ranges to obtain multiple consumer number ranges. The consumer numbers in each consumer number range are consecutive in sequence. For example: the consumer numbers included in consumer number range 1 are from 1 to 100, the consumer numbers included in consumer number range 2 are from 101 to 200, the consumer numbers included in consumer number range 3 are from 201 to 500, etc. The specific numerical range of the consumer numbers included in each consumer number range is not limited here.
[0127] After obtaining the real-time consumer number, find the consumer number range where the real-time consumer number is located, and this range is the target consumer number range. Continuing the above example, assuming the obtained real-time consumer number is 120, then the target consumer number range is consumer number range 2.
[0128] Step D2: Determine the target number of the target consumer number range.
[0129] In some embodiments, the target number can be set flexibly, such as the median, 1 / 3 number. In other embodiments, the target number can be obtained according to the consumer numbers in the target consumer number range among the historical consumer numbers in the historical period. For example, the target number is the maximum value, average value, or a preset multiple of the average value (such as 1.1 times, 1.2 times, etc.) of the consumer numbers in the target consumer number range among the historical consumer numbers in the historical period (such as within a week, within a month). It should be noted that the product of the average value and the preset multiple should not be greater than the maximum value of the target consumer number range. For the convenience of explanation, the following takes the target number being the median as an example for illustration.
[0130] Continuing the above example, select the median 150 from consumer number range 2.
[0131] Step D3: Determine whether the real-time consumer number is less than or equal to the target number. If so, execute Step D4; if not, execute Step D5.
[0132] Step D4: Adjust the currently configured consumer number to the target consumer number through the global configuration container. The target consumer number is the sum of the real-time consumer number and the preset consumer number.
[0133] Step D5: Adjust the currently configured consumer number to the maximum number of the target consumer number range through the global configuration container.
[0134] Continuing with the above example, the number of real-time consumers is 120, and the median of the corresponding target consumer range 2 is 150. The number of real-time consumers 120 is less than the median 150. If the number of real-time consumers is 180, the median of the corresponding target consumer range 2 is still 150, and the number of real-time consumers 180 is greater than the median 150.
[0135] Different consumer ranges are divided according to the different usage frequencies of the number of consumers configured in the message queue. For example, the number of consumers often configured in the message queue is 110, 150, 180, etc. In other words, the number of consumers below 100 and above 200 is not often configured in the queue, but the situation of being configured in the queue is not excluded. At this time, the consumer range can be divided into three ranges, namely, consumer number range 1 (including consumer numbers 1 - 100), consumer number range 2 (including consumer numbers 101 - 200), and consumer number range 3 (including consumer numbers 201 - 500).
[0136] After determining that the number of currently configured consumers needs to be adjusted and determining the target number in the target consumer number range corresponding to the number of real-time consumers, if the number of real-time consumers is less than or equal to the target number, it means that there are enough common consumers above the number of real-time consumers for the number of real-time consumers to increase further. At this time, a preset number of consumers can be added to the number of real-time consumers and used as the finally configured number of consumers. Continuing with the above example, assuming the number of real-time consumers is 120, which is less than the median 150 of the target consumer range 2. At this time, the number of consumers can be configured as 130, 150, or 170. The preset number of consumers here can be set according to the actual situation and can be less than half of the target consumer number range. For specific values, no limitation is made here. If the number of real-time consumers is greater than the median, it means that there are not enough common consumers above the number of real-time consumers for the number of real-time consumers to increase further. At this time, the maximum number in the target consumer number range can be used as the finally configured number of consumers. Continuing with the above example, assuming the number of real-time consumers is 180, which is greater than the median 150 of the target consumer range 2. At this time, the number of consumers can be configured as the maximum number 200 in the target consumer range 2.
[0137] In this way, the finally configured number of consumers will be slightly greater than the number of real-time consumers. Even if the total number of messages in the subsequent message queue increases, and the increase in the total number of messages is not large, it will not exceed the currently configured number of consumers, thus eliminating the need to reconfigure the number of consumers again. Overall, it reduces the number of times of configuring the number of consumers, avoids the repeated configuration of the number of consumers in the message middleware, and ensures the stable operation of the message middleware.
[0138] So far, all the descriptions of the method for scaling in and out based on the message middleware provided by the embodiments of this application have been completed.
[0139] Based on the same inventive concept, as an implementation of the above method, an embodiment of the present application further provides a scaling device based on a message middleware.
[0140] The scaling device based on the message middleware is applied to the message middleware, in which a listening container and a global configuration container are pre-injected. The listening container is used to monitor the message queues in the message middleware, and the global configuration container is used to obtain the currently configured number of consumers in the message middleware and perform hot modification on the currently configured number of consumers.
[0141] Figure 5 The structural schematic of the scaling device based on the message middleware in the embodiment of the present application Figure 1 is shown in Figure 5 As shown, the device may include: a first acquisition module 51, a second acquisition module 52, and a configuration module 53.
[0142] The first acquisition module 51 is configured to obtain the total number of messages in the message queue in the message middleware through the listening container, and determine the total number of messages as the real-time number of consumers in the message middleware.
[0143] The second acquisition module 52 is configured to obtain the currently configured number of consumers in the message middleware through the global configuration container.
[0144] The configuration module 53 is configured to, if the real-time number of consumers does not match the currently configured number of consumers, adjust the currently configured number of consumers according to the real-time number of consumers through the global configuration container.
[0145] As a refinement and extension of the Figure 5 device shown above, an embodiment of the present application further provides a scaling device based on a message middleware.
[0146] A timing scheduler is also pre-injected into the message middleware, and the timing scheduler is connected to the listening container and the global configuration container.
[0147] The message middleware includes multiple message queues, and each message queue is correspondingly configured with a number of consumers.
[0148] Figure 6 The structural schematic of the scaling device based on the message middleware in the embodiment of the present application Figure 2 is shown in Figure 6 As shown, the system may include: a first acquisition module 61, an information sending module 62, a second acquisition module 63, a judgment module 64, and a configuration module 65.
[0149] The first acquisition module 61 is configured to, in response to a startup instruction triggered by a timing scheduler according to a preset period, obtain the total number of messages in the message queue in the message middleware by listening to the container, and determine the total number of messages as the number of real-time consumers in the message middleware.
[0150] The first acquisition module 61 includes: a message listening unit 611 and a message calculation unit 612.
[0151] The message listening unit 611 is configured to obtain, by listening to the container, a first quantity of messages received by the message middleware within a preset time period and a second quantity of messages sent out, and the preset time period is positively correlated with the message processing speed of the message queue.
[0152] The message calculation unit 612 is configured to determine the total number of messages in the message queue in the message middleware based on the first quantity, the second quantity, and the number of messages already existing in the message queue.
[0153] The information sending module 62 is configured to feedback acquisition information to the timing scheduler, and the acquisition information is used to indicate that the total number of messages in the message queue in the message middleware has been obtained.
[0154] The second acquisition module 63 is configured to, in response to a continue acquisition instruction triggered by the timing scheduler based on the acquisition information, obtain the number of currently configured consumers in the message middleware through the global configuration container.
[0155] The second acquisition module 63 includes: a message acquisition unit 631, a queue determination unit 632, a current queue unit 633, a number acquisition unit 634, a number determination unit 635, and an end unit 636.
[0156] The message acquisition unit 631 is configured to obtain a target message monitored by the listening container.
[0157] The queue determination unit 632 is configured to determine a target message queue corresponding to the target message.
[0158] The current queue unit 633 is configured to determine the message queue currently in use in the message middleware.
[0159] The number acquisition unit 634 is configured to, if the target message queue is included in the currently used message queue, execute obtaining the target number of consumers corresponding to the target message queue in the message middleware through the global configuration container.
[0160] The number determination unit 635 is configured to determine the target number of consumers as the number of currently configured consumers of the target message queue in the message middleware.
[0161] The end unit 636 is configured to, if the target message queue is not included in the currently used message queue, end adjusting the number of consumers.
[0162] A configuration module 64, configured to adjust the currently configured number of consumers according to the real-time number of consumers through a global configuration container if the real-time number of consumers does not match the currently configured number of consumers.
[0163] The configuration module 64 may include: a first determination unit 641, a first modification unit 642, and a second modification unit 643.
[0164] The first determination unit 641 is configured to determine the maximum number of consumers corresponding to the message middleware when the real-time number of consumers is greater than the currently configured number of consumers.
[0165] The first modification unit 642 is configured to, if the real-time number of consumers exceeds the maximum number of consumers, modify the currently configured number of consumers to the maximum number of consumers through the global configuration container.
[0166] The second modification unit 643 is configured to, if the real-time number of consumers does not exceed the maximum number of consumers, modify the currently configured number of consumers to the real-time number of consumers through the global configuration container.
[0167] The configuration module 64 may further include: a second determination unit 644, a third determination unit 645, a third modification unit 646, and a fourth modification unit 647.
[0168] The second determination unit 644 is configured to determine a target consumer number range corresponding to the real-time number of consumers. The message middleware corresponds to multiple consumer number ranges, and each consumer number range includes multiple consecutive consumer numbers.
[0169] The third determination unit 645 is configured to determine the target number of the target consumer number range.
[0170] The third modification unit 646 is configured to, if the real-time number of consumers is less than or equal to the target number, adjust the currently configured number of consumers to a target consumer number through the global configuration container, where the target consumer number is the sum of the real-time number of consumers and a preset number of consumers.
[0171] The fourth modification unit 647 is configured to, if the real-time number of consumers is greater than the target number, adjust the currently configured number of consumers to the maximum number of the target consumer number range through the global configuration container.
[0172] It should be noted here that the description of the above device embodiments is similar to the description of the above method embodiments and has similar beneficial effects to the method embodiments. For the technical details not disclosed in the device embodiments of the present application, please refer to the description of the method embodiments of the present application for understanding.
[0173] Based on the same inventive concept, an embodiment of the present application further provides an electronic device.
[0174] Figure 7 This is a schematic structural diagram of the electronic device in the embodiments of the present application. Refer to Figure 7 As shown, the electronic device may include: a processor 71, a memory 72, and a bus 73. Among them, the processor 71 and the memory 72 complete mutual communication through the bus 73. The processor 71 is used to call program instructions in the memory 72 to execute the methods in the above one or more embodiments.
[0175] It should be noted here that the description of the above embodiments of the electronic device is similar to the description of the above method embodiments and has similar beneficial effects to those of the method embodiments. For the technical details not disclosed in the embodiments of the electronic device of the present application, please refer to the description of the method embodiments of the present application for understanding.
[0176] Based on the same inventive concept, the embodiments of the present application also provide a computer-readable storage medium, which may include: a stored program. Among them, when the program runs, it controls the device where the storage medium is located to execute the methods in the above one or more embodiments.
[0177] It should be noted here that the description of the above embodiments of the storage medium is similar to the description of the above method embodiments and has similar beneficial effects to those of the method embodiments. For the technical details not disclosed in the embodiments of the storage medium of the present application, please refer to the description of the method embodiments of the present application for understanding.
[0178] The above is only the specific implementation manner of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed in the present application, and all should be covered by the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claimed rights.
Claims
1. A method for scaling capacity based on message middleware, characterized in that: The method is applied to a message middleware, wherein a monitoring container and a global configuration container are pre-injected into the message middleware, wherein the monitoring container is used to monitor the message queue in the message middleware, and the global configuration container is used to obtain the number of consumers currently configured in the message middleware and to perform hot modification on the number of consumers currently configured. The method comprises: Obtaining the total number of messages in the message queue in the message middleware through the monitoring container, and determining the total number of messages as the number of real-time consumers in the message middleware; Obtaining the number of consumers currently configured in the message middleware through the global configuration container; If the number of real-time consumers does not match the number of currently configured consumers, the number of currently configured consumers is adjusted according to the number of real-time consumers through the global configuration container.
2. The method according to claim 1, characterized in that The message middleware includes a plurality of message queues, each message queue is configured with a corresponding number of consumers; the obtaining the number of consumers currently configured in the message middleware through the global configuration container includes: Obtain the target message monitored by the monitoring container; Determine a target message queue corresponding to the target message; Obtaining the number of target consumers configured corresponding to the target message queue in the message middleware through the global configuration container; The target number of consumers is determined as the number of consumers currently configured for the target message queue in the message middleware.
3. The method according to claim 2, characterized in that Before obtaining the number of target consumers corresponding to the target message queue in the message middleware through the global configuration container, the method further includes: Determine the message queue currently in use in the message middleware; If the currently used message queue includes the target message queue, the step of obtaining the number of target consumers corresponding to the target message queue in the message middleware through the global configuration container is executed; If the target message queue is not included in the currently used message queue, the adjustment of the number of consumers is terminated.
4. The method according to any one of claims 1 to 3, characterized in that The acquiring the total number of messages in the message queue in the message middleware through the monitoring container includes: Acquiring, by means of the monitoring container, a first number of messages received and a second number of messages sent by the message middleware within a preset time period, wherein the preset time period is positively correlated with a message processing speed of the message queue; The total number of messages in the message queue in the message middleware is determined based on the first number, the second number, and the number of messages already in the message queue.
5. The method according to any one of claims 1 to 3, characterized in that The adjusting the number of consumers of the current configuration according to the number of real-time consumers through the global configuration container includes: When the number of real-time consumers is greater than the number of currently configured consumers, determining the maximum number of consumers corresponding to the message middleware; If the number of real-time consumers exceeds the maximum number of consumers, modifying the currently configured number of consumers to the maximum number of consumers through the global configuration container; If the number of real-time consumers does not exceed the maximum number of consumers, the currently configured number of consumers is modified to the number of real-time consumers through the global configuration container.
6. The method according to any one of claims 1 to 3, characterized in that The adjusting the number of consumers of the current configuration according to the number of real-time consumers through the global configuration container includes: Determine a target consumer number interval corresponding to the real-time consumer number, the message middleware corresponds to multiple consumer number intervals, and each consumer number interval includes multiple consecutive consumer numbers; Determine a target number for the target consumer number interval; If the number of real-time consumers is less than or equal to the target number, the number of consumers currently configured is adjusted to the target number of consumers through the global configuration container, where the target number of consumers is the sum of the number of real-time consumers and the preset number of consumers; If the number of real-time consumers is greater than the target number, the number of consumers in the current configuration is adjusted to the maximum number of the target consumer range through the global configuration container.
7. The method according to any one of claims 1 to 3, characterized in that The message middleware is also pre-injected with a timing scheduler, and the timing scheduler is connected to the listening container and the global configuration container; the total number of messages in the message queue in the message middleware is obtained through the listening container, including: In response to a start instruction triggered by the timing scheduler according to a preset period, obtaining the total number of messages in the message queue in the message middleware through the monitoring container; Feedback acquisition information to the timing scheduler, where the acquisition information is used to indicate the total number of messages in the message queue in the message middleware that have been acquired; The obtaining the number of consumers currently configured in the message middleware through the global configuration container includes: In response to a continue acquisition instruction triggered by the timing scheduler based on the acquisition information, the number of consumers currently configured in the message middleware is acquired through the global configuration container.
8. A capacity expansion and contraction device based on message middleware, characterized in that: The device is applied to a message middleware, wherein a monitoring container and a global configuration container are pre-injected into the message middleware, wherein the monitoring container is used to monitor the message queue in the message middleware, and the global configuration container is used to obtain the number of consumers currently configured in the message middleware and to perform hot modification on the number of consumers currently configured, and the device comprises: A first acquisition module is used to acquire the total number of messages in the message queue in the message middleware through the monitoring container, and determine the total number of messages as the number of real-time consumers in the message middleware; A second acquisition module, used to acquire the number of consumers currently configured in the message middleware through the global configuration container; A configuration module is used to adjust the number of consumers in the current configuration according to the number of real-time consumers through the global configuration container if the number of real-time consumers does not match the number of consumers in the current configuration.
9. An electronic device, characterized in that: The electronic device comprises: a processor, a memory, and a bus; wherein the processor and the memory communicate with each other via the bus; and the processor is used to call program instructions in the memory to execute the method as claimed in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The storage medium comprises: a stored program; wherein, when the program is running, the device where the storage medium is located is controlled to execute the method as claimed in any one of claims 1 to 7.