A message queue cluster migration method and device
By creating messages with message tags for production-side business and utilizing a message queue cluster migration method with pre-defined mapping relationships, the configuration complexity problem when migrating an ActiveMQ cluster to a RocketMQ cluster is solved, achieving efficient message queue cluster migration and fast message forwarding.
Patent Information
- Application Number
- CN202111479614.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-06
- Publication Date
- 2025-12-09
- Estimated Expiration
- 2041-12-06
AI Technical Summary
In existing technologies, message queue cluster migration is inefficient and error-prone, especially when migrating a low-performance ActiveMQ cluster to a higher-performance RocketMQ cluster, where the configuration workload is large and complex.
A second message queue cluster is created for all production-side services, and a message topic is configured. Each production-side service generates a message with a message tag. Using the pre-defined mapping relationship between the message tag and the first message queue cluster, the message is sent to the matching message queue. Virtual consumers and virtual producers are used for message forwarding.
It greatly reduces configuration workload, improves migration efficiency, and accelerates message forwarding rate through multiple virtual consumers and producers, reducing manual intervention and development workload.
Smart Images

Figure CN114064328B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application belongs to the technical field of computer, and particularly relates to a message queue cluster migration method and device. BACKGROUND
[0002] Message queue (MQ) middleware refers to a container or service for saving messages in message transmission, and is an important component for realizing high performance, high availability, high scalability and other advanced features of a distributed system, and is suitable for various scenarios such as message communication, asynchronous processing, application decoupling, and traffic peak clipping.
[0003] For example, two kinds of currently popular message queue middleware include ActiveMQ and RocketMQ. ActiveMQ is an open source message queue middleware based on the JMS (Java Message Service) specification, and has a throughput of ten thousand and high availability. RocketMQ is an open source message queue of Alibaba, which is developed in Java and has the characteristics of high throughput (100,000), high availability, and suitability for large-scale distributed system applications.
[0004] However, considering that different message queue clusters have different performances, sometimes it is necessary to migrate a message queue cluster based on one kind of message queue middleware to another kind of message queue middleware, which usually requires a large amount of configuration work, has low migration efficiency and high error rate. For example, considering that RocketMQ has higher performance than ActiveMQ, it is necessary to migrate a business system originally based on an ActiveMQ cluster to a RocketMQ cluster to improve the performance of the entire business system. SUMMARY
[0005] Therefore, the purpose of the present application is to provide a message queue cluster migration method and device to solve the problems of low efficiency and high error rate in the message queue cluster migration process, and the specific technical solutions are as follows:
[0006] In a first aspect, the present application provides a message queue cluster migration method applied to a message system, wherein the message system includes a plurality of production-side businesses and a plurality of consumption-side businesses, wherein the message queue cluster of the consumption-side business is a first message queue cluster, and the method comprises:
[0007] creating a second message queue cluster for the plurality of production-side businesses, and the second message queue cluster is configured with a message topic;
[0008] each of the production-side businesses generates a message carrying a message tag and publishes the message to the message topic, wherein the message tags carried by messages of different message types are different.
[0009] According to a preset mapping relationship between the message label and the message queue in the first message queue cluster, each message in the second message queue cluster is sent to a message queue in the first message queue cluster that matches the message label of the message.
[0010] In a possible implementation of the first aspect, the sending of each message in the second message queue cluster to a message queue in the first message queue cluster that matches the message label of the message according to a preset mapping relationship between the message label and the message queue in the first message queue cluster comprises:
[0011] parsing the message in the message topic to obtain a target message label carried by the message;
[0012] querying the mapping relationship between the message label and the message queue in the first message queue cluster to obtain a target message queue in the first message queue cluster that matches the target message label;
[0013] sending the message to the target message queue.
[0014] In another possible implementation of the first aspect, the message system comprises a common producer module.
[0015] The process of publishing the message to the message topic by the production-side business comprises:
[0016] After any of the production-side businesses generates the message, the common producer module is invoked to send the message to the message topic in the second message queue cluster.
[0017] In still another possible implementation of the first aspect, the first message queue cluster is an ActiveMQ cluster, and the second message queue cluster is a RocketMQ cluster.
[0018] In a second aspect, the application further provides a message system, comprising a plurality of production-side businesses, a plurality of consumption-side businesses, and a message synchronization module, the first message queue cluster corresponding to the consumption-side businesses is a second message queue cluster created for the plurality of production-side businesses, and the second message queue cluster is configured with a message topic.
[0019] Each of the production-side businesses generates a message carrying a message label and publishes the message to the message topic, wherein the message labels carried by messages of different message types are different.
[0020] The message synchronization module is configured to send each message in the second message queue cluster to a message queue in the first message queue cluster that matches a message tag of the message according to a preset mapping relationship between the message tag and the message queue in the first message queue cluster.
[0021] In a possible implementation of the second aspect, the message synchronization module comprises a virtual consumer and a virtual producer.
[0022] The virtual consumer reads the messages in the second message queue cluster and sends them to the virtual producer.
[0023] The virtual producer parses the messages to obtain target message tags carried by the messages, queries the preset mapping relationship between the message tags and the message queues in the first message queue cluster, obtains a target message queue in the first message queue cluster that matches the target message tags, and publishes the messages to the target message queue.
[0024] In another possible implementation of the second aspect, each production-side business corresponds to a common producer module.
[0025] The messages produced by each production-side business invoke the common producer module to publish the messages to the message topic of the second message queue cluster.
[0026] In still another possible implementation of the second aspect, the first message queue cluster is an ActiveMQ cluster, and the second message queue cluster is a RocketMQ cluster.
[0027] In a third aspect, the present application also provides a device, comprising a memory and a processor, wherein the memory stores instructions, and the processor executes the instructions to enable the device to perform the message queue cluster migration method according to any one of the first aspect.
[0028] In a fourth aspect, the present application also provides a computer readable storage medium, characterized in that computer executable instructions are stored thereon, and the computer executable instructions are loaded and executed by a processor to implement the message queue cluster migration method according to any one of the first aspect.
[0029] In a fifth aspect, the present application also provides a computer program product, which is adapted to execute the program of the message queue cluster migration method according to any one of the first aspect when executed on an electronic device.
[0030] The message queue cluster migration method provided in the application is used by a consumer-side business to use a first message queue cluster, and migrates the message queue cluster corresponding to each producer-side business from the first message queue cluster to a second message queue cluster, and the message generated by each producer-side business is published to a same message topic (i.e. Topic) in the second message queue cluster. Moreover, the message generated by each producer-side business carries a message label. According to the preset mapping relationship between the message label and the message queue in the first message queue cluster, the message published by the producer-side business is sent to the message queue matched with the message label, so as to enable the consumer-side business to consume the message based on the first message queue cluster. As can be known from the above, all the producer-side businesses in the scheme share one second message queue cluster, and one message topic is configured, and different second message queue clusters and Topics do not need to be created for different producer-side businesses, which greatly reduces the configuration workload and improves the migration efficiency. Moreover, the message generated by the producer-side business carries a message label, and according to the mapping relationship between the message label and different message queues in the first message queue cluster, each message is forwarded to the corresponding message queue in the first message queue cluster, and the mapping relationship between different Topics and the message queues in the first message queue cluster does not need to be configured respectively, thereby further reducing the configuration workload and improving the migration efficiency. BRIEF DESCRIPTION OF DRAWINGS
[0031] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings needed to be used in the embodiments or the prior art description. Obviously, the drawings in the following description are some embodiments of the present application, and for those skilled in the art, other drawings can also be obtained without creative labor based on these drawings.
[0032] Figure 1 is a system structure schematic diagram based on ActiveMQ cluster;
[0033] Figure 2 is a structure schematic diagram of a message system provided by the embodiment of the present application;
[0034] Figure 3 is a flowchart of a message queue cluster migration method provided by the embodiment of the present application;
[0035] Figure 4 is a flowchart of a message forwarding process provided by the embodiment of the present application;
[0036] Figure 5 is a signaling diagram of another message queue cluster migration method provided by the embodiment of the present application. DETAILED DESCRIPTION
[0037] In order to make the purposes, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are some but not all of the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by a person of ordinary skill in the art without creative work fall within the protection scope of the present application.
[0038] Before the method provided in the present application is described in detail, the technical terms or related technologies involved in the present application are described:
[0039] Producer (message producer), responsible for generating messages, and generally business systems are responsible for generating messages.
[0040] Consumer (message consumer), responsible for consuming messages, and generally services are responsible for consuming messages.
[0041] Message (message), that is, the information to be transmitted, such as the message generated by the business on the production side in the present application.
[0042] Topic (message topic) message delivery model, under which a message publisher publishes a message to a specific Topic, and 0 or more subscribers interested in the message topic can receive the published message.
[0043] Queue message delivery model, through which a message producer can send a message to a message consumer, and in this delivery model, the message destination type is a queue (Queue), and the message is first transmitted to a specific queue in the message server end, and then the message is transmitted from the queue to a consumer listening to the queue.
[0044] In one application scenario, the same system platform includes multiple different business subsystems, each business subsystem can generate different types of messages, and messages generated by different producers are published to different message queue clusters. If the first message queue cluster used by each producer is migrated to the second message queue cluster. Because there are many consumption-side businesses, the consumer side still uses the first message queue cluster. Among them, the message delivery model of the first message queue cluster and the second message queue cluster is different, for example, the first message queue cluster uses an ActiveMQ cluster based on a queue message delivery model, and the second message queue cluster uses a RocketMQ cluster based on a Topic message delivery model.
[0045] In this scenario, a second message queue cluster needs to be created for each producer, and in order to ensure that the messages in the second message queue cluster can be consumed by the consumers using the first message queue cluster, the mapping relationship between each type of message in each second message queue cluster and each message queue in the first message queue cluster also needs to be configured, so that the messages of each type in the second message queue cluster can be forwarded to the corresponding message queue in the first message queue cluster on the consumer side, so as to be consumed by the consumers. However, when migrating each first message queue cluster on the producer side to the second message queue cluster, a second message queue cluster needs to be created for each producer, and the manual configuration workload is large, which leads to low message migration and is prone to errors. At the same time, the configuration workload of the mapping relationship between each type of message in the second message queue cluster and the message queue in the first message queue cluster is large, which further leads to low message migration.
[0046] The following will take the first message queue cluster ActiveMQ cluster as an example for description, please refer to Figure 1 , which shows a structural diagram of a message system based on ActiveMQ cluster.
[0047] As shown in Figure 1 , the message system includes N producers, multiple ActiveMQ clusters, and multiple consumers. Each ActiveMQ cluster includes at least one VirtualTopic, and each VirtualTopic includes multiple message queues (queues).
[0048] VirtualTopic is Topic for the producer and Queue for the consumer, and the internal processing mechanism is to redistribute the received messages to each Queue. Different consumers only care about and connect to their own Queue to receive messages.
[0049] Since the performance of ActiveMQ cluster is lower than that of RocketMQ cluster, it is necessary to migrate the ActiveMQ cluster of the business platform to RocketMQ cluster. However, the business platform includes multiple ActiveMQ clusters or multiple VirtualTopics, and when migrating the ActiveMQ cluster to RocketMQ cluster, multiple RocketMQ clusters need to be created, or multiple Topics need to be configured, which has a large configuration workload and is prone to problems. In addition, under the premise of no awareness on the consumer side (i.e., the consumer still uses ActiveMQ cluster to consume messages), when migrating the ActiveMQ cluster of the producer to RocketMQ cluster, the corresponding relationship between each RocketMQ cluster or each Topic and the queue in the ActiveMQ cluster also needs to be configured, which has a large configuration workload and is prone to errors.
[0050] To solve the problems in the cluster migration scenario, the application provides a message queue cluster migration method. The method creates a second message queue cluster for all production-side businesses in the system, and the second message queue cluster is configured with only one message topic. Each production-side business generates a message carrying a message tag, and different types of messages correspond to different message tags. Moreover, a mapping relationship between the message tags and the message queues in the first message queue cluster is set in advance, and based on the mapping relationship, the messages in the second message queue cluster can be forwarded to the corresponding message queues in the first message queue cluster. As can be seen, the scheme does not need to create different second message queue clusters and Topics for different production-side businesses, greatly reducing the configuration workload and improving the migration efficiency. Moreover, the messages generated by the production-side businesses carry message tags, and based on the mapping relationship between the message tags and the different message queues in the first message queue cluster, each message is forwarded to the corresponding message queue in the first message queue cluster, without the need to configure the mapping relationship between different Topics and the message queues in the first message queue cluster, thereby further reducing the configuration workload and improving the migration efficiency.
[0051] Please refer to Figure 2 , which shows a structure diagram of a message system provided by an embodiment of the application. The system includes N message producers, a second message queue cluster, a message synchronization module, and a first message queue cluster.
[0052] For example, in a business system including multiple different businesses, the producers are various businesses that generate messages, and the consumers are services in the business system that receive the messages generated by the various businesses.
[0053] In this embodiment, the first message queue cluster is taken as an ActiveMQ cluster, and the second message queue cluster is taken as a RocketMQ cluster as an example for illustration. In other embodiments, the first message queue cluster and the second message queue cluster can each adopt other message queue clusters, which are not limited by the application.
[0054] The businesses on the producer side are migrated from the ActiveMQ cluster to the RocketMQ cluster. The RocketMQ cluster is configured with one Topic, and the messages published by each producer are published to the Topic, and the messages published by the producers carry message tags Tag.
[0055] Tag (message tag), which is used to provide additional flexibility for users. Different types of messages generated by the same business module can be identified by different Tags. The consumers can subscribe to and consume messages through the Topic and the Tag.
[0056] The message synchronization module can be deployed separately to forward the messages in the RocketMQ cluster to the corresponding queues in the RocketMQ cluster, so that the consumers consume the messages in the ActiveMQ cluster, and read the messages subscribed by the consumers from the message queues in the ActiveMQ cluster for consumption, that is, the message cluster migration on the producer side is transparent to the consumers.
[0057] In an exemplary embodiment, the message synchronization module comprises a virtual consumer (i.e., a RocketMQ consumer) and a virtual producer (i.e., an ActiveMQ producer).
[0058] The virtual consumer reads the messages in the Topic of the second message queue cluster and forwards them to the virtual producer associated with the virtual consumer.
[0059] The virtual producer publishes the messages to the queue of the first message queue cluster, wherein the virtual producer publishes the received messages to the queue matched with the Tag carried by the messages according to the mapping relationship between the Tag and the queue.
[0060] In a possible implementation, multiple virtual consumers and multiple virtual producers are started simultaneously to speed up the message forwarding.
[0061] The multiple virtual consumers can simultaneously consume the messages in the Topic of the RocketMQ cluster, thereby speeding up the message forwarding.
[0062] In another possible implementation, each virtual consumer corresponds to multiple virtual producers, and the multiple virtual producers can simultaneously process the received messages, that is, send the received messages to the corresponding queue according to the mapping relationship between the Tag and the queue. The virtual producer with the fastest publishing speed forwards the messages to the queue matched with the messages, and other virtual producers do not need to continue to process the messages. Therefore, configuring multiple virtual producers can speed up the message forwarding rate.
[0063] The message system provided by the embodiment includes a second message queue cluster, and the second message queue cluster is configured with a message topic. Each producer generates a message carrying a message tag, and the message tags corresponding to different types of messages are different. A mapping relationship between the message tags and the message queues in the first message queue cluster is preset, and based on the mapping relationship, the messages in the second message queue cluster can be forwarded to the corresponding message queues in the first message queue cluster. Different second message queue clusters and topics do not need to be created for different producers, which greatly reduces the configuration workload and improves the migration efficiency. Moreover, according to the mapping relationship between the message tags and the different message queues in the first message queue cluster, each message is forwarded to the corresponding message queue in the first message queue cluster, and the mapping relationship between different topics and the message queues in the first message queue cluster does not need to be configured, which further reduces the configuration workload and improves the migration efficiency.
[0064] The message queue cluster migration process will be described in detail below in combination with the flowchart of the message synchronization method.
[0065] Please refer to Figure 3 , which shows the flowchart of a message queue cluster migration method according to an embodiment of the present application, applied to Figure 2 the message system shown in FIG. 1, that is, the producers are migrated from the first message queue cluster to the second message queue cluster, and the consumers still use the first message queue cluster. The first message queue cluster uses the Queue message delivery model, and the second message queue cluster uses the Topic message delivery model.
[0066] As shown in Figure 3 , the method can include the following steps:
[0067] S110, a second message queue cluster is created, and the second message queue cluster is configured with a Topic.
[0068] The embodiment only needs to create one second message queue cluster, and the second message queue cluster is configured with only one message topic, that is, Topic. All producers in the message system publish messages to the Topic.
[0069] All producers publish messages to the same Topic, so all producers can share the same producer sending module, thereby avoiding the need to repeatedly write codes of different producer sending modules, and thus reducing the migration workload.
[0070] S120, each producer generates a message carrying a Tag, and publishes the message to the Topic.
[0071] Wherein, the Tag represents the message type, i.e. the Tag in messages of different message types is different.
[0072] The Tag in messages generated by different producers is different, and the Tag in messages of different message types generated by the same producer is different.
[0073] For example, the Tag corresponding to the suspense movie and television drama generated by the movie and television service in the video service platform is different from the Tag of the animation.
[0074] The Tag is part of the message, and the producer can generate different Tags according to the type of the message when generating the message, without the need for manual additional creation or configuration.
[0075] S130, according to the mapping relationship between the preset Tag and the message queue in the first message queue cluster, sends each message to the message queue in the first message queue cluster that matches the Tag of the message.
[0076] The mapping relationship between the Tag and the message queue in the first message queue cluster needs to be manually pre-configured. The staff can configure the mapping relationship between the Tag and the Queue in the first message queue cluster of the consumer according to the mapping relationship between the Queue in the first message queue cluster of the producer side associated with each Queue in the first message queue cluster of the consumer before the message cluster migration, and the Queue in the first message queue cluster of the producer side and the Queue in the first message queue cluster of the producer side. The mapping relationship is written in a configuration file, and the message system initializes to read the configuration file to obtain the mapping relationship.
[0077] For example, a certain business system includes different types of business 1 and business 2, the message types generated by the two businesses are different, the message generated by business 1 needs to be forwarded to the queue queue1 of the ActiveMQ cluster, and the message generated by business 2 needs to be forwarded to queue2, in this case, the mapping relationship between the Tag and the queue is: Tag1 corresponds to queue1, and Tag2 corresponds to queue2. When the message generated by the producer needs to be forwarded to the consumer side, according to the mapping relationship, the message containing Tag1 is forwarded to queue1, and the message containing Tag2 is forwarded to queue2.
[0078] In an exemplary embodiment, as Figure 4 shown, the process shown in S130 can include the following steps:
[0079] S131, parsing the message in the message topic to obtain the target message tag carried by the message.
[0080] Read the message in the Topic of the second message queue cluster, and parse the Tag carried in the message, i.e. the target message label.
[0081] S132, query the mapping relationship between the message label and the message queue in the first message queue cluster, and obtain the target message queue of the first message queue cluster matched with the target message label.
[0082] Query the mapping relationship between the Tag and the queue, and obtain the queue in the first message queue cluster matched with the target message label, i.e. the target message queue.
[0083] S133, send the message to the target message queue.
[0084] Finally, the message read from the Topic of the second message queue cluster is sent to the target message queue in the first message queue cluster, and finally the message in the second message queue cluster is forwarded to the first message queue cluster, so that the consumer can consume the message according to the queue message consumption mode.
[0085] In an embodiment of the present application, S130 can be performed by a message synchronization module in the message system shown in the figure, which includes a virtual consumer and a virtual producer, wherein each virtual consumer is associated with at least one virtual producer. Figure 2
[0086] The virtual consumer reads the message in the Topic of the second message queue cluster as a consumer of the second message queue cluster, and forwards it to the virtual producer associated with the virtual consumer.
[0087] The virtual producer publishes the message to the queue of the first message queue cluster as a producer of the first message queue cluster, wherein the virtual producer publishes the received message to the queue matched with the Tag carried in the message according to the mapping relationship between the Tag and the queue.
[0088] This embodiment only needs to configure the mapping relationship between each Tag and queue, and does not need to configure the Topic corresponding to the queue on the producer side one by one on the consumer side, so as to further reduce the manual configuration workload.
[0089] The message queue cluster migration method provided in the embodiment creates a second message queue cluster for all production-side businesses in the system, and the second message queue cluster is configured with only one message topic. Each production-side business generates a message carrying a message tag, and the message tags corresponding to different types of messages are different. Moreover, a mapping relationship between the message tags and the message queues in the first message queue cluster is preset, and based on the mapping relationship, the messages in the second message queue cluster can be forwarded to the corresponding message queues in the first message queue cluster. It can be seen that the scheme does not need to create different second message queue clusters and Topics for different production-side businesses, greatly reducing the configuration workload and improving the migration efficiency. Moreover, the messages generated by the production-side businesses carry message tags, and based on the mapping relationship between the message tags and the different message queues in the first message queue cluster, each message is forwarded to the corresponding message queue in the first message queue cluster, without the need to configure the mapping relationship between different Topics and the message queues in the first message queue cluster, thereby further reducing the configuration workload and improving the migration efficiency.
[0090] Referring to Figure 5 , a flowchart of another message queue cluster migration method provided in the embodiment of the application is shown, and the first message queue cluster in the embodiment is an ActiveMQ cluster based on a Topic message delivery model, and the second message queue cluster is a RocketMQ cluster based on a queue message delivery model.
[0091] As shown in Figure 5 , the method can include the following steps:
[0092] In S210, a RocketMQ cluster is created, and the RocketMQ cluster is configured with a Topic.
[0093] As shown in Figure 2 , the message system includes N message producers (i.e. message generating business parties), and the messages generated by the N producers are all published to the Topic. The sending modules of the N producers execute the same logic of sending messages to the same Topic, and therefore, the N producers share a common producer module, and any producer generates a message and calls the common producer module to send the message to the same Topic. In this way, the code of the producer module can be avoided from being repeatedly written, and the workload of the developers is reduced.
[0094] In an example embodiment, the producer module of RocketMQ cluster can be dynamically loaded modularly on each production side business, that is, whether the configuration information of instantiating the producer is configured. If the configuration information of instantiating the producer is configured, the producer needs to be instantiated. Each production side business does not need to instantiate the producer, thus reducing the system resource consumption.
[0095] In other words, the producer program does not need to be configured for each production side business. The producer program only needs to be developed for any one of the production side businesses, avoiding repeated development of the producer program, and reducing the workload of the developer.
[0096] S220, the production side business generates a message carrying a Tag. The Tags corresponding to different message types are different.
[0097] In an example embodiment, the Tags corresponding to the message types in the entire business system can be configured. The Tags corresponding to different message types are different. For example, the message tag corresponding to the A type message is Tag1, and the message tag corresponding to the B type message is Tag2.
[0098] When the production side business generates a message of a certain type, the Tag corresponding to the type is carried in the message.
[0099] Further, the mapping relationship between the Tag and the queue in the ActiveMQ cluster is configured, and the mapping relationship is written into the configuration file.
[0100] S230, the production side business publishes the message to the Topic of RocketMQ cluster by using the common producer module.
[0101] After any production side business generates a message, the common producer module is started, and the message is published to the Topic by the common producer module.
[0102] S240, the virtual consumer in the message synchronization module reads the message from the Topic and forwards it to the virtual producer associated with the virtual consumer.
[0103] The message synchronization module includes a virtual consumer and a virtual producer. The virtual consumer is a consumer of RocketMQ cluster, and is used to read the message in RocketMQ cluster. The virtual producer is a producer of ActiveMQ cluster, and is used to publish the message to the queue of ActiveMQ cluster.
[0104] In an embodiment of the present application, in order to speed up the message forwarding speed, multiple virtual consumers and multiple virtual producers are started at the same time.
[0105] Multiple virtual consumers can consume the messages in the Topic of RocketMQ cluster at the same time, which accelerates the message forwarding speed.
[0106] In an exemplary embodiment, according to the mapping relationship between Tag and queue in the configuration file, a virtual consumer and n virtual producers are started for each group of mapping relationship, n≥1.
[0107] Each virtual consumer sends the read messages to all virtual producers associated with itself, so that multiple virtual producers can process the received messages at the same time, i.e., according to the mapping relationship between Tag and queue, the received messages are sent to the corresponding queue.
[0108] The virtual producer with the fastest publishing speed forwards the message to the queue matching the message, and other virtual producers do not need to continue to process the message, therefore, configuring multiple virtual producers can accelerate the message forwarding speed.
[0109] S250, the virtual producer parses the target message tag carried by the message, and determines the target message queue matching the target message tag according to the mapping relationship between Tag and queue.
[0110] When the message synchronization module is initialized, the mapping relationship between Tag and queue in the configuration file is read, and after the virtual producer receives the message, the target message tag in the message is obtained by parsing the message, and the target message queue matching the target tag is queried based on the mapping relationship.
[0111] S260, the virtual producer publishes the received message to the target message queue.
[0112] The virtual producer publishes the received message to the target message queue of the ActiveMQ cluster based on the mapping relationship between Tag and queue.
[0113] For example, TagA corresponds to queue1, then after the virtual producer receives the message containing TagA, the message is sent to queue1 of the ActiveMQ cluster. For another example, TagB corresponds to queue2, when the virtual producer receives the message containing TagB, the message is forwarded to queue2.
[0114] S270, the consumer-side business reads the subscribed messages from the queue of the ActiveMQ cluster.
[0115] The consumer-side service can directly consume messages according to the message consumption mode of the ActiveMQ cluster, for example, consumer 1 subscribes to the messages in queue 1, consumer 1 listens to queue 1, and when it is detected that there is a message in queue 1, consumer 1 directly reads the message from queue 1.
[0116] The message queue cluster migration method provided in the embodiment does not need to create different RocketMQ clusters and Topics for different production-side services, greatly reduces the configuration workload, and improves the migration efficiency. Moreover, according to the mapping relationship between the message tags and different message queues in the first message queue cluster, each message is forwarded to the corresponding message queue in the first message queue cluster, without configuring the mapping relationship between different Topics and message queues in the first message queue cluster, thereby further reducing the configuration workload and improving the migration efficiency. Moreover, the message synchronization module in the embodiment is configured with multiple RocketMQ consumers (i.e., virtual consumers) and multiple ActiveMQ producers (i.e., virtual producers), the multiple virtual consumers forward the same message in the Topic to the corresponding virtual producer, each virtual producer publishes the message to the queue in the ActiveMQ cluster based on the mapping relationship between the Tag and the queue, and the multiple virtual consumers and virtual producers process one message at the same time, which accelerates the message forwarding rate and improves the message forwarding efficiency.
[0117] The application further provides a storage medium executable by a computing device, the storage medium storing a program, and the program, when executed by the computing device, implements the message queue cluster migration method described above.
[0118] The application further provides a computer program product, which, when executed on an electronic device, is adapted to execute a program that is initialized with any of the message queue cluster migration method steps described above.
[0119] For each method embodiment described above, in order to simply describe, the embodiments are described as a series of action combinations, but those skilled in the art should know that the present application is not limited to the order of actions described, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should know that the embodiments described in the specification all belong to preferred embodiments, and the actions and modules involved are not necessarily necessary for the present application.
[0120] It should be noted that the technical features described in each of the embodiments of the present specification can be substituted or combined with each other, and each embodiment focuses on the differences from other embodiments, and the same or similar parts between each embodiment can be mutually referred to. For the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the part of the method embodiment.
[0121] The steps in the method of each embodiment of the present application can be adjusted, combined and deleted in sequence according to actual needs.
[0122] The modules and sub-modules in the device and terminal in each embodiment of the present application can be combined, divided and deleted according to actual needs.
[0123] In several embodiments provided by the present application, it should be understood that the disclosed terminal, device and method can be implemented by other ways. For example, the terminal embodiments described above are only schematic, for example, the division of modules or sub-modules is only a logical function division, and there can be another division way in actual implementation, for example, a plurality of sub-modules or modules can be combined or integrated into another module, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the shown or discussed mutually can be indirect coupling or communication connection through some interface, device or module, and can be electrical, mechanical or other forms.
[0124] The modules or sub-modules described as separate components can or can not be physically separated, and the components of the modules or sub-modules can or can not be physical modules or sub-modules, that is, they can be located in one place, or can be distributed to multiple network modules or sub-modules. Some or all of the modules or sub-modules can be selected according to actual needs to achieve the purpose of the present embodiment scheme.
[0125] In addition, each functional module or sub-module in each embodiment of the present application can be integrated in one processing module, or each module or sub-module can exist physically, or two or more modules or sub-modules can be integrated in one module. The above integrated module or sub-module can be realized in the form of hardware or in the form of software functional module or sub-module.
[0126] Finally, it should be noted that, in this document, the term "only" is used simply to contrast with another entity or action, and does not necessarily require or imply that there is any such actual relationship or order between the entities or actions. Also, the terms "comprises", "comprising", or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but can also include other elements not expressly listed or inherent to such process, method, article, or apparatus. An element proceeded by "comprises... a" does not, without more constraints, exclude the existence of additional identical elements in the process, method, article, or apparatus that comprises the element.
[0127] The above description of disclosed embodiments provides enabling teaching for a person skilled in the art to realize or use the present application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein can be applied to other embodiments without departing from the spirit or scope of the application. Thus, the present application is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
[0128] The above description is only the preferred embodiment of the present application, and it should be pointed out that, for those skilled in the art, several improvements and refinements can be made without departing from the principles of the present application, and these improvements and refinements should also be considered as the protection scope of the present application.
Claims
1. A method for migrating a message queue cluster, the method comprising: The method is applied to a message system, the message system comprising a plurality of producer-side services, a plurality of consumer-side services and a message synchronization module, wherein a message queue cluster of the consumer-side services is a first message queue cluster, the message synchronization module comprises at least one virtual consumer and at least one virtual producer, each virtual consumer corresponds to at least one virtual producer, and the method comprises: creating a second message queue cluster for the plurality of producer-side services, and the second message queue cluster is configured with only one message topic; each of the producer-side services generates a message carrying a message tag and publishes the message to the message topic, wherein the message tags carried by messages of different message types are different; reading the messages in the second message queue cluster by at least one virtual consumer and sending the messages to the virtual producer associated with the virtual consumer; sending each message in the second message queue cluster to a message queue in the first message queue cluster matched with the message tag of the message according to a preset mapping relationship between the message tag and the message queue in the first message queue cluster by at least one virtual producer.
2. The method of claim 1, wherein, The sending of each message in the second message queue cluster to a message queue in the first message queue cluster matched with the message tag of the message according to a preset mapping relationship between the message tag and the message queue in the first message queue cluster comprises: parsing the message in the message topic to obtain a target message tag carried by the message; querying the mapping relationship between the message tag and the message queue in the first message queue cluster to obtain a target message queue of the first message queue cluster matched with the target message tag; sending the message to the target message queue.
3. The method of claim 1, wherein, The message system comprises a common producer module; the process of publishing the message by the producer-side service to the message topic comprises: after any of the producer-side services generates the message, the common producer module is invoked to send the message to the message topic of the second message queue cluster.
4. The method according to any one of claims 1 to 3, characterized in that, The first message queue cluster is an ActiveMQ cluster, and the second message queue cluster is a RocketMQ cluster.
5. A messaging system, characterized by The message system comprises a plurality of producer-side services, a plurality of consumer-side services and a message synchronization module, the first message queue cluster corresponding to the consumer-side services, a second message queue cluster is created for the plurality of producer-side services, and the second message queue cluster is configured with only one message topic; each of the producer-side services generates a message carrying a message tag and publishes the message to the message topic, wherein the message tags carried by messages of different message types are different; The message synchronization module comprises at least one virtual consumer and at least one virtual producer, each virtual consumer corresponding to at least one virtual producer; messages in the second message queue cluster are read by at least one virtual consumer and sent to the virtual producer associated with the virtual consumer; each message in the second message queue cluster is sent to the message queue in the first message queue cluster matched with the message tag of the message by at least one virtual producer according to the preset mapping relationship between the message tag and the message queue in the first message queue cluster.
6. The messaging system of claim 5, wherein, The virtual producer analyzes the message to obtain the target message tag carried by the message, queries the preset mapping relationship between the message tag and the message queue in the first message queue cluster, obtains the target message queue in the first message queue cluster matched with the target message tag, and publishes the message to the target message queue.
7. The messaging system of claim 5, wherein, Each production-side business corresponds to a common producer module; The message produced by each production-side business calls the common producer module to be published to the message topic of the second message queue cluster.
8. The messaging system of claim 5, wherein, The first message queue cluster is an ActiveMQ cluster, and the second message queue cluster is a RocketMQ cluster.
9. An apparatus, comprising: comprising: a memory and a processor, wherein the memory has instructions stored therein, and the processor executes the instructions to cause the device to perform the message queue cluster migration method of any one of claims 1-4.
10. A computer-readable storage medium, characterized in that, a computer executable instruction is stored thereon, and the computer executable instruction is loaded and executed by a processor to implement the message queue cluster migration method of any one of claims 1-4.
Citation Information
Patent Citations
Server-crossing message pushing system and method
CN105282245A
Cloud-based rail transit integrated data bus communication method and system
CN112380155A