Method, device, equipment and readable storage medium for multi-cloud adaptation of message queue

By analyzing cloud migration instructions to generate configuration files, generating producer and consumer instances, the communication between the target object and the target cloud message queue is achieved, which solves the problem of low code modification efficiency in cloud environment migration, and realizes flexible adaptation of multi-cloud message queues Compatible with mode.

CN114513504BActive Publication Date: 2024-11-05GLODON CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210357772.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-04-06
Publication Date
2024-11-05
Estimated Expiration
2042-04-06

AI Technical Summary

Technical Problem

During the migration of cloud environments, the existing technology needs to modify product code to adapt to message queues on different clouds, resulting in inefficiency. The binding device using SpringCloud Stream is expensive to learn, complex to operate, and poor universality.

Method used

By receiving cloud migration instructions, parsing the configuration files of the target cloud, generating producer and consumer instances, realizing communication between the target object and the target cloud message queue, without modifying the product code, it supports multiple message queue types such as RocketMQ, RabbitMQ, Kafka, etc. Flexible adaptation.

Benefits of technology

It realizes efficient and flexible adaptation of message queues on multiple clouds without modifying product code, and is compatible with point-to-point mode and publish subscription mode, reducing the complexity and learning cost of cloud environment migration.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114513504B_ABST
    Figure CN114513504B_ABST
Patent Text Reader

Abstract

The present invention discloses a method, apparatus, device and readable storage medium for multi-cloud adaptation of a message queue, the method comprising: receiving a cloud migration instruction for switching an existing cloud connected to a target object to a target cloud; parsing a configuration file corresponding to the type of the message queue on the target cloud from the cloud migration instruction; configuring a preset producer template according to the configuration file to obtain a producer instance, and configuring a preset consumer template according to the configuration file to obtain a consumer instance; performing message processing operations between the target object and the message queue on the target cloud through the producer instance and the consumer instance; the present invention can efficiently and flexibly adapt message queues on multiple clouds without modifying product codes.
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, device, equipment and readable storage medium for multi-cloud adaptation of a message queue. Background Art

[0002] With the development of cloud environment service technology, many companies need to connect to private cloud, public cloud or hybrid cloud environment services. Message queues are used based on cloud environments. Different types of message queues are deployed in different cloud environments, for example: RocketMQ on Alibaba Cloud and RabbitMQ on Huawei Cloud.

[0003] When migrating to a cloud environment, the product line needs to be modified to use the message queue on the new cloud. However, modifying the code requires a lot of manpower, resulting in reduced efficiency. In addition, although the SpringCloud Stream binder can be used to solve the cloud environment migration problem in the existing technology, this method has a high learning cost, complex operation, and poor universality.

[0004] Therefore, how to efficiently and flexibly adapt message queues on multiple clouds without modifying product codes has become a technical problem that technical personnel in this field urgently need to solve. Summary of the invention

[0005] The object of the present invention is to provide a method, apparatus, device and readable storage medium for multi-cloud adaptation of a message queue, which can efficiently and flexibly adapt message queues on multiple clouds without modifying the product code.

[0006] According to one aspect of the present invention, a method for multi-cloud adaptation of a message queue is provided, which is applied to a target object that needs to use a cloud message queue, and the method includes:

[0007] receiving a cloud migration instruction for switching an existing cloud connected to the target object to a target cloud;

[0008] Parsing a configuration file corresponding to the type of the message queue on the target cloud from the cloud migration instruction;

[0009] According to the configuration file, a preset producer template is configured to obtain a producer instance, and according to the configuration file, a preset consumer template is configured to obtain a consumer instance;

[0010] Message processing operations are performed between the target object and the message queue on the target cloud through the producer instance and the consumer instance.

[0011] Optionally, configuring a preset producer template according to the configuration file to obtain a producer instance, and configuring a preset consumer template according to the configuration file to obtain a consumer instance, includes:

[0012] Acquire a target producer template and a target consumer template corresponding to the type of the target cloud message queue from a preset template library;

[0013] Adding configuration parameters of each configuration item in the configuration file to the target producer template to obtain one or more producer instances;

[0014] The configuration parameters of each configuration item in the configuration file are added to the target consumer template to obtain one or more consumer instances.

[0015] Optionally, performing a message processing operation between the target object and a message queue on the target cloud through the producer instance and the consumer instance includes:

[0016] Acquire a message to be sent generated by the target object; wherein the message to be sent includes: a message header and a message body, and the message header includes a message subject and a message tag;

[0017] The message to be sent is sent to the message queue on the target cloud through the producer instance.

[0018] Optionally, sending the message to be sent to the message queue on the target cloud through the producer instance includes:

[0019] Determine whether the transmission mode of the message queue on the target cloud is point-to-point mode;

[0020] If yes, obtain the message subject and message tag in the message to be sent, and obtain the group number of the consumer for consuming the message to be sent;

