Consumption method and electronic device based on message queue implemented in multiple computer rooms
By realizing distributed message queue consumption in a multi-computer room environment, the consumer side queries multiple computer rooms to obtain message data based on the queue identification, solving the problem of synchronous switching of the consumer side caused by message production side switching, and achieving efficient and reliable message consumption.
Patent Information
- Application Number
- CN202010906376.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-09-01
- Publication Date
- 2025-02-28
- Estimated Expiration
- 2040-09-01
Smart Images

Figure CN112068972B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computers, and in particular to a message queue consumption method and electronic equipment based on multi-computer room implementation. Background Art
[0002] The message queue is used to store data to be transmitted in the queue. The business end that writes data to the queue is called the message producer, and the business end that reads data from the queue is called the message consumer. The message queue can realize the orderly storage of multiple message data, which is conducive to the reliable transmission of messages. With the increasing complexity of business scenarios, many business systems contain multiple computer rooms. In the implementation of multiple computer rooms, in order to ensure that the message consumer can consume reliably, the message producer and the message consumer need to be deployed in the same computer room.
[0003] However, in actual business scenarios, the message production end may switch between computer rooms. For example, a message production end switches from computer room A to computer room B. Before the switching operation is performed, the message queue produced by the message production end is located in computer room A. After the switching operation is performed, the message queue produced by the message production end is located in computer room B. Accordingly, before the switching operation is performed, the message consumption end corresponding to the message production end is located in computer room A; after the switching operation is performed, the message consumption end corresponding to the message production end also needs to be switched to computer room B.
[0004] However, in the process of implementing the present invention, the inventors found that the above-mentioned scheme in the prior art has at least the following defects: on the one hand, after the message production end switches the computer room, the message consumption end needs to switch synchronously with the message production end, which makes the operation cumbersome; on the other hand, after the message consumption end switches synchronously with the message production end, it will consume through the switched computer room. However, in actual situations, since the production operation and the consumption operation are often not synchronized, when the consumption operation lags behind the production operation, it will cause the message data that has not been consumed to remain in the computer room before the switching, thus causing the data loss problem. Summary of the invention
[0005] In view of the above problems, the present invention is proposed to provide a consumption method and electronic device based on a message queue implemented in multiple computer rooms, which overcome the above problems or at least partially solve the above problems.
[0006] According to one aspect of the present invention, a method for consuming a message queue based on multiple computer rooms is provided, comprising:
[0007] When any one of the multiple computer rooms receives a message write request, the message data contained in the message write request is written into a message queue corresponding to the computer room that receives the message write request;
[0008] When any of the multiple computer rooms receives a message consumption request, the queue identifier of the message queue to be consumed contained in the message consumption request is obtained, the computer room where the message queue matching the queue identifier is located among the multiple computer rooms is determined as the target computer room, and the message data of the message queue corresponding to the queue identifier is obtained from the target computer room for consumption.
[0009] According to another aspect of the present invention, there is provided an electronic device, comprising: a processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other via the communication bus;
[0010] The memory is used to store at least one executable instruction, and the executable instruction enables the processor to perform the following operations:
[0011] When any one of the multiple computer rooms receives a message write request, the message data contained in the message write request is written into a message queue corresponding to the computer room that receives the message write request;
[0012] When any of the multiple computer rooms receives a message consumption request, the queue identifier of the message queue to be consumed contained in the message consumption request is obtained, the computer room where the message queue matching the queue identifier is located among the multiple computer rooms is determined as the target computer room, and the message data of the message queue corresponding to the queue identifier is obtained from the target computer room for consumption.
[0013] According to another aspect of the present invention, a computer storage medium is provided, wherein the storage medium stores at least one executable instruction, and the executable instruction enables the processor to perform the following operations:
[0014] When any one of the multiple computer rooms receives a message write request, the message data contained in the message write request is written into a message queue corresponding to the computer room that receives the message write request;
[0015] When any of the multiple computer rooms receives a message consumption request, the queue identifier of the message queue to be consumed contained in the message consumption request is obtained, the computer room where the message queue matching the queue identifier is located among the multiple computer rooms is determined as the target computer room, and the message data of the message queue corresponding to the queue identifier is obtained from the target computer room for consumption.
[0016] In the consumption method and electronic device of the message queue based on multi-computer room implementation provided by the present invention, the message data generated by the message production end is directly written into the computer room where the message production end is located; in addition, when the message consumption end consumes data, the computer room where the message consumption end is located determines the computer room where the message queue matching the queue identifier is located in multiple computer rooms as the target computer room according to the queue identifier of the message queue to be consumed contained in the message consumption request, and obtains the message data of the message queue corresponding to the queue identifier from the target computer room for consumption. It can be seen that in the consumption process, the computer room where the message queue to be consumed is located can be queried from multiple computer rooms according to the queue identifier of the message queue to be consumed, so as to obtain the corresponding message data. This method can actively query the data required by the consumer end from multiple computer rooms during the consumption process, so that the consumer end can consume without following the production end to switch computer rooms, and can effectively prevent the problem of data omission caused by consumption lag.
[0017] The above description is only an overview of the technical solution of the present invention. In order to more clearly understand the technical means of the present invention, it can be implemented according to the contents of the specification. In order to make the above and other purposes, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the detailed description of the preferred embodiments below. The accompanying drawings are only for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the present invention. Moreover, the same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings:
[0019] Figure 1 A flowchart of a message queue consumption method based on multi-computer room implementation provided by an embodiment of the present invention is shown;
[0020] Figure 2 A flowchart of a message queue consumption method based on multiple computer rooms provided by another embodiment of the present invention is shown;
[0021] Figure 3 A schematic structural diagram of an electronic device according to another embodiment of the present invention is shown. DETAILED DESCRIPTION
[0022] The exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.
[0023] Embodiment 1
[0024] Figure 1 FIG. 1 is a flowchart of a method for consuming a message queue based on multiple computer rooms provided by an embodiment of the present invention. Figure 1 As shown, the method comprises the following steps:
[0025] Step S110: When any one of the multiple computer rooms receives a message write request, the message data contained in the message write request is written into a message queue corresponding to the computer room that receives the message write request.
[0026] Each computer room corresponds to one or more services. A service may correspond to a project or an application, or may correspond to a function in an application, which is not limited in the present invention. The service corresponding to each computer room may be a message production end or a message consumption end, or may be a message production end and a message consumption end at the same time, depending on the business function currently executed by the service.
[0027] When a service is used to generate message data, the service, as a message production end, sends a message write request to the computer room corresponding to the service. When any computer room receives a message write request from the service of this computer room, the message data contained in the message write request is written into the message queue corresponding to the computer room. It can be seen that after any computer room receives a message write request, it can directly write the received message data into the message queue corresponding to the computer room. Among them, the message queue corresponding to the computer room refers to: a message queue stored in the storage space corresponding to the computer room. Among them, the storage space corresponding to the computer room can be a storage space local to the computer room, or it can be a storage space in a database connected to the computer room. Specifically, the message queue corresponding to the computer room can be maintained by the queue server in the computer room.
[0028] It can be seen that in this embodiment, regardless of whether the message production end switches the computer room, it only needs to write the message queue in the computer room where the message production end is currently located. For example, assuming that the message production end is originally located in computer room A, computer room A is responsible for writing the generated message data into the message queue in computer room A. When the message production end switches to computer room B, computer room B is responsible for writing the generated message data into the message queue in computer room B.
[0029] Step S120: When any of the multiple computer rooms receives a message consumption request, the queue identifier of the message queue to be consumed contained in the message consumption request is obtained, the computer room where the message queue matching the queue identifier is located among the multiple computer rooms is determined as the target computer room, and the message data of the message queue corresponding to the queue identifier is obtained from the target computer room for consumption.
[0030] Since each computer room corresponds to one or more services, when a service is used to consume message data, the service, as a message consumer, sends a message consumption request to the computer room corresponding to the service. After any computer room receives a message consumption request from the service of this computer room, it needs to obtain the queue identifier of the message queue to be consumed contained in the message consumption request, query the corresponding computer room based on the queue identifier and obtain the data.
[0031] Specifically, the computer room where the message queue matching the queue identifier is located among the multiple computer rooms is determined as the target computer room, and the message data of the message queue corresponding to the queue identifier is obtained from the target computer room for consumption. There are many ways to determine the target computer room. For example, a computer room can be randomly selected from multiple computer rooms and try to obtain data until the acquisition is successful. The queue identifier of the message queue to be consumed contained in the message consumption request is used to identify the data content to be consumed, which can be the key of the message queue or the name of the message queue.
[0032] It can be seen that in the consumption method of the message queue based on multiple computer rooms provided by the present invention, the computer room where the message queue to be consumed is located can be queried from multiple computer rooms according to the queue identifier of the message queue to be consumed during the consumption process, thereby obtaining the corresponding message data. This method can actively query the data required by the consumer end from multiple computer rooms during the consumption process, so that the consumer end can consume without following the production end to switch computer rooms, and can effectively prevent data omission problems caused by consumption lags.
[0033] Embodiment 2
[0034] Figure 2 FIG. 2 is a flowchart of a method for consuming a message queue based on multiple computer rooms provided by another embodiment of the present invention. Figure 2 As shown, the method comprises the following steps:
[0035] Step S210: Setting up proxy modules in each computer room respectively.
[0036] Specifically, a proxy module is set in each of the multiple computer rooms, and the proxy module inside each computer room is used to process the message writing request and message consumption request from each service. In specific implementation, the proxy module of each computer room is used to implement the processing of the message writing request and message consumption request sent by each service based on the extended protocol, and in the processing process, the queue identifier of the message queue to be consumed is obtained by parsing the message content to determine the target computer room to obtain data.
[0037] The proxy modules in each computer room can realize data interaction and sharing, thereby realizing interconnection and intercommunication between multiple computer rooms through the proxy modules of each computer room. Specifically, the proxy module can also be called a proxy component or a proxy element, which can be realized by software programming or hardware, and the present invention does not limit this.
[0038] It should be noted that this step is an optional step. In other embodiments of the present invention, the proxy module may not be set, and the above functions may be maintained by modifying the internal source code of the computer room. The present invention does not limit the specific implementation details.
[0039] Step S220: When any one of the multiple computer rooms receives a message write request, the message data included in the message write request is written into a message queue corresponding to the computer room that receives the message write request.
[0040] Each computer room corresponds to one or more services. A service may correspond to a project or an application, or may correspond to a function in an application, which is not limited in the present invention. The service corresponding to each computer room may be a message production end or a message consumption end, or may be a message production end and a message consumption end at the same time, depending on the business function currently executed by the service.
[0041] When a service is used to generate message data, the service, as a message production end, sends a message write request to the computer room corresponding to the service. When any computer room receives a message write request from the service of this computer room, the message data contained in the message write request is written into the message queue corresponding to the computer room. It can be seen that after any computer room receives a message write request, it can directly write the received message data into the message queue corresponding to the computer room. Among them, the message queue corresponding to the computer room refers to: a message queue stored in the storage space corresponding to the computer room. Among them, the storage space corresponding to the computer room can be a storage space local to the computer room, or it can be a storage space in a database connected to the computer room. Specifically, the message queue corresponding to the computer room can be maintained by the queue server in the computer room.
[0042] It can be seen that in this embodiment, regardless of whether the message production end switches the computer room, it only needs to write the message queue in the computer room where the message production end is currently located. For example, assuming that the message production end is originally located in computer room A, computer room A is responsible for writing the generated message data into the message queue in computer room A. When the message production end switches to computer room B, computer room B is responsible for writing the generated message data into the message queue in computer room B.
[0043] Step S230: When any of the multiple computer rooms receives a message consumption request, the queue identifier of the message queue to be consumed contained in the message consumption request is obtained, the computer room where the message queue matching the queue identifier is located among the multiple computer rooms is determined as the target computer room, and the message data of the message queue corresponding to the queue identifier is obtained from the target computer room for consumption.
[0044] Since each computer room corresponds to one or more services, when a service is used to consume message data, the service, as a message consumer, sends a message consumption request to the computer room corresponding to the service. After any computer room receives the message consumption request sent by the service of this computer room, it needs to obtain the queue identifier of the message queue to be consumed contained in the message consumption request, query the corresponding computer room according to the queue identifier and obtain the data. Specifically, the computer room where the message queue matching the queue identifier is located among multiple computer rooms is determined as the target computer room, and the message data of the message queue corresponding to the queue identifier is obtained from the target computer room for consumption. There are many ways to determine the target computer room. For example, a computer room can be randomly selected from multiple computer rooms and try to obtain data until the acquisition is successful. The queue identifier of the message queue to be consumed contained in the message consumption request is used to identify the data content to be consumed, which can be the key of the message queue or the name of the message queue.
[0045] In this embodiment, the target computer room can be determined in multiple ways:
[0046] In one implementation, a computer room is selected from multiple computer rooms as a candidate computer room; if a message queue matching the queue identifier exists in the candidate computer room, the candidate computer room is determined as a target computer room, and an available type of data prompt identifier is added to the candidate computer room; if a message queue matching the queue identifier does not exist in the candidate computer room, a non-available type of data prompt identifier is added to the candidate computer room, and a new computer room is selected from multiple computer rooms as a candidate computer room.
[0047] It can be seen that in this method, the computer room where the message queue matching the queue identifier is located is queried in a tentative manner, and during the query process, the data prompt identifier of each computer room is dynamically updated according to the query results of each computer room, so as to facilitate the next query process. Among them, an available type of data prompt identifier is set for the computer room where the message queue matching the queue identifier is located, so that the computer room is queried first in the next query process; a non-available type of data prompt identifier is set for the computer room where the message queue matching the queue identifier is located, so that the computer room is avoided in the next query process.
[0048] Accordingly, when selecting a computer room from multiple computer rooms as a candidate computer room, a computer room with a data prompt identifier of an available type is selected as the candidate computer room according to the type of the data prompt identifier of each computer room. In addition, when there are multiple computer rooms with data prompt identifiers of an available type, a computer room with a data prompt identifier of an available type can be randomly selected as the candidate computer room.
[0049] In addition, considering that some computer rooms may be temporarily inaccessible due to network reasons, in order to avoid the query time-consuming problem caused by this, in this embodiment, a network detection tool can be further used to detect whether each computer room is in an available state, and a computer room can be selected from multiple computer rooms in an available state as a candidate computer room. For example, a timer can be set in each computer room, and a ping command can be sent to each computer room through the timer to determine whether each computer room is currently available, and the candidate computer room is selected only from the available computer rooms.
[0050] In addition, the inventor discovered in the process of implementing the present invention that the following problems may occur when only setting data prompt identifiers for computer rooms: Assume that data about the message queue of key1 is stored in computer room A, and data about the message queue of key2 is stored in computer room B. If the queue identifier contained in the first received message consumption request is key1, then after querying, an available type of data prompt identifier is set for computer room A, and / or a non-available type of data prompt identifier is set for computer room B. However, if the queue identifier contained in the second received message consumption request is key2, at this time, computer room A will be queried first based on the data prompt identifiers of each computer room, but at this time, the data with the queue identifier of key2 is located in computer room B, resulting in inaccurate data prompt identifiers.
[0051] In order to solve the above problem, in this embodiment, the data prompt identifier is further divided into: a plurality of data prompt sub-identifiers corresponding to different queue identifiers; accordingly, when adding a data prompt identifier of an available type for a candidate computer room, a data prompt sub-identifier of an available type corresponding to the queue identifier of the message queue to be consumed is added to the candidate computer room; and when adding a data prompt identifier of a non-available type for a candidate computer room, a data prompt sub-identifier of a non-available type corresponding to the queue identifier of the message queue to be consumed is added to the candidate computer room. It can be seen that this embodiment can set the data prompt identifier as a fine-grained prompt identifier, for example, the data prompt identifier is set at the granularity of the queue identifier of the message queue to be consumed.
[0052] Accordingly, when selecting a computer room with a data prompt identifier of an available type as a candidate computer room based on the type of the data prompt identifier of each computer room, the candidate computer room is further selected based on whether the type of the data prompt sub-identifier of the queue identifier of the message queue to be consumed contained in the message consumption request received this time corresponding to each computer room is an available type, thereby improving the selection efficiency of the candidate computer room.
[0053] In addition, considering that the data status of each computer room changes dynamically, after adding a non-available type of data prompt identifier to a candidate computer room, a validity period (e.g., 5 to 10 seconds) of the non-available type of data prompt identifier is further set to ensure that each computer room can be queried in a timely manner. Accordingly, when the validity period of the non-available type of data prompt identifier expires, the non-available type of data prompt identifier added to the computer room is deleted. Alternatively, when selecting a computer room with an available type of data prompt identifier as a candidate computer room according to the type of the data prompt identifier of each computer room, the computer room with an available type of data prompt identifier can be further selected as a candidate computer room in combination with the validity period of the non-available type of data prompt identifier.
[0054] The steps in the method of this embodiment are performed by the above-mentioned proxy module. When the proxy module in any computer room receives a network request, the type of the network request is determined according to the parameters contained in the network request. The types of network requests mainly include: message writing type, message consumption type and statistical type.
[0055] When a message write request is received according to the type of network request, the proxy module is used to write the message data into the message queue corresponding to the computer room. It can be seen that for the message write request, it can be directly written to the local computer room. In other words, when a message write request is received, the proxy module determines that the execution strategy corresponding to the message write request is: execution in the computer room, and accordingly, only forwards data to the database (such as redis server) in the computer room.
[0056] When it is determined according to the type of network request that a message consumption request is received, the proxy module is used to query the computer room corresponding to the message consumption request from multiple computer rooms, and provide feedback based on the query results. It can be seen that for a message consumption request, one computer room is selected from multiple computer rooms to obtain data, which can be selected randomly or according to other strategies. That is to say, when a message consumption request is received, the proxy module determines that the execution strategy corresponding to the message consumption request is: randomly select a computer room to execute, specifically, from the computer room list, a random computer room executes the command, if the execution is successful and there is data returned, it returns directly, if the return is empty or the execution fails, continue to select a computer room from the remaining computer rooms to execute the command until the data is successfully obtained.
[0057] When it is determined that a statistical request has been received based on the type of network request, the proxy module is used to obtain the data content associated with the statistical request in each computer room respectively, and determine the statistical results based on the data content obtained from multiple computer rooms. For example, when a statistical request for key1 is received, the length of the message queue corresponding to key1 contained in each computer room is obtained respectively, and the statistical result can be obtained by adding the results of each computer room, thereby determining the total length of the message queue corresponding to key1. In other words, when a message consumption request is received, the proxy module determines that the execution strategy corresponding to the statistical request is: execute for all computer rooms at the same time, specifically, execute in parallel for all computer rooms, then merge the various results returned by all computer rooms, and finally return the merged results to the client, which is mainly used for statistical length.
[0058] In this embodiment, each service can be a message producer or a message consumer, and the same service can be a message producer and a message consumer in sequence. Accordingly, the current role of the service needs to be determined through the command parameters included in the network request.
[0059] For ease of understanding, a specific example is given below. When any computer room receives a message consumption request, first, the key value contained in the message consumption request is obtained, and then several computer rooms that are currently in an available state are determined from multiple computer rooms, which can be determined specifically through the ping command. Next, for each computer room that is in an available state, a computer room is randomly selected as a candidate computer room, and it is determined whether the data prompt identifier of the candidate computer room is an available type. If the data prompt identifier of the candidate computer room is an available type, it is queried whether there is corresponding data in the candidate computer room; if the data prompt identifier of the candidate computer room is an unavailable type, it is further determined whether the prompt identifier of the unavailable type is within the validity period (that is, whether the interval between the current time and the last request time is less than the preset threshold). If so, the computer room is excluded and other computer rooms are selected.
[0060] In addition, in this embodiment, it is further detected whether there is a jitter in the dual-machine room dedicated line between any two of the multiple machine rooms. The so-called jitter in the dual-machine room dedicated line means that the network jitter occurs in the machine room dedicated line connecting the two machine rooms, which causes the data transmitted through the machine room dedicated line to be temporarily unreachable. When the jitter of the dual-machine room dedicated line is detected, both machine rooms are downgraded to an unavailable state, that is, the data prompt identifiers of the two machine rooms connected by the jittering machine room dedicated line are set to the unavailable type, thereby avoiding the failure of obtaining data due to network jitter.
[0061] In addition, in a specific implementation method, each computer room in this embodiment stores the message queue through the Redis database. Among them, the Redis database stores the message queue in the memory, and once the data in the message queue is consumed, the corresponding content in the memory is deleted. Therefore, in the above scenario, a consumption request must correspond to a message data. If a consumption request corresponds to multiple message data, it will cause the redundant data to be deleted by mistake. Therefore, when any computer room receives a message consumption request, if the data corresponding to the message consumption request is obtained from multiple computer rooms at the same time, multiple data may be obtained at the same time, resulting in the data in the memory being deleted by mistake. In order to solve this problem, in this embodiment, it is implemented by randomly selecting a computer room from multiple computer rooms to obtain data, thereby ensuring that only one piece of data is deleted each time a consumption request is received, and there will be no problem of redundant data being deleted by mistake.
[0062] In addition, it should be noted that the method in this embodiment can solve the problem of incomplete message consumption caused by the message production end switching the computer room. For example, suppose the message production end is originally located in computer room A, and the 1st to 50th data are produced in computer room A. Correspondingly, the message consumption end corresponding to the message production end is also located in computer room A, responsible for consuming the produced data. Then, the message production end switches to computer room B, and continues to produce the 51st to 200th data in computer room B. In the traditional method, the message consumption end corresponding to the message production end needs to be switched to computer room B synchronously so as to continue to consume the newly produced messages from computer room B. However, since the consumption process often lags behind the production process, assuming that when the message production end and the message consumption end switch computer rooms at the same time, the message consumption end only consumes the 40th data, then there are still 41st to 50th data in computer room A that have not been consumed. That is: there are still 10 unconsumed data in computer room A. However, since the message consumption end has switched to computer room B with the message production end, the remaining 10 data in computer room A cannot be consumed. However, the above-mentioned problem can be completely solved through the method in the present invention. In the embodiment of the present invention, the consumer end does not need to switch the computer room with the producer end. That is to say, after the message production end switches to computer room B, the message consumption end is still located in computer room A, and consumption is performed through the proxy module in computer room A. Correspondingly, when the proxy module in computer room A receives a message consumption request, it queries computer room A and computer room B at the same time, determines whether the data to be consumed is located in computer room A or computer room B according to the query results, and obtains the data from the corresponding computer room for consumption. It can be seen that in this method, since the proxy module in any computer room will query each computer room separately, it can ensure that the data in any computer room is completely consumed without omissions.
[0063] In summary, in the consumption method of the message queue based on multi-computer room implementation provided by the present invention, during the consumption process, the computer room where the message queue to be consumed is located can be queried from multiple computer rooms according to the queue identifier of the message queue to be consumed, thereby obtaining the corresponding message data. This method can actively query the data required by the consumer end from multiple computer rooms during the consumption process, so that the consumer end can consume without following the production end to switch computer rooms, and can effectively prevent data omissions caused by consumption lags. In addition, this method can set data prompt identifiers for each computer room, thereby improving the speed and accuracy of obtaining data next time.
[0064] Embodiment 3
[0065] An embodiment of the present application provides a non-volatile computer storage medium, which stores at least one executable instruction. The computer executable instruction can execute the message queue consumption method based on multi-computer room implementation in any of the above method embodiments.
[0066] The executable instructions may be used to cause the processor to perform the following operations:
[0067] When any one of the multiple computer rooms receives a message write request, the message data contained in the message write request is written into a message queue corresponding to the computer room that receives the message write request;
[0068] When any of the multiple computer rooms receives a message consumption request, the queue identifier of the message queue to be consumed contained in the message consumption request is obtained, the computer room where the message queue matching the queue identifier is located among the multiple computer rooms is determined as the target computer room, and the message data of the message queue corresponding to the queue identifier is obtained from the target computer room for consumption.
[0069] In an optional implementation, the executable instructions are used to cause the processor to perform the following operations:
[0070] Select a computer room from multiple computer rooms as a candidate computer room;
[0071] If a message queue matching the queue identifier exists in the candidate computer room, the candidate computer room is determined as a target computer room, and a data prompt identifier of an available type is added to the candidate computer room;
[0072] If there is no message queue matching the queue identifier in the candidate computer room, a data prompt identifier of a non-available type is added to the candidate computer room, and a computer room is reselected from multiple computer rooms as the candidate computer room.
[0073] In an optional implementation, the executable instructions are used to cause the processor to perform the following operations:
[0074] According to the types of data prompt identifiers of various computer rooms, computer rooms with data prompt identifiers of available types are selected as candidate computer rooms.
[0075] In an optional implementation, the executable instructions are used to cause the processor to perform the following operations:
[0076] When there are multiple computer rooms with data prompt identifiers of available types, a computer room with data prompt identifiers of available types is randomly selected as a candidate computer room.
[0077] In an optional implementation, the executable instructions are used to cause the processor to perform the following operations:
[0078] A network detection tool is used to detect whether each computer room is in an available state, and a computer room is selected from multiple computer rooms in an available state as a candidate computer room.
[0079] In an optional implementation, the data prompt identifier further includes: a plurality of data prompt sub-identifiers corresponding to different queue identifiers respectively;
[0080] The executable instructions are used to cause the processor to perform the following operations:
[0081] Adding a data prompt sub-identifier of an available type corresponding to the queue identifier of the message queue to be consumed to the candidate computer room;
[0082] A non-available data prompt sub-identifier corresponding to the queue identifier of the message queue to be consumed is added to the candidate computer room.
[0083] In an optional implementation, the executable instructions are used to cause the processor to perform the following operations:
[0084] Setting the validity period of the non-usable data prompt identifier;
[0085] Wherein, when the validity period of the non-usable data prompt identifier expires, the non-usable data prompt identifier added for the computer room is deleted; or,
[0086] The selecting a computer room with a data prompt identifier of an available type as a candidate computer room according to the type of the data prompt identifier of each computer room includes: selecting a computer room with a data prompt identifier of an available type as a candidate computer room in combination with the validity period of the data prompt identifier of a non-available type.
[0087] In an optional implementation, the executable instructions are used to cause the processor to perform the following operations:
[0088] An agent module is set in each computer room respectively, and the above steps are executed by the agent module;
[0089] Among them, when the proxy module in any computer room receives a network request, the type of the network request is determined according to the parameters contained in the network request; when it is determined according to the type of network request that a message write request is received, the proxy module is used to write the message data into the message queue corresponding to the computer room; when it is determined according to the type of network request that a statistical request is received, the proxy module is used to respectively obtain the data content associated with the statistical request in each computer room, and determine the statistical results based on the data content obtained from multiple computer rooms.
[0090] Embodiment 4
[0091] Figure 3 A schematic structural diagram of an electronic device according to another embodiment of the present invention is shown. The specific embodiment of the present invention does not limit the specific implementation of the electronic device.
[0092] like Figure 3 As shown, the electronic device may include: a processor (processor) 302 , a communication interface (Communications Interface) 304 , a memory (memory) 306 , and a communication bus 308 .
[0093] The processor 302, the communication interface 304, and the memory 306 communicate with each other via the communication bus 308. The communication interface 304 is used to communicate with other devices such as a client or other server network elements. The processor 302 is used to execute the program 310, which can specifically execute the relevant steps in the above-mentioned embodiment of the message queue consumption method based on multiple computer rooms.
[0094] Specifically, the program 310 may include program codes, which include computer operation instructions.
[0095] The processor 302 may be a central processing unit (CPU), or an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present invention. The one or more processors included in the electronic device may be processors of the same type, such as one or more CPUs; or processors of different types, such as one or more CPUs and one or more ASICs.
[0096] The memory 306 is used to store the program 310. The memory 306 may include a high-speed RAM memory, and may also include a non-volatile memory (non-volatile memory), such as at least one disk memory.
[0097] The program 310 may be specifically configured to enable the processor 302 to perform the following operations:
[0098] When any one of the multiple computer rooms receives a message write request, the message data contained in the message write request is written into a message queue corresponding to the computer room that receives the message write request;
[0099] When any of the multiple computer rooms receives a message consumption request, the queue identifier of the message queue to be consumed contained in the message consumption request is obtained, the computer room where the message queue matching the queue identifier is located among the multiple computer rooms is determined as the target computer room, and the message data of the message queue corresponding to the queue identifier is obtained from the target computer room for consumption.
[0100] In an optional implementation, the executable instructions are used to cause the processor to perform the following operations:
[0101] Select a computer room from multiple computer rooms as a candidate computer room;
[0102] If a message queue matching the queue identifier exists in the candidate computer room, the candidate computer room is determined as a target computer room, and a data prompt identifier of an available type is added to the candidate computer room;
[0103] If there is no message queue matching the queue identifier in the candidate computer room, a data prompt identifier of a non-available type is added to the candidate computer room, and a computer room is reselected from multiple computer rooms as the candidate computer room.
[0104] In an optional implementation, the executable instructions are used to cause the processor to perform the following operations:
[0105] According to the types of data prompt identifiers of various computer rooms, computer rooms with data prompt identifiers of available types are selected as candidate computer rooms.
[0106] In an optional implementation, the executable instructions are used to cause the processor to perform the following operations:
[0107] When there are multiple computer rooms with data prompt identifiers of available types, a computer room with data prompt identifiers of available types is randomly selected as a candidate computer room.
[0108] In an optional implementation, the executable instructions are used to cause the processor to perform the following operations:
[0109] A network detection tool is used to detect whether each computer room is in an available state, and a computer room is selected from multiple computer rooms in an available state as a candidate computer room.
[0110] In an optional implementation, the data prompt identifier further includes: a plurality of data prompt sub-identifiers corresponding to different queue identifiers respectively;
[0111] The executable instructions are used to cause the processor to perform the following operations:
[0112] Adding a data prompt sub-identifier of an available type corresponding to the queue identifier of the message queue to be consumed to the candidate computer room;
[0113] A non-available data prompt sub-identifier corresponding to the queue identifier of the message queue to be consumed is added to the candidate computer room.
[0114] In an optional implementation, the executable instructions are used to cause the processor to perform the following operations:
[0115] Setting the validity period of the non-usable data prompt identifier;
[0116] Wherein, when the validity period of the non-usable data prompt identifier expires, the non-usable data prompt identifier added for the computer room is deleted; or,
[0117] The selecting a computer room with a data prompt identifier of an available type as a candidate computer room according to the type of the data prompt identifier of each computer room includes: selecting a computer room with a data prompt identifier of an available type as a candidate computer room in combination with the validity period of the data prompt identifier of a non-available type.
[0118] In an optional implementation, the executable instructions are used to cause the processor to perform the following operations:
[0119] An agent module is set in each computer room respectively, and the above steps are executed by the agent module;
[0120] Among them, when the proxy module in any computer room receives a network request, the type of the network request is determined according to the parameters contained in the network request; when it is determined according to the type of network request that a message write request is received, the proxy module is used to write the message data into the message queue corresponding to the computer room; when it is determined according to the type of network request that a statistical request is received, the proxy module is used to respectively obtain the data content associated with the statistical request in each computer room, and determine the statistical results based on the data content obtained from multiple computer rooms.
[0121] The algorithm and display provided herein are not inherently related to any particular computer, virtual system or other device. Various general purpose systems can also be used together with the teachings based on this. According to the above description, it is obvious that the structure required for constructing such systems. In addition, the present invention is not directed to any specific programming language either. It should be understood that various programming languages can be utilized to realize the content of the present invention described herein, and the description of the above specific languages is for disclosing the best mode of the present invention.
[0122] In the description provided herein, a large number of specific details are described. However, it is understood that embodiments of the present invention can be practiced without these specific details. In some instances, well-known methods, structures and techniques are not shown in detail so as not to obscure the understanding of this description.
[0123] Similarly, it should be understood that in order to streamline the present disclosure and aid in understanding one or more of the various inventive aspects, in the above description of exemplary embodiments of the present invention, various features of the present invention are sometimes grouped together into a single embodiment, figure, or description thereof. However, this disclosed method should not be interpreted as reflecting the intention that the claimed invention requires more features than those explicitly recited in each claim. More specifically, as reflected in the claims below, inventive aspects lie in less than all the features of the individual embodiments disclosed above. Therefore, the claims that follow the specific embodiment are hereby expressly incorporated into the specific embodiment, with each claim itself serving as a separate embodiment of the present invention.
[0124] Those skilled in the art will appreciate that the modules in the devices in the embodiments may be adaptively changed and arranged in one or more devices different from the embodiments. The modules or units or components in the embodiments may be combined into one module or unit or component, and in addition they may be divided into a plurality of submodules or subunits or subcomponents. Except that at least some of such features and / or processes or units are mutually exclusive, all features disclosed in this specification (including the accompanying claims, abstracts and drawings) and all processes or units of any method or device disclosed in this manner may be combined in any combination. Unless otherwise expressly stated, each feature disclosed in this specification (including the accompanying claims, abstracts and drawings) may be replaced by an alternative feature providing the same, equivalent or similar purpose.
[0125] In addition, those skilled in the art will appreciate that, although some embodiments herein include certain features included in other embodiments but not other features, the combination of features of different embodiments is meant to be within the scope of the present invention and form different embodiments. For example, in the claims below, any one of the claimed embodiments may be used in any combination.
[0126] It should be noted that the above embodiments illustrate the present invention rather than limit it, and that those skilled in the art may devise alternative embodiments without departing from the scope of the appended claims. In the claims, any reference symbol between brackets shall not be construed as a limitation on the claims. The word "comprising" does not exclude the presence of elements or steps not listed in the claims. The word "one" or "an" preceding an element does not exclude the presence of a plurality of such elements. The present invention may be implemented by means of hardware comprising a number of different elements and by means of a suitably programmed computer. In a unit claim enumerating a number of devices, several of these devices may be embodied by the same hardware item. The use of the words first, second, and third, etc., does not indicate any order. These words may be interpreted as names.
Claims
1. A consumption method of a message queue based on multiple computer rooms, comprising: A proxy module is respectively set in each computer room, wherein when the proxy module in any computer room receives a network request, the type of the network request is determined according to the parameters contained in the network request; When it is determined according to the type of the network request that a message writing request is received, the proxy module is used to write the message data contained in the message writing request into the message queue corresponding to the computer room; When it is determined according to the type of the network request that a message consumption request is received, the proxy module is used to obtain a queue identifier of a message queue to be consumed contained in the message consumption request, determine a computer room where a message queue matching the queue identifier is located among multiple computer rooms as a target computer room, and obtain message data of the message queue corresponding to the queue identifier from the target computer room for consumption; When it is determined according to the type of network request that a statistical request is received, the proxy module is used to respectively obtain data content associated with the statistical request in each computer room, and determine the statistical result according to the obtained data content from multiple computer rooms.
2. The method according to claim 1, wherein: The step of determining the computer room where the message queue matching the queue identifier is located among the multiple computer rooms as the target computer room comprises: Select a computer room from multiple computer rooms as a candidate computer room; If a message queue matching the queue identifier exists in the candidate computer room, the candidate computer room is determined as a target computer room, and a data prompt identifier of an available type is added to the candidate computer room; If there is no message queue matching the queue identifier in the candidate computer room, a data prompt identifier of a non-available type is added to the candidate computer room, and a computer room is reselected from multiple computer rooms as the candidate computer room.
3. The method according to claim 2, wherein: The selecting a computer room from multiple computer rooms as a candidate computer room comprises: According to the types of data prompt identifiers of various computer rooms, computer rooms with data prompt identifiers of available types are selected as candidate computer rooms.
4. The method according to claim 3, wherein: The selecting a computer room with a data prompt identifier of an available type as a candidate computer room comprises: When there are multiple computer rooms with data prompt identifiers of available types, a computer room with data prompt identifiers of available types is randomly selected as a candidate computer room.
5. The method according to any one of claims 2 to 4, wherein: The selecting a computer room from multiple computer rooms as a candidate computer room comprises: A network detection tool is used to detect whether each computer room is in an available state, and a computer room is selected from multiple computer rooms in an available state as a candidate computer room.
6. The method according to any one of claims 2 to 4, wherein: The data prompt identifier further includes: a plurality of data prompt sub-identifiers corresponding to different queue identifiers respectively; Then, the step of adding a data prompt identifier of an available type to the candidate computer room includes: adding a data prompt sub-identifier of an available type corresponding to the queue identifier of the message queue to be consumed to the candidate computer room; And the adding of a non-available type of data prompt identifier for the candidate computer room includes: adding a non-available type of data prompt sub-identifier corresponding to the queue identifier of the message queue to be consumed for the candidate computer room.
7. The method according to any one of claims 3-4, wherein: After adding the data prompt mark of the non-available type to the candidate computer room, the method further includes: setting the validity period of the data prompt mark of the non-available type; The method further comprises: when the validity period of the non-usable data prompt identifier expires, deleting the non-usable data prompt identifier added for the computer room; or The selecting a computer room with a data prompt identifier of an available type as a candidate computer room according to the type of the data prompt identifier of each computer room includes: selecting a computer room with a data prompt identifier of an available type as a candidate computer room in combination with the validity period of the data prompt identifier of a non-available type.
8. An electronic device comprising: A processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other via the communication bus; The memory is used to store at least one executable instruction, and the executable instruction enables the processor to execute any one of the methods according to claims 1-7.
9. A computer storage medium, wherein at least one executable instruction is stored in the storage medium, and the executable instruction enables a processor to execute the method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Data sending method and device and server
CN108347477A
Message consumption method and device, storage medium and electronic equipment
CN110740145A