A method and device for managing message queues based on Go language

By obtaining and loading queue cluster information in Go language and using the load balancing module to start the queue cluster, the problem of low message queue startup efficiency in Go language is solved, and efficient multi-threaded concurrency and reducing server load is achieved.

CN114416311BActive Publication Date: 2025-02-11CHINA TELECOM CORP LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111665664.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-30
Publication Date
2025-02-11
Estimated Expiration
2041-12-30

AI Technical Summary

Technical Problem

The Go language lacks a framework suitable for RabbitMq message queue, which leads to low startup efficiency of message queues and increases the overall load of the server.

Method used

By obtaining and loading queue cluster information, including consumer and producer information, to Go language files, and starting the queue cluster using the load balancing module, load balancing of consumer and producer information is achieved.

Benefits of technology

It improves the startup efficiency of message queues, realizes multi-thread concurrency, and reduces the running load of the server.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114416311B_ABST
    Figure CN114416311B_ABST
Patent Text Reader

Abstract

The present invention provides a method and device for managing a message queue based on the Go language, wherein the method comprises: obtaining configuration information, the configuration information comprising queue cluster information, the queue cluster information comprising queue consumer information and queue producer information, loading the configuration information into a Go language file, running the Go language file, and starting the queue cluster according to the configuration information. The technical solution of the present invention can realize synchronous or asynchronous startup of multiple threads in the message queue, improve the startup efficiency of the message queue, and realize multi-thread concurrency by loading consumer information and producer information into a Go language file and starting a message queue managed based on the Go language.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a method and device for managing a message queue based on the Go language. Background Art

[0002] Go language (also known as Golang) is a compiled, concurrent programming language developed by Google. Go language is optimized for programming multi-processor system applications, allowing programmers to have higher productivity. Programs compiled with Go language can be comparable to the speed of C or C++ code. At the same time, Go language supports parallel processes.

[0003] The underlying development system of the telecommunications channel operation center uses the message queue RabbitMq middleware to handle high-concurrency multi-threaded services. However, the Go language currently does not have a framework suitable for RabbitMq. During operation, the efficiency of starting the message queue is not high, which increases the overall load of the server. Summary of the invention

[0004] In view of the above problems, embodiments of the present invention are proposed to provide a method for managing message queues based on the Go language, and a corresponding device for managing message queues based on the Go language, which overcome the above problems or at least partially solve the above problems.

[0005] In order to solve the above problems, on the one hand, an embodiment of the present invention discloses a method for managing a message queue based on the Go language, comprising:

[0006] Acquire configuration information, where the configuration information includes queue cluster information, where the queue cluster information includes queue consumer information and queue producer information;

[0007] Load the configuration information into a Go language file;

[0008] Run the Go language file and start the queue cluster according to the configuration information.

[0009] Further, the obtaining of configuration information, the configuration information including queue cluster information, the queue cluster information including queue consumer information and queue producer information, includes:

[0010] Acquiring order information, wherein the order information includes consumer information and producer information;

[0011] Queue cluster information, queue consumer information and queue producer information are generated based on the order information, the consumer information and the producer information respectively.

[0012] Furthermore, the consumer information includes the number, type and consumption method of consumers;

[0013] The queue cluster is provided with a first node, a second node and a third node, the first node is the name of the queue cluster, the second node is the startup quantity of the consumer, and the third node is the consumption mode of the consumer.

[0014] Further, the producer information corresponds to the consumer information, and the producer information includes switch information and router information;

[0015] The queue cluster is provided with a fourth node, a fifth node and a sixth node, the fourth node is the number of the switch, the fifth node is the name of the switch, and the sixth node is the number of the router.

[0016] Furthermore, the method further comprises:

[0017] The queue cluster is started using a load balancing server, and load balancing is performed on the startup of the queue consumer information and the queue producer information.

[0018] On the other hand, the present invention also provides a device for managing a message queue based on the Go language, comprising:

[0019] A configuration information acquisition module, used to acquire configuration information, wherein the configuration information includes queue cluster information, and the queue cluster information includes queue consumer information and queue producer information;

[0020] A configuration information loading module, used to load the configuration information into a Go language file;

[0021] The queue cluster startup module is used to run the Go language file and start the queue cluster according to the configuration information.

[0022] Furthermore, the configuration information acquisition module includes:

[0023] An order information acquisition submodule is used to acquire order information, wherein the order information includes consumer information and producer information;

[0024] The queue information generation submodule is used to generate queue cluster information, queue consumer information and queue producer information based on the order information, the consumer information and the producer information respectively.

[0025] Furthermore, the consumer information includes the number, type and consumption method of consumers;

[0026] The queue cluster is provided with a first node, a second node and a third node, the first node is the name of the queue cluster, the second node is the startup quantity of the consumer, and the third node is the consumption mode of the consumer.

[0027] Further, the producer information corresponds to the consumer information, and the producer information includes switch information and router information;

[0028] The queue cluster is provided with a fourth node, a fifth node and a sixth node, the fourth node is the number of the switch, the fifth node is the name of the switch, and the sixth node is the number of the router.

[0029] Furthermore, the device also includes:

[0030] A load balancing module is used to start the queue cluster and to load balance the startup of the queue consumer information and the queue producer information.

[0031] On the other hand, an embodiment of the present invention further provides an electronic device, comprising a processor, a memory, and a computer program stored in the memory and capable of running on the processor, wherein the computer program, when executed by the processor, implements the steps of the method for managing message queues based on the Go language.

[0032] On the other hand, an embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the method for managing a message queue based on the Go language are implemented.

[0033] The embodiment of the present invention includes the following advantages: obtaining configuration information, the configuration information includes queue cluster information, the queue cluster information includes queue consumer information and queue producer information, loading the configuration information into a Go language file, running the Go language file, and starting the queue cluster according to the configuration information. The technical solution of the present invention can realize synchronous or asynchronous startup of multiple threads in the message queue, improve the startup efficiency of the message queue, and realize multi-threaded concurrency by loading consumer information and producer information into a Go language file and starting a message queue managed based on the Go language.

[0034] The embodiment of the present invention starts a queue cluster by using a load balancing module, and performs load balancing on the startup of queue consumer information and queue producer information, thereby reducing the operation load of the server. BRIEF DESCRIPTION OF THE DRAWINGS

[0035] Figure 1 A flowchart of a method for managing a message queue based on the Go language provided in an embodiment of the present invention;

[0036] Figure 2 It is a structural block diagram of a method for managing message queues based on the Go language provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0037] In order to make the above-mentioned objects, features and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.

[0038] Due to the integrated network management requirements of the telecommunications group, the network elements of the metropolitan area network need to be managed and centralized. The number of network elements managed by the network management has increased to 100,000, which has increased the overall load of the server. The underlying development system of the telecommunications channel operation center will use the message queue RabbitMq middleware to handle high-concurrency multi-threaded services. Based on the advantages of Go language with compiled and concurrent functions, programmers use Go language to write engineering projects and establish a configuration queue framework based on order information by writing Go language to facilitate the startup of the management message queue.

[0039] Figure 1 A flowchart of a method for managing a message queue based on the Go language provided in an embodiment of the present invention, the method comprising the following steps:

[0040] Step 101: Obtain configuration information, where the configuration information includes queue cluster information, and the queue cluster information includes queue consumer information and queue producer information;

[0041] In this embodiment, the programmer first obtains order information, which includes consumer information and producer information; and generates queue cluster information, queue consumer information and queue producer information based on the order information, the consumer information and the producer information respectively.

[0042] Specifically, the consumer information includes the number, type and consumption mode of consumers. The queue cluster is provided with a first node, a second node and a third node, the first node is the name of the queue cluster, the second node is the startup number of consumers, and the third node is the consumption mode of consumers. The code instructions for configuring consumer information are as follows:

[0043] #Recharge order information-pending payment