[0021] Searching, through the producer instance, from the target cloud for a target message queue whose queue name includes the message subject, message tag, and group number; wherein the target cloud includes multiple message queues;

[0022] The message to be sent is sent to the target message queue through the producer instance.

[0023] Optionally, performing a message processing operation between the target object and a message queue on the target cloud through the producer instance and the consumer instance includes:

[0024] Obtaining the message to be consumed from the message queue on the target cloud through the consumer instance;

[0025] Send the message to be consumed to the target object.

[0026] Optionally, obtaining the to-be-consumed message from the message queue on the target cloud through the consumer instance includes:

[0027] Determine whether the transmission mode of the message queue on the target cloud is point-to-point mode;

[0028] If yes, then obtain the message topic and message tag subscribed by the target object, and obtain the group number of the target object;

[0029] Searching, through the consumer instance, from the target cloud for a target message queue whose queue name includes the message subject, message tag, and group number; wherein the target cloud includes multiple message queues;

[0030] Obtain the message to be consumed from the target message queue through the consumer instance.

[0031] Optionally, the message queue on the target cloud includes the following types:

[0032] RocketMQ, RabbitMQ, Kafka, Tencent Cloud's TDMQ, AWS's SQS and IOT's EMQ.

[0033] In order to achieve the above object, the present invention also provides a device for multi-cloud adaptation of a message queue, which is applied to a target object that needs to use a cloud message queue, and the device includes:

[0034] A receiving module, configured to receive a cloud migration instruction for switching an existing cloud connected to the target object to a target cloud;

[0035] A parsing module, used to parse the cloud migration instruction to obtain a configuration file corresponding to the type of the message queue on the target cloud;

[0036] A configuration module, configured to configure a preset producer template according to the configuration file to obtain a producer instance, and to configure a preset consumer template according to the configuration file to obtain a consumer instance;

[0037] A processing module is used to perform message processing operations between the target object and the message queue on the target cloud through the producer instance and the consumer instance.

[0038] In order to achieve the above objectives, the present invention also provides a computer device, which specifically includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, and the processor implements the steps of the message queue multi-cloud adaptation method introduced above when executing the computer program.

[0039] In order to achieve the above-mentioned object, the present invention also 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 multi-cloud adaptation of message queues introduced above are implemented.

[0040] The method, apparatus, device and readable storage medium for multi-cloud adaptation of message queues provided by the present invention, when a target product needs to be migrated to a cloud environment, obtains the configuration file of the message queue on the migrated target cloud and generates corresponding producer instances and consumer instances according to the configuration file, so as to enable the target product to communicate with the message queue on the target cloud through the producer instance and the consumer instance, without modifying the product code of the target product, and only using the configuration file to switch to different types of message queues on different clouds, thereby achieving a flexible adaptation effect; by setting the format of the queue name of the message queue in point-to-point mode so that the message queue in point-to-point mode can be compatible with the messages generated by the message queue in publish-subscribe mode, so that the message queue in publish-subscribe mode and the message queue in point-to-point mode are compatible without changing the underlying business code of the target object. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] 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:

[0042] Figure 1 An optional flowchart of the method for multi-cloud adaptation of a message queue provided in Example 1;

[0043] Figure 2 A schematic diagram of the point-to-point mode production and consumption process provided in Example 1;

[0044] Figure 3 A schematic diagram of the production and consumption process of the publish-subscribe model provided in Example 1;

[0045] Figure 4 Another optional flowchart of the method for multi-cloud adaptation of a message queue provided in Embodiment 2;

[0046] Figure 5 A schematic diagram of a RocketMQ configuration file provided in Example 2;

[0047] Figure 6 A schematic diagram of a RabbitMQ configuration file provided in Example 2;

[0048] Figure 7A schematic diagram of an optional composition structure of a device for multi-cloud adaptation of a message queue provided in Example 3;

[0049] Figure 8 A schematic diagram of an optional hardware architecture of a computer device provided in Example 4. DETAILED DESCRIPTION

[0050] In order to make the purpose, technical scheme 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 embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.

[0051] Embodiment 1

[0052] The embodiment of the present invention provides a method for multi-cloud adaptation of a message queue, which is applied to a target object that needs to use a cloud message queue, such as Figure 1 As shown, the method specifically comprises the following steps:

[0053] Step S101: receiving a cloud migration instruction for switching an existing cloud connected to the target object to a target cloud.

[0054] The cloud migration instruction is used to switch the existing cloud currently used by the target object to the target cloud, and the type of the message queue on the existing cloud is different from the type of the message queue on the target cloud.

[0055] A message queue is a queued carrier that stores messages in the form of a queue during the message transmission process.

[0056] In this embodiment, based on user needs, it is necessary to switch from the message queue on the existing cloud to the message queue on the target cloud, and different clouds have different types of message queues. For example, the message queue type on Alibaba Cloud currently used by the user is RocketMQ, and it needs to be switched to the message queue type on Huawei Cloud, which is RabbitMQ.

[0057] Specifically, the message queues on the target cloud include the following types:

[0058] RocketMQ, RabbitMQ, Kafka, Tencent Cloud's TDMQ, AWS's SQS and IOT's EMQ.

[0059] Step S102: Parse the configuration file corresponding to the type of the message queue on the target cloud from the cloud migration instruction.

[0060] Among them, corresponding configuration file templates are pre-configured for different types of message queues to distinguish different configuration files through different prefixes in the configuration file templates. The system loads different configuration files to instantiate corresponding message queue services, thereby enabling the target object to use various types of message queues.

[0061] In addition, the configuration file template includes multiple configuration items. The configuration items in the configuration file template corresponding to different types of message queues are also different. The configuration file is generated by adding configuration parameters to each configuration item in the configuration file template.

[0062] In this embodiment, corresponding configuration file templates are pre-configured for different types of message queues. When it is necessary to switch to the message queue on the target cloud, the configuration file template corresponding to the message queue on the target cloud is obtained, and the configuration item parameters in the configuration file template are modified to form a configuration file. The producer instance and the consumer instance are generated for the preset producer template and the consumer template according to the configuration file, and then the message is transmitted to the target cloud through the producer instance and the consumer instance. The message queue of the existing cloud can be switched to the message queue of the target cloud without changing the code of the target object, thereby achieving flexible adaptation and modification. In addition, when it is necessary to switch to the message queue on the third cloud, it is only necessary to obtain the configuration file corresponding to the message queue on the third cloud to switch, so that flexible switching can be performed between different clouds.

[0063] Step S103: configuring the preset producer template according to the configuration file to obtain a producer instance, and configuring the preset consumer template according to the configuration file to obtain a consumer instance.

[0064] Specifically, step S103 includes:

[0065] Step A1: Acquire a target producer template and a target consumer template corresponding to the type of the target cloud message queue from a preset template library;

[0066] Among them, the message transmission method in the message queue is that the producer first produces the message and sends it to the message queue, and then the consumer consumes the message in the message queue.

[0067] Corresponding producer templates and consumer templates are set in advance for different types of message queues, so as to obtain producer instances and consumer instances of corresponding message queue types by using the producer templates and consumer templates.

[0068] Step A2: adding configuration parameters of each configuration item in the configuration file to the target producer template to obtain one or more producer instances;

[0069] Step A3: Add the configuration parameters of each configuration item in the configuration file to the target consumer template to obtain one or more consumer instances.

[0070] In this embodiment, multiple producer instances and multiple consumer instances can be generated through a configuration file to achieve multi-instance deployment; specifically, when the configuration file is a unit number, one producer instance and one consumer instance will be generated, and when the configuration file is in an array form, multiple producer instances and multiple consumer instances will be generated.

[0071] Step S104: Perform message processing operations between the target object and the message queue on the target cloud through the producer instance and the consumer instance.

[0072] Specifically, step S104 includes:

[0073] Step B1: Acquire a message to be sent generated by the target object; wherein the message to be sent includes: a message header and a message body, and the message header includes a message subject and a message tag;

[0074] In actual applications, the messages transmitted in the message queue include a message header and a message body. The message header is used to specify the path where the message is consumed, so that consumers can subscribe and consume based on the message header, and the message body is used to carry the message content.

[0075] In addition, the message header of the existing message only contains the message subject, while in this embodiment, a message tag is added to the message header, so that consumers can find the specified information for consumption based on the message subject and message tag, thereby realizing a deeper secondary tag subscription function.

[0076] Step B2: Send the message to be sent to the message queue on the target cloud through the producer instance.

[0077] Specifically, step B2 includes:

[0078] Step C1: Determine whether the transmission mode of the message queue on the target cloud is a point-to-point mode;

[0079] In this embodiment, the transmission mode of the message queue includes a point-to-point mode and a publish-subscribe mode. In the publish-subscribe mode, the producer transmits the message to the message queue on the target cloud in the form of a message subject and a message tag. The consumer can consume the message in the message queue on the target cloud according to the message subject and the message tag, and each message can be consumed by multiple consumers. In the point-to-point mode, the producer transmits the message to the message queue on the target cloud, and the consumer consumes the message in the specified message queue on the target cloud. The consumed message will be excluded from the message queue on the target cloud, and a message can only be consumed once by one consumer.

[0080] Step C2: If yes, obtain the message subject and message tag in the message to be sent, and obtain the group number of the consumer for consuming the message to be sent;

[0081] A corresponding group number is pre-set for each consumer, so as to combine the group number with the message subject and message tag in the message to be sent so as to find the target information queue.

[0082] Step C3: searching the target message queue whose queue name includes the message subject, message tag and group number from the target cloud through the producer instance; wherein the target cloud includes multiple message queues;

[0083] Step C4: Send the message to be sent to the target message queue through the producer instance.