[0044] queue-name:q.recharge.order.release.ocp

[0045] queue-count:5

[0046] queue-prefetch:30

[0047] queue-cluster:mq-2

[0048] queue-method:CZOrderHandler

[0049] #Recharge order information-Payment successful

[0050] -queue-name:q.recharge.ocp

[0051] queue-count:5

[0052] queue-prefetch:30

[0053] queue-cluster:mq-2

[0054] queue-method:CZSrderHandler

[0055] Among them, the queue-name node is the name of the consumer information queue, the queue-count node is the number of consumer startups, the queue-prefetch node is the number of consumer fetches each time, the queue-cluster node is the cluster to which the consumer information queue belongs, and the queue-method is the consumption method registered by the consumer.

[0056] The producer information corresponds to the consumer information, and the producer information includes the switch information and the router information. The queue cluster is set with the fourth node, the fifth node and the sixth node. The fourth node is the number of the switch used by the node, the fifth node is the name of the switch, and the sixth node is the number of the router. The code instructions for configuring the producer information are as follows:

[0057] queue:

[0058] exchange-config:

[0059] #Order Push Switch

[0060] -exchange-id:ex-1

[0061] exchange-name:x.order.ocp.order.push

[0062] routing-key:order

[0063] exchange-type:topic

[0064] exchange-couster:mq-1

[0065] #Status Push Switch

[0066] -exchange-id:ex-2

[0067] exchange-name:x.order.ocp.status.push

[0068] routing-key:status

[0069] exchange-type:topic

[0070] exchange-couster:mq-1

[0071] Where, exchange-id is the switch ID, exchange-name is the switch name, routing-key is the router information, exchange-type is the switch type, and exchange-cluster is the queue cluster to which the switch belongs.

[0072] Step 102: Load the configuration information into a Go language file;

[0073] The consumer information and producer information in the queue cluster information are loaded into a Go language file, wherein a number of nodes corresponding to the order information are set in the Go language file.

[0074] Step 103: Run the Go language file and start the queue cluster according to the configuration information.

[0075] Among them, the code instructions for starting the consumer information queue are as follows:

[0076] / / Start the consumer

[0077] queueConfigList:=config.

[0078] QueueSecret.Queue.

[0079] QueueConfig

[0080] for_v:=rangequeueConfigList

[0081] {

[0082] goconsumer.StartConsumer(v)

[0083] }

[0084] In the actual operation process, users manage message queues based on the Go language. By setting the startup number of consumer information queues and producer information queues in the queue cluster information, they can realize synchronous or asynchronous startup of multiple threads in the message queue, improve the startup efficiency of the message queue, and realize multi-threaded concurrency.

[0085] In an optional embodiment, the user may use a load balancing server to start a queue cluster, and perform load balancing on the startup of the queue consumer information and the queue producer information, thereby reducing the operating load of the server.

[0086] In an optional embodiment, after establishing a configuration queue framework based on order information by writing Go language, in order to facilitate the startup of the message queue, the package dependency management tool of Go language can be used for management. Among them, there are many package dependency management tools for Go language, and installing any one of them can realize the management of external dependency packages. Compared with directly using Go language to obtain third-party libraries one by one through go and get instructions, the package dependency management tool can directly give the introduced third-party library package a special directory, and can specially formulate a configuration file to control the third-party library introduced by the Go language project, version and other dependencies. In the specific application process: first read the information of the third-party library that the Go language project depends on recorded in the configuration file of the Go language project; download the corresponding third-party library to the directory of the GO language project according to the information of the third-party library. Optionally, the package dependency management tool may include: dep, Godep, Go mod, Go vendor.

[0087] In an optional embodiment, in order to facilitate the synchronous or asynchronous start of multiple threads in the message queue, the user can establish a scheduling center. After establishing a configuration queue framework based on order information by writing Go language, the consumer information queue and producer information queue in the queue framework are uniformly scheduled to avoid task conflicts caused by starting multiple message queues at the same time, and different consumer information queues that depend on the same switch are scheduled, so that the configuration queue framework based on order information can start and run normally. An executor is set in the scheduling center, which is used to receive scheduling requests and execute task logic, and at the same time uses RPC communication to access the scheduling center and receive execution requests and termination requests from the scheduling center.