[0084] In order to achieve compatibility between the point-to-point mode and the publish-subscribe mode during cloud migration, such as Figure 2 As shown, in this embodiment, the point-to-point mode is improved so that messages that meet the publish-subscribe mode can be used by the message queues of the point-to-point mode. Specifically, multiple message queues are created on the target cloud that adopts the point-to-point mode, and a queue name is set for each created message queue in the naming method of "message topic Topic + message tag Tag + group number Group ID", so that the messages generated by the target object can be stored not only on the target cloud that adopts the publish-subscribe mode but also on the target cloud that adopts the point-to-point mode. In addition, consumers also find the corresponding message queue on the target cloud according to the message topic, message tag and group number to consume the messages therein.

[0085] like Figure 3As shown, the publish-subscribe mode in this embodiment still adopts the existing publish-subscribe mode. The only difference is that the existing publish-subscribe mode only sorts messages according to the message topic, while in this embodiment, the messages are sorted according to the message topic and message tag on the target cloud. Adding message tags allows consumers to subscribe to and consume messages in the message queue in a more fine-grained manner.

[0086] Furthermore, step S104 further includes:

[0087] Step D1: Obtain the message to be consumed from the message queue on the target cloud through the consumer instance;

[0088] Step D2: Send the message to be consumed to the target object.

[0089] Specifically, step D1 includes:

[0090] Step E1: Determine whether the transmission mode of the message queue on the target cloud is a point-to-point mode;

[0091] Step E2: If yes, obtain the message topic and message tag subscribed by the target object, and obtain the group number of the target object;

[0092] Step E3: searching the target message queue whose queue name includes the message subject, message tag and group number from the target cloud through the consumer instance; wherein the target cloud includes multiple message queues;

[0093] Step E4: Obtain the to-be-consumed message from the target message queue through the consumer instance.

[0094] In actual applications, according to the target object's demand for messages, producer instances can be used to produce messages, or consumer instances can be used to consume messages. Regardless of whether the target object's demand is to produce or consume messages, the messages can be adaptively converted according to the transmission mode of the message queue on the target cloud after cloud migration to meet the target object's demand for message transmission.

[0095] In this embodiment, when the target product needs to be migrated to the cloud environment, the configuration file of the message queue on the migrated target cloud is obtained and the corresponding producer instance and consumer instance are generated according to the configuration file, so that the target product can communicate with the message queue on the target cloud through the producer instance and the consumer instance without modifying the product code of the target product. Only the configuration file can be used to switch to different types of message queues on different clouds, thereby achieving a flexible adaptation effect; by setting the queue name format of the message queue in point-to-point mode so that the message queue in point-to-point mode can be compatible with the messages generated by the message queue in publish-subscribe mode, so that the message queue in publish-subscribe mode and the message queue in point-to-point mode are compatible without changing the underlying business code of the target object.

[0096] Embodiment 2

[0097] An embodiment of the present invention provides a method for multi-cloud adaptation of a message queue, including: Figure 4 In the message-queue-starter software development kit (i.e., jar package) shown in the figure, the message-queue-starter software development kit is used by the caller (equivalent to the target object in the first embodiment), wherein the caller can be a product or a service that needs to send and receive messages. By introducing the message-queue-starter software development kit into the code of the caller and using different configuration file templates, different message queues can be switched. The method specifically includes the following steps:

[0098] Step S201: receiving a cloud migration instruction for switching an existing cloud connected to the caller to a target cloud.

[0099] The cloud migration instruction is used to switch the existing cloud used by the caller to the target cloud, and the type of the message queue on the existing cloud is different from the type of the message queue on the target cloud.

[0100] Step S202: Parse the cloud migration instruction to obtain a configuration file corresponding to the type of the message queue on the target cloud.

[0101] In this embodiment, corresponding configuration file templates are configured in advance for different types of message queues to distinguish different configuration files through different prefixes in the configuration file templates. The system loads different configuration files to instantiate corresponding message queue services, thereby enabling the target object to use various types of message queues.

[0102] like Figure 5 The following is the configuration file of RocketMQ: Figure 6The following is a configuration file for RabbitMQ. Different configuration file templates have different prefixes. The prefix of the configuration file template is used to determine the type of message queue corresponding to the configuration file template. For example: Figure 5 As shown in the figure, the prefix of RocketMQ configuration file template is paas:mq:ons:, and Figure 6 As shown in the figure, the prefix of the RabbitMQ configuration file is paas:mq:rabbitmq:. In addition, the configuration file template includes multiple configuration items, and the configuration items of different configuration file templates are different. For example, Figure 5 As shown in the configuration file template of RocketMQ, the address (namesrv-addr) is included, and as Figure 6 The configuration file template of RabbitMQ includes the domain name (host). The configuration file is formed by adding configuration parameters to each configuration item in the configuration file template.