[0088] Based on the above description, the embodiment of the present invention includes the following advantages: obtaining configuration information, the configuration information includes queue cluster information, the queue cluster information includes queue consumer information and queue producer information, loading the configuration information into a Go language file, running the Go language file, and starting the queue cluster according to the configuration information. The technical solution of the present invention can realize the synchronous or asynchronous startup of multiple threads in the message queue, improve the startup efficiency of the message queue, and realize multi-threaded concurrency by loading consumer information and producer information into a Go language file and starting a message queue managed based on the Go language. The embodiment of the present invention starts the queue cluster by using a load balancing module, and load balances the startup of the queue consumer information and the queue producer information, thereby reducing the operating load of the server.

[0089] It should be noted that, for the sake of simplicity, the method embodiments are described as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present invention are not limited by the order of the actions described, because according to the embodiments of the present invention, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present invention.

[0090] Figure 2 is a structural block diagram of a device for managing a message queue based on the Go language provided by an embodiment of the present invention. In order to implement the above-mentioned evaluation method, an embodiment of the present invention further provides a device for managing a message queue based on the Go language, including:

[0091] A configuration information acquisition module 201 is used to acquire configuration information, wherein the configuration information includes queue cluster information, and the queue cluster information includes queue consumer information and queue producer information;

[0092] A configuration information loading module 202, used to load the configuration information into a Go language file;

[0093] The queue cluster startup module 203 is used to run the Go language file and start the queue cluster according to the configuration information.

[0094] In an optional embodiment, the configuration information acquisition module 201 may include:

[0095] An order information acquisition submodule is used to acquire order information, wherein the order information includes consumer information and producer information;

[0096] The queue information generation submodule is used to generate queue cluster information, queue consumer information and queue producer information based on the order information, the consumer information and the producer information respectively.

[0097] In an optional embodiment, the consumer information includes the number, type and consumption method of consumers; the queue cluster is provided with a first node, a second node and a third node, the first node is the name of the queue cluster, the second node is the startup number of consumers, and the third node is the consumption method of consumers.

[0098] In an optional embodiment, the producer information corresponds to the consumer information, and the producer information includes switch information and router information; the queue cluster is provided with a fourth node, a fifth node and a sixth node, the fourth node is the number of the switch, the fifth node is the name of the switch, and the sixth node is the number of the router.

[0099] In an optional embodiment, the device further includes:

[0100] A load balancing module is used to start the queue cluster and to load balance the startup of the queue consumer information and the queue producer information.

[0101] In an optional embodiment, in order to facilitate the synchronous or asynchronous start of multiple threads in the message queue, the user can establish a scheduling center. After establishing a configuration queue framework based on order information by writing Go language, the consumer information queue and producer information queue in the queue framework are uniformly scheduled to avoid task conflicts caused by starting multiple message queues at the same time, and different consumer information queues that depend on the same switch are scheduled, so that the configuration queue framework based on order information can start and run normally. An executor is set in the scheduling center, which is used to receive scheduling requests and execute task logic, and at the same time uses RPC communication to access the scheduling center and receive execution requests and termination requests from the scheduling center.

[0102] Based on the above description, the embodiment of the present invention includes the following advantages: obtaining configuration information, the configuration information includes queue cluster information, the queue cluster information includes queue consumer information and queue producer information, loading the configuration information into a Go language file, running the Go language file, and starting the queue cluster according to the configuration information. The technical solution of the present invention can realize the synchronous or asynchronous startup of multiple threads in the message queue, improve the startup efficiency of the message queue, and realize multi-threaded concurrency by loading consumer information and producer information into a Go language file and starting a message queue managed based on the Go language. The embodiment of the present invention starts the queue cluster by using a load balancing module, and load balances the startup of the queue consumer information and the queue producer information, thereby reducing the operating load of the server.