[0103] In this embodiment, corresponding configuration file templates are pre-configured for different types of message queues. When it is necessary to switch to a message queue on a target cloud, the configuration file template corresponding to the message queue on the target cloud is obtained, and the configuration item parameters in the configuration file template are modified to form a configuration file. The producer instance and the consumer instance are generated for the preset producer template and the consumer template according to the configuration file, and then the message is transmitted to the target cloud through the producer instance and the consumer instance. The message queue of the existing cloud can be switched to the message queue of the target cloud without changing the code of the target object, thereby achieving flexible adaptation and modification. In addition, when it is necessary to switch to a message queue on another cloud, it is only necessary to obtain the configuration file corresponding to the message queue on the other cloud to switch, and it is possible to flexibly switch between the existing cloud, the target cloud and another cloud.

[0104] Step S203: configuring the preset producer template according to the configuration file to obtain a producer instance, and configuring the preset consumer template according to the configuration file to obtain a consumer instance.

[0105] Specifically, step S03 includes:

[0106] Step F1: Obtain a target producer template and a target consumer template corresponding to the type of the target cloud message queue from a preset template library;

[0107] Step F2: adding configuration parameters of each configuration item in the configuration file to the target producer template to obtain one or more producer instances;

[0108] Step F3: Add the configuration parameters of each configuration item in the configuration file to the target consumer template to obtain one or more consumer instances.

[0109] In practical applications, such as Figure 4 As shown, the message-queue-starter software development kit starts the corresponding AutoConfiguration (i.e., the automatic assembly component in SpringBoot) according to the type of message queue corresponding to the configuration file, so as to complete the assembly of the target producer template and the target consumer template through the AutoConfiguration.

[0110] In this embodiment, the automatic assembly mode of SpringBoot is used, wherein SpringBoot is a Java Web application development framework that can support automatic assembly of configuration files. A specific instance can be automatically assembled by simply changing the configuration item parameters of the configuration file.

[0111] In this embodiment, the configuration file is automatically assembled through SpringBoot to configure the producer template and the consumer template; for example: when automatically assembling RabbitMQ, RabbitMQAutoConfiguration is started, and the RabbitMQ producer template and the RabbitMQ consumer template are obtained from the preset template library, and the configuration parameters of each configuration item in the configuration file are added to the RabbitMQ producer template and the RabbitMQ consumer template through RabbitMQAutoConfiguration.

[0112] like Figure 4 As shown in the figure, corresponding AutoConfiguration is set for RocketMQ, RabbitMQ, Kafka, Tencent Cloud's TDMQ, AWS's SQS, and IOT's EMQ, and the corresponding producer instance and consumer instance are generated according to the configuration file using the corresponding AutoConfiguration of each message queue; Figure 4 The producer instances and consumer instances corresponding to Kafka, Tencent Cloud's TDMQ, AWS's SQS, and IOT's EMQ are the same as those corresponding to RocketMQ and RabbitMQ. Therefore, the producer instances and consumer instances corresponding to Kafka, Tencent Cloud's TDMQ, AWS's SQS, and IOT's EMQ are not shown.

[0113] In this embodiment, the automatic assembly class AutoConfiguration of various types of message queues utilizes the automatic assembly mechanism of the SpringBootBean object, and can instantiate the message queue instance according to the configuration items in the configuration file, thereby switching the message queue.

[0114] Further, such as Figure 4 As shown, in this embodiment, multi-instance deployment can be achieved, that is, multiple producer instances and multiple consumer instances are generated through the configuration file. Generally, when the configuration file is a single element, one producer instance and one consumer instance are generated; when the configuration file is in array form, multiple producer instances and multiple consumer instances are generated.

[0115] Step S204: when the caller is a generator, obtain the information to be sent generated by the caller; wherein the information to be sent includes: a message header and a message body, and the message header includes an information topic Topic and a message tag Tag.

[0116] In actual applications, the messages transmitted in the message queue include a message header and a message body. The message header is used to specify the path where the message is consumed, and contains the message topic and message tag, so that consumers can subscribe and consume according to the message header. The message body is used to carry the message content.

[0117] In addition, the message header of the existing message only contains the message subject. In this embodiment, a message tag is added to the message header to implement a deeper secondary tag subscription function, so that consumers can find designated information for consumption based on the message subject and message tag.

[0118] Specifically, this embodiment includes two types of messages: ProduceMessage to be sent and ConsumeMessage to be consumed. In addition, both the message to be sent and the message to be consumed include a message header and a message body. The message header includes a message topic Topic and a message tag, and the message body is uniformly converted into a byte array to achieve compatibility between different message formats.

[0119] In this embodiment, common fields are abstracted from the message formats of the six message queues and added to the message Message, that is, in this embodiment, the field content and format of the message Message are redefined to be compatible with the six different types of message queues.

[0120] Step S205: calling the producer instance through a preset Producer interface to send the message to be sent to the message queue on the target cloud.

[0121] In this embodiment, the message-queue-starter software development kit is used to encapsulate a general outgoing interface (i.e., Producer interface) and a receiving interface (i.e., Consumer interface) for the caller, so as to call a specific producer instance through the outgoing interface and call a specific consumer instance through the receiving interface.

[0122] In addition, in this embodiment, the producer instance will also perform adaptive conversion on the message to be sent so that the converted message to be sent meets the requirements of the message queue on the target cloud.

[0123] Specifically, step S205 includes:

[0124] Step G1: Determine whether the transmission mode of the message queue on the target cloud is point-to-point mode;

[0125] Step G2: If yes, obtain the message subject and message tag in the message to be sent, and obtain the group number of the consumer for consuming the message to be sent;

[0126] Step G3: searching, through the producer instance, for a target message queue on the target cloud whose queue name includes the message subject, message tag, and group number; wherein the target cloud includes multiple message queues;

[0127] Step G4: Send the message to be sent to the target message queue through the producer instance.

[0128] In this embodiment, if Figure 2 As described, the message-queue-starter software development kit will create a redundant queue group on the target cloud, wherein the redundant queue group includes multiple message queues, and the queue names of each message queue in the redundant queue group are named in the format of "message topic Topic + message tag Tag + group number GroupID". Since there will be message topics Topic and message tags Tag in the messages of the message queue in the publish-subscribe mode, and there will be no message topics Topic and message tags Tag in the messages of the message queue in the point-to-point mode, in this embodiment, in order to allow the message queue in the point-to-point mode to process messages with message topics Topic and message tags Tag (i.e., messages in the message queue that conforms to the publish-subscribe mode), the message topics Topic and message tags Tag will be added to the name of the message queue in the point-to-point mode, so that the message queue in the point-to-point mode is compatible with the message queue in the publish-subscribe mode.

[0129] In addition, when the transmission mode of the target cloud message queue is the publish-subscribe mode, the message to be sent is sent to the target message queue through the producer instance according to the existing publish-subscribe model. Figure 3 As shown, in this embodiment, the message-queue-starter software development kit will create different message topics in the Broker service on the target cloud and set multiple message tags for each message topic. Figure 3 As shown, according to the Topic and Tag in the message to be sent, the message to be sent is stored in the target message queue corresponding to the Topic and Tag in the Broker server on the target cloud.

[0130] In this embodiment, according to the needs of the caller, the caller can act as a producer to store the message to be sent in the message queue on the target cloud, and can also act as a consumer to consume the message stored in the message queue on the target cloud. The above steps S204 and S05 are performed when the caller is a producer.

[0131] Furthermore, the method further comprises:

[0132] Step S206: When the caller is a consumer role, the consumer instance is called through a preset Consumer interface to obtain the message to be consumed from the message queue on the target cloud.

[0133] Specifically, step S206 includes:

[0134] Step H1: Determine whether the transmission mode of the message queue on the target cloud is a point-to-point mode;

[0135] Step H2: If yes, obtain the message topic and message tag subscribed by the caller, and obtain the group number of the caller;

[0136] Step H3: searching, through the consumer instance, for a target message queue whose queue name includes the message subject, message tag, and group number from the redundant queue group on the target cloud; wherein the target cloud includes multiple message queues;

[0137] Step H4: Obtain the message to be consumed from the target message queue through the consumer instance.

[0138] Step S207: Send the message to be consumed to the caller through the consumer instance.

[0139] In addition, in this embodiment, the consumer instance will also perform adaptive conversion on the message to be consumed, so that the converted message to be consumed meets the requirements of the caller.

[0140] In addition, in this embodiment, when the transmission mode of the message queue on the target cloud is the publish-subscribe mode, Figure 3 As shown, the consumer instance finds the corresponding target message queue from the Broker server on the target cloud according to the message topic Topic and the message tag, and then obtains the message to be consumed from the target queue.

[0141] The above steps S206 and S207 are performed when the caller is in the role of a generator.

[0142] In this embodiment, the caller references the message-queue-starter software development kit, and automatically assembles and generates corresponding producer instances and consumer instances according to the configuration file of the message queue on the target cloud. At the same time, the message-queue-starter software development kit encapsulates the general Producer interface and Consumer interface for the caller, and calls the specific producer instance through the Producer interface and calls the specific consumer instance through the Consumer interface according to the corresponding role of the caller, thereby improving the compatibility of different message queues on the corresponding target cloud and achieving efficient multi-cloud adaptation of message queues.

[0143] Embodiment 3

[0144] The embodiment of the present invention provides a device for multi-cloud adaptation of a message queue, such as Figure 7 As shown, the device is applied to the target object that needs to use the cloud message queue. The device specifically includes the following components:

[0145] A receiving module 701 is used to receive a cloud migration instruction for switching an existing cloud connected to the target object to a target cloud;

[0146] A parsing module 702 is used to parse the cloud migration instruction to obtain a configuration file corresponding to the type of the message queue on the target cloud;

[0147] A configuration module 703, configured to configure a preset producer template according to the configuration file to obtain a producer instance, and to configure a preset consumer template according to the configuration file to obtain a consumer instance;