[0103] An embodiment of the present invention also provides an electronic device, including a processor, a memory, and a computer program stored in the memory and capable of running on the processor. When the computer program is executed by the processor, the various processes of the above-mentioned method embodiment are implemented and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.

[0104] An embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the various processes of the above-mentioned method embodiment are implemented and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.

[0105] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0106] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, devices, or computer program products. Therefore, embodiments of the present invention may take the form of complete hardware embodiments, complete software embodiments, or embodiments combining software and hardware. Furthermore, embodiments of the present invention may take the form of computer program products implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.

[0107] The embodiments of the present invention are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0108] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0109] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0110] Although the preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present invention.

[0111] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.

[0112] The method for managing message queues based on the Go language and the device for managing message queues based on the Go language provided by the present invention are introduced in detail above. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of ​​the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.

Claims

1. A method for managing a message queue based on the Go language, characterized in that: include: Acquire configuration information, where the configuration information includes queue cluster information, where the queue cluster information includes queue consumer information and queue producer information; Load the configuration information into a Go language file; Run the Go language file and start the queue cluster according to the configuration information; The queue cluster information also includes: Set the startup quantity of consumer information queues and producer information queues; The starting the queue cluster includes: The consumer information queue and the producer information queue in the configuration queue framework based on order information are uniformly scheduled through the scheduling center.

2. The method according to claim 1, characterized in that The acquiring of configuration information, wherein the configuration information includes queue cluster information, wherein the queue cluster information includes queue consumer information and queue producer information, includes: Acquiring order information, wherein the order information includes consumer information and producer information; Queue cluster information, queue consumer information and queue producer information are generated based on the order information, the consumer information and the producer information respectively.

3. The method according to claim 2, characterized in that The consumer information includes the number, type and consumption method of consumers; The queue cluster is provided with a first node, a second node and a third node, the first node is the name of the queue cluster, the second node is the startup quantity of the consumer, and the third node is the consumption mode of the consumer.

4. The method according to claim 2, characterized in that: The producer information corresponds to the consumer information, and the producer information includes switch information and router information; The queue cluster is provided with a fourth node, a fifth node and a sixth node, the fourth node is the number of the switch, the fifth node is the name of the switch, and the sixth node is the number of the router.

5. The method according to claim 1, characterized in that: The method further comprises: The queue cluster is started using a load balancing server, and load balancing is performed on the startup of the queue consumer information and the queue producer information.

6. A device for managing message queues based on Go language, characterized in that: include: A configuration information acquisition module, used to acquire configuration information, wherein the configuration information includes queue cluster information, and the queue cluster information includes queue consumer information and queue producer information; A configuration information loading module, used to load the configuration information into a Go language file; A queue cluster startup module, used to run the Go language file and start the queue cluster according to the configuration information; The configuration information acquisition module is also used to: Get the startup quantity of the set consumer information queue and producer information queue from the queue cluster information; The queue cluster startup module is also used to: The consumer information queue and the producer information queue in the configuration queue framework based on order information are uniformly scheduled through the scheduling center.

7. The device according to claim 6, characterized in that The configuration information acquisition module includes: An order information acquisition submodule is used to acquire order information, wherein the order information includes consumer information and producer information; The queue information generation submodule is used to generate queue cluster information, queue consumer information and queue producer information based on the order information, the consumer information and the producer information respectively.

8. The device according to claim 7, characterized in that The consumer information includes the number, type and consumption method of consumers; The queue cluster is provided with a first node, a second node and a third node, the first node is the name of the queue cluster, the second node is the startup quantity of the consumer, and the third node is the consumption mode of the consumer.

9. An electronic device, characterized in that: include: A processor, a memory, and a computer program stored in the memory and capable of running on the processor, wherein when the computer program is executed by the processor, the steps of the method according to any one of claims 1 to 5 are implemented.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.