[0148] The processing module 704 is used to perform message processing operations between the target object and the message queue on the target cloud through the producer instance and the consumer instance.

[0149] Specifically, the configuration module 703 is used to:

[0150] Acquire a target producer template and a target consumer template corresponding to the type of the target cloud message queue from a preset template library;

[0151] Adding configuration parameters of each configuration item in the configuration file to the target producer template to obtain one or more producer instances;

[0152] The configuration parameters of each configuration item in the configuration file are added to the target consumer template to obtain one or more consumer instances.

[0153] Furthermore, the processing module 704 specifically includes:

[0154] A first acquisition unit is used to acquire a message to be sent generated by the target object; wherein the message to be sent includes: a message header and a message body, and the message header includes a message subject and a message tag;

[0155] The first sending unit is used to send the message to be sent to the message queue on the target cloud through the producer instance.

[0156] Furthermore, the first sending unit is specifically configured to:

[0157] Determine whether the transmission mode of the message queue on the target cloud is point-to-point mode;

[0158] If yes, obtain the message subject and message tag in the message to be sent, and obtain the group number of the consumer for consuming the message to be sent;

[0159] Searching, through the producer instance, from the target cloud for a target message queue whose queue name includes the message subject, message tag, and group number; wherein the target cloud includes multiple message queues;

[0160] The message to be sent is sent to the target message queue through the producer instance.

[0161] Furthermore, the processing module 704 further includes:

[0162] A second acquisition unit, configured to acquire the to-be-consumed message from the message queue on the target cloud through the consumer instance;

[0163] The second sending unit is used to send the message to be consumed to the target object.

[0164] Furthermore, the second acquisition unit is specifically used to:

[0165] Determine whether the transmission mode of the message queue on the target cloud is point-to-point mode;

[0166] If yes, then obtain the message topic and message tag subscribed by the target object, and obtain the group number of the target object;

[0167] Searching, through the consumer instance, from the target cloud for a target message queue whose queue name includes the message subject, message tag, and group number; wherein the target cloud includes multiple message queues;

[0168] Obtain the message to be consumed from the target message queue through the consumer instance.

[0169] In addition, the message queues on the target cloud include the following types:

[0170] RocketMQ, RabbitMQ, Kafka, Tencent Cloud's TDMQ, AWS's SQS and IOT's EMQ.

[0171] Embodiment 4

[0172] This embodiment also provides a computer device, such as a smart phone, tablet computer, laptop computer, desktop computer, rack server, blade server, tower server or cabinet server (including an independent server or a server cluster composed of multiple servers) that can execute programs. Figure 8 As shown, the computer device 80 of this embodiment includes at least but not limited to: a memory 801 and a processor 802 that can be interconnected through a system bus. It should be noted that Figure 8 Only a computer device 80 having components 801 - 802 is shown, but it should be understood that implementing all of the components shown is not a requirement, and more or fewer components may alternatively be implemented.

[0173] In this embodiment, the memory 801 (i.e., a readable storage medium) includes a flash memory, a hard disk, a multimedia card, a card-type memory (e.g., an SD or DX memory, etc.), a random access memory (RAM), a static random access memory (SRAM), a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), a programmable read-only memory (PROM), a magnetic memory, a magnetic disk, an optical disk, etc. In some embodiments, the memory 801 may be an internal storage unit of the computer device 80, such as a hard disk or a memory of the computer device 80. In other embodiments, the memory 801 may also be an external storage device of the computer device 80, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card, etc. equipped on the computer device 80. Of course, the memory 801 may also include both the internal storage unit and the external storage device of the computer device 80. In this embodiment, the memory 801 is generally used to store the operating system and various application software installed on the computer device 80. In addition, the memory 801 may also be used to temporarily store various types of data that have been output or are to be output.

[0174] In some embodiments, the processor 802 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chips. The processor 802 is generally used to control the overall operation of the computer device 80.

[0175] Specifically, in this embodiment, the processor 802 is used to execute the program of the message queue multi-cloud adaptation method stored in the memory 801, and the program of the message queue multi-cloud adaptation method is executed to implement the following steps:

[0176] receiving a cloud migration instruction for switching an existing cloud connected to the target object to a target cloud;

[0177] Parsing a configuration file corresponding to the type of the message queue on the target cloud from the cloud migration instruction;

[0178] According to the configuration file, a preset producer template is configured to obtain a producer instance, and according to the configuration file, a preset consumer template is configured to obtain a consumer instance;

[0179] Message processing operations are performed between the target object and the message queue on the target cloud through the producer instance and the consumer instance.

[0180] The specific implementation process of the above method steps can be found in Example 1, and this embodiment will not be repeated here.

[0181] Embodiment 5

[0182] This embodiment also provides a computer-readable storage medium, such as a flash memory, a hard disk, a multimedia card, a card-type memory (for example, an SD or DX memory, etc.), a random access memory (RAM), a static random access memory (SRAM), a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), a programmable read-only memory (PROM), a magnetic memory, a disk, an optical disk, a server, an App application store, etc., on which a computer program is stored. When the computer program is executed by a processor, the following method steps are implemented:

[0183] receiving a cloud migration instruction for switching an existing cloud connected to the target object to a target cloud;

[0184] Parsing a configuration file corresponding to the type of the message queue on the target cloud from the cloud migration instruction;

[0185] According to the configuration file, a preset producer template is configured to obtain a producer instance, and according to the configuration file, a preset consumer template is configured to obtain a consumer instance;

[0186] Message processing operations are performed between the target object and the message queue on the target cloud through the producer instance and the consumer instance.

[0187] The specific implementation process of the above method steps can be found in Example 1, and this embodiment will not be repeated here.

[0188] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or 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 device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.

[0189] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.

[0190] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method.

[0191] The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.

Claims

1. A method for multi-cloud adaptation of a message queue, characterized in that: Applied to a target object that needs to use a cloud message queue, the method includes: receiving a cloud migration instruction for switching an existing cloud connected to the target object to a target cloud; Parsing a configuration file corresponding to the type of the message queue on the target cloud from the cloud migration instruction; According to the configuration file, a preset producer template corresponding to the type of the message queue on the target cloud is configured to obtain a producer instance, and according to the configuration file, a preset consumer template corresponding to the type of the message queue on the target cloud is configured to obtain a consumer instance; Message processing operations are performed between the target object and the message queue on the target cloud through the producer instance and the consumer instance.

2. The method for multi-cloud adaptation of a message queue according to claim 1, characterized in that: The configuring a preset producer template according to the configuration file to obtain a producer instance, and configuring a preset consumer template according to the configuration file to obtain a consumer instance, includes: Acquire a target producer template and a target consumer template corresponding to the type of the target cloud message queue from a preset template library; Adding configuration parameters of each configuration item in the configuration file to the target producer template to obtain one or more producer instances; The configuration parameters of each configuration item in the configuration file are added to the target consumer template to obtain one or more consumer instances.

3. The method for multi-cloud adaptation of a message queue according to claim 1 or 2, characterized in that: The performing a message processing operation between the target object and the message queue on the target cloud through the producer instance and the consumer instance includes: Acquire a message to be sent generated by the target object; wherein the message to be sent includes: a message header and a message body, and the message header includes a message subject and a message tag; The message to be sent is sent to the message queue on the target cloud through the producer instance.

4. The method for multi-cloud adaptation of a message queue according to claim 3, characterized in that: The sending the message to be sent to the message queue on the target cloud through the producer instance includes: Determine whether the transmission mode of the message queue on the target cloud is point-to-point mode; If yes, obtain the message subject and message tag in the message to be sent, and obtain the group number of the consumer for consuming the message to be sent; Searching, through the producer instance, from the target cloud for a target message queue whose queue name includes the message subject, message tag, and group number; wherein the target cloud includes multiple message queues; The message to be sent is sent to the target message queue through the producer instance.

5. The method for multi-cloud adaptation of a message queue according to claim 1 or 2, characterized in that: The performing a message processing operation between the target object and the message queue on the target cloud through the producer instance and the consumer instance includes: Obtaining the message to be consumed from the message queue on the target cloud through the consumer instance; Send the message to be consumed to the target object.

6. The method for multi-cloud adaptation of a message queue according to claim 5, characterized in that: The obtaining the to-be-consumed message from the message queue on the target cloud through the consumer instance includes: Determine whether the transmission mode of the message queue on the target cloud is point-to-point mode; If yes, then obtain the message topic and message tag subscribed by the target object, and obtain the group number of the target object; Searching, through the consumer instance, from the target cloud for a target message queue whose queue name includes the message subject, message tag, and group number; wherein the target cloud includes multiple message queues; Obtain the message to be consumed from the target message queue through the consumer instance.

7. The method for multi-cloud adaptation of a message queue according to claim 1, characterized in that: The message queues on the target cloud include the following types: RocketMQ, RabbitMQ, Kafka, Tencent Cloud's TDMQ, AWS's SQS and IOT's EMQ.

8. A message queue multi-cloud adaptation device, characterized in that: Applied to a target object that needs to use a cloud message queue, the device includes: A receiving module, configured to receive a cloud migration instruction for switching an existing cloud connected to the target object to a target cloud; A parsing module, used to parse the cloud migration instruction to obtain a configuration file corresponding to the type of the message queue on the target cloud; A configuration module, configured to configure a preset producer template corresponding to the type of the message queue on the target cloud according to the configuration file to obtain a producer instance, and to configure a preset consumer template corresponding to the type of the message queue on the target cloud according to the configuration file to obtain a consumer instance; A processing module is used to perform message processing operations between the target object and the message queue on the target cloud through the producer instance and the consumer instance.

9. A computer device, comprising: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the method according to any one of claims 1 to 7 when executing the computer program.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.