Message Processing Method, Device, Computer Equipment and Storage Medium
By indirectly calling the initial processing function of the message middleware when receiving the message middleware call request, the standard processing function and the target adapter are used to indirectly call the message middleware initial processing function, the problem of modifying the call request code in the prior art is solved, and the message processing efficiency is improved.
Patent Information
- Application Number
- CN202110914770.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-10
- Publication Date
- 2025-06-27
- Estimated Expiration
- 2041-08-10
AI Technical Summary
In the prior art, when calling different message middleware, it is necessary to modify the call request code in a targeted manner, resulting in low message processing efficiency.
When receiving the message middleware call request, the initial processing function is indirectly called according to the standard processing function for message processing, and the target adapter is used to transfer the standard interface and message middleware to uniformly call the initial processing functions of different message middleware.
It avoids the problem of modifying the call request code when calling different message middleware, and improves the efficiency of message processing.
Smart Images

Figure CN113626222B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of infrastructure operation and maintenance, and particularly to a message processing method, apparatus, computer device, and storage medium. Background Art
[0002] Message middleware is an important foundation for communication between various business systems. Among them, the business system can be an insurance business system, a medical platform, etc. The calling methods of existing various message middleware are different, but the basic principles are the same. Each middleware consists of a producer, a consumer, a message topic, a message queue, and a message body. In actual application scenarios, business systems usually need to call different message middleware for different scenarios; since the calling methods of each message middleware are different, it is necessary to modify the calling request code specifically to achieve normal calling of the message middleware for message processing. Therefore, it takes a long time, resulting in low message processing efficiency.
[0003] Therefore, how to improve the efficiency of message processing has become an urgent problem to be solved. Summary of the Invention
[0004] This application provides a message processing method, apparatus, computer device, and storage medium, which realizes that when receiving a message middleware calling request, indirectly calls an initial processing function through a standard processing function for message processing, avoiding the problem of specifically modifying the calling request code when calling the initial processing functions of different message middleware, and improving the efficiency of message processing.
[0005] In a first aspect, this application provides a message processing method, and the method includes:
[0006] When receiving a message middleware calling request based on a preset standard interface, determine a first message middleware to be called;
[0007] Determine a target adapter corresponding to the calling request, where the target adapter is used to transfer the standard interface and the first message middleware;
[0008] According to the target adapter, determine an initial processing function to be called corresponding to the first message middleware;
[0009] Execute a standard processing function in the standard interface to call the initial processing function for message processing based on the target adapter, where the standard processing function is used to call the initial processing function.
[0010] In a second aspect, this application further provides a message processing apparatus, and the apparatus includes:
[0011] A message middleware determination module, configured to determine a first message middleware to be called when a message middleware call request is received based on a preset standard interface;
[0012] An adapter determination module, configured to determine a target adapter corresponding to the call request, where the target adapter is used to transfer the standard interface and the first message middleware;
[0013] An initial processing function determination module, configured to determine an initial processing function to be called corresponding to the first message middleware according to the target adapter;
[0014] A standard processing function execution module, configured to execute a standard processing function in the standard interface to call the initial processing function for message processing based on the target adapter, where the standard processing function is used to call the initial processing function.
[0015] In a third aspect, the present application further provides a computer device, where the computer device includes a memory and a processor;
[0016] The memory is used to store a computer program;
[0017] The processor is configured to execute the computer program and implement the message processing method as described above when executing the computer program.
[0018] In a fourth aspect, the present application further provides a computer-readable storage medium, where the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the processor is caused to implement the message processing method as described above.
[0019] The present application discloses a message processing method, apparatus, computer device, and storage medium. When a message middleware call request is received based on a preset standard interface, a first message middleware to be called is determined, so that message processing can be implemented by calling the first message middleware through a unified standard interface; by determining a target adapter corresponding to the call request, a target adapter for transferring the standard interface and the first message middleware can be obtained, and subsequently, based on the target adapter, an initial processing function in the first message middleware can be indirectly called according to the standard processing function in the standard interface; by determining the type of the target adapter, an initial processing function to be called corresponding to the first message middleware can be determined; by executing the standard processing function in the standard interface to call the initial processing function for message processing based on the target adapter, it can be implemented that the standard processing function uniformly calls the initial processing functions of different message middleware for message processing, avoiding the problem that the call request code needs to be modified specifically when calling the initial processing functions of different message middleware, and improving the efficiency of message processing. Description of the Drawings
[0020] To more clearly illustrate the technical solutions of the embodiments of the present application, the accompanying drawings required for the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings in the following description are some embodiments of the present application. For those of ordinary skill in the art, without creative efforts, other accompanying drawings can be obtained based on these drawings.
[0021] Figure 1 It is a schematic flowchart of a message processing method provided by an embodiment of the present application;
[0022] Figure 2 It is a schematic diagram of an adapter adapting a standard interface and a first message middleware provided by an embodiment of the present application;
[0023] Figure 3 It is another schematic diagram of an adapter adapting a standard interface and a first message middleware provided by an embodiment of the present application;
[0024] Figure 4 It is a schematic flowchart of sub-steps for standardizing each message middleware to a standard interface through an adapter provided by an embodiment of the present application;
[0025] Figure 5 It is a schematic diagram of standardizing each message middleware to a standard interface through an adapter provided by an embodiment of the present application;
[0026] Figure 6 It is another schematic diagram of standardizing each message middleware to a standard interface through an adapter provided by an embodiment of the present application;
[0027] Figure 7 It is another schematic diagram of standardizing each message middleware to a standard interface through an adapter provided by an embodiment of the present application;
[0028] Figure 8 It is a schematic block diagram of a message processing device provided by an embodiment of the present application;
[0029] Figure 9 It is a schematic block diagram of the structure of a computer device provided by an embodiment of the present application. Detailed implementation manners
[0030] Next, the technical solutions in the embodiments of the present application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are some, rather than all, of the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts fall within the scope of protection of the present application.
[0031] The flowcharts shown in the accompanying drawings are merely illustrative examples and do not necessarily include all content and operations / steps, nor are they necessarily executed in the order described. For example, some operations / steps can be decomposed, combined, or partially merged, so the actual execution order may change according to the actual situation.
[0032] It should be understood that the terms used in this application specification are only for the purpose of describing specific embodiments and are not intended to limit this application. As used in this application specification and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an", and "the" are intended to include the plural forms.
[0033] It should also be understood that the term "and / or" used in this application specification and the appended claims refers to any combination and all possible combinations of one or more of the associated listed items, and includes these combinations.
[0034] Embodiments of the present application provide a message processing method, apparatus, computer device, and storage medium. Among them, the message processing method can be applied to a server or a terminal, and when receiving a call request from a message middleware, it indirectly calls an initial processing function according to a standard processing function to perform message processing, avoiding the problem of having to modify the call request code specifically when calling the initial processing functions of different message middleware, and improving the efficiency of message processing.
[0035] Among them, the server can be an independent server or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, Content Delivery Network (CDN), and big data and artificial intelligence platforms. The terminal can be an electronic device such as a smart phone, a tablet computer, a notebook computer, and a desktop computer.
[0036] The following will describe in detail some embodiments of the present application with reference to the accompanying drawings. Without conflict, the following embodiments and the features in the embodiments can be combined with each other.
[0037] As Figure 1 shown, the message processing method includes steps S10 to S40.
[0038] Step S10: When receiving a message middleware call request based on a preset standard interface, determine the first message middleware to be called.
[0039] It should be noted that the message processing method provided by the embodiments of this application can be applied to scenarios where a business system calls a message middleware for message processing. For example, the business system can send a message middleware call request to a standard interface, causing the server or terminal to execute the standard processing function in the standard interface to call the initial processing function in the message middleware for message processing based on the target adapter. Thus, the problem of having to specifically modify the call request code when calling the initial processing functions of different message middleware can be avoided, improving the efficiency of message processing.
[0040] Exemplarily, the business system can include but is not limited to a claim reporting system, a claim investigation system, a medical platform, and the like. For example, the claim reporting system can send a message middleware call request to the standard interface to call the message middleware to produce messages. Again, for example, the claim investigation system can send a message middleware call request to the standard interface to call the message middleware to consume messages.
[0041] Exemplarily, the user can query medical data through the medical platform, such as personal health records, prescriptions, inspection reports, and other data. The medical platform can call the message middleware to produce messages and consume messages to return the data required by the user.
[0042] In some embodiments, when a message middleware call request is received based on a preset standard interface, the first message middleware to be called is determined. Exemplarily, the message middleware currently installed on the server or terminal can be determined as the first message middleware to be called.
[0043] Exemplarily, the message middleware can include but is not limited to Kafka, ActiveMQ, RabbitMQ, and RocketMQ, etc.
[0044] It should be noted that the user can install and start the message middleware to be used on the server or terminal according to business requirements; then create a message topic for the message middleware to enable the message middleware to have the ability to produce messages and consume messages. Among them, the message middleware can include parts such as producers, consumers, message topics, message queues, and message bodies. It can be understood that producing messages means that the producer writes messages into the message queue; consuming messages means that the consumer reads messages from the message queue.
[0045] Exemplarily, in the embodiments of this application, the standard interface can be one or two. When there are two standard interfaces, it can include a message production interface and a message consumption interface. Among them, the message production interface is used to receive call requests with a message processing type of message production processing type; the message consumption interface is used to receive call requests with a message processing type of message consumption processing type.
[0046] When a message middleware call request is received through a preset standard interface, determining a first message middleware to be called can implement calling the first message middleware through the unified standard interface for message processing.
[0047] Step S20: Determine a target adapter corresponding to the call request, where the target adapter is used to transfer the standard interface and the first message middleware.
[0048] It should be noted that the adapter refers to the adapter in the adapter pattern. The main idea of the adapter pattern is to transform the interface of a class into another interface, so that two classes that originally could not work together due to interface mismatch can work together.
[0049] Exemplarily, the adapter pattern includes a source, an adapter, and a target. Among them, the source refers to the object or class to be adapted; the adapter refers to the intermediate object connecting the target and the source; the target refers to the expected target. In the embodiments of the present application, the source refers to the message middleware; the target refers to the standard interface. It should be noted that in the prior art, if you want to call the message middleware through the standard interface, you need to consider the call method in the message middleware and modify the call request code for different message middleware; while in the embodiments of the present application, by using the adapter to transfer the standard interface and the message middleware, it is possible to directly call the message middleware through the standard interface without paying attention to the call method of the message middleware. Thus, the efficiency of calling the message middleware is improved, and further the efficiency of message processing.
[0050] In some embodiments, determining the target adapter corresponding to the call request may include: determining the target adapter according to the message processing type of the call request, where the message processing type includes a production message processing type and a consumption message processing type.
[0051] It should be noted that in the embodiments of the present application, the adapters for transferring the standard interface and the first message middleware include a first type of adapter and a second type of adapter. Among them, the first type of adapter takes effect when producing messages; the second type of adapter takes effect when consuming messages.
[0052] Exemplarily, the target adapter corresponding to the call request may be determined according to the message processing type of the call request.
[0053] In some implementation manners, determining the target adapter according to the message processing type of the call request may include: when the message processing type is the production message processing type, determining the first type of adapter as the target adapter; when the message processing type is the consumption message processing type, determining the second type of adapter as the target adapter.
[0054] Please refer to Figure 2 ,Figure 2 It is a schematic diagram of an adapter for connecting a standard interface and a first message middleware provided by an embodiment of the present application. As Figure 2 shown, when there is only one standard interface, the adapter of the first message middleware is connected to the standard interface. Among them, the adapter can include a first type of adapter and a second type of adapter.
[0055] It should be noted that when there is only one standard interface, all call requests are received through the standard interface; therefore, the target adapter corresponding to the call request can be determined by the message processing type of the call request. Among them, the message processing type of the call request can be determined according to the type identifier in the call request. For example, when the business system sends a call request, different type identifiers can be added to the call request to distinguish the message processing types of the call requests.
[0056] In an embodiment of the present application, when the standard interface includes a production message interface and a consumption message interface, the target adapter can be determined according to the type of the standard interface.
[0057] Please refer to Figure 3 , Figure 3 It is another schematic diagram of an adapter for connecting a standard interface and a first message middleware provided by an embodiment of the present application. As Figure 3 shown, the adapter of the first message middleware includes a first type of adapter and a second type of adapter; among them, the first type of adapter is used to connect the production message interface and the first message middleware, and the second type of adapter is used to connect the consumption message interface and the first message middleware.
[0058] Exemplarily, when the standard interface for receiving the call request is the production message interface, the first type of adapter is determined as the target adapter.
[0059] Exemplarily, when the standard interface for receiving the call request is the consumption message interface, the second type of adapter is determined as the target adapter.
[0060] By determining the target adapter corresponding to the call request, the target adapter for connecting the standard interface and the first message middleware can be obtained. Subsequently, based on the target adapter, the initial processing function in the first message middleware can be indirectly called according to the standard processing function in the standard interface for message processing.
[0061] In the embodiments of the present application, adapters for each message middleware can be pre-generated. Through the adapters, each message middleware is standardized to a standard interface, so as to realize the unified invocation of the message middleware through the standard interface. Among them, standardization refers to the process of mapping the initial message functions of the message middleware into the same standard message functions and encapsulating the mapped standard message functions into the standard interface. Thus, the initial message functions of each message middleware can be invoked through the standard message functions in the standard interface for message processing; there is no need to pay attention to the initial message functions of the message middleware, nor to modify the call request code, which improves the efficiency of invoking the message middleware and further improves the efficiency of message processing.
[0062] Exemplarily, the initial message functions may include an initial production message function and an initial consumption message function. Among them, the initial production message function refers to the method for the producer of the message middleware to write messages into the message queue; the initial consumption message function refers to the method for the consumer of the message middleware to read messages from the message queue.
[0063] It should be noted that for different message middleware, the corresponding initial production message functions and initial consumption message functions are different. For example, the initial production message function of the Kafka message middleware is the KafkaProducer.send function, and the initial consumption message function is the KafkaConsumer.subscribe function; the initial production message function of the RocketMQ message middleware is the DefaultMQProducer.send function, and the initial consumption message function is the DefaultMQPushConsumer.consumeMessage function; the initial production message function of the ActiveMQ message middleware is the MessageProducer.send function, and the initial consumption message function is the MessageConsumer.Receive function.
[0064] It can be understood that by invoking the unified standard message function, it is essentially to invoke the initial message function of the message middleware for message processing; therefore, the problem of needing to specifically modify the call request code when invoking the initial processing functions of different message middleware can be avoided, and the efficiency of message processing is improved.
[0065] Please refer to Figure 4 , Figure 4 which is a schematic flowchart of the sub-steps for standardizing each message middleware to a standard interface through an adapter provided by the embodiments of the present application, and specifically may include the following steps S201 to step S203.
[0066] Step S201, generate a plurality of adapters corresponding to each message middleware, and the adapters include a first type of adapter and a second type of adapter.
[0067] Exemplarily, a first type of adapter and a second type of adapter corresponding to each message middleware can be created. It should be noted that since the initial production message functions and initial consumption message functions corresponding to different message middleware are different, it is necessary to create a first type of adapter and a second type of adapter corresponding to each message middleware. Thus, the initial production message function corresponding to the message middleware can be standardized to a standard interface through the first type of adapter, and the initial consumption message function corresponding to the message middleware can be standardized to the standard interface through the second type of adapter.
[0068] Please refer to Figure 5 , Figure 5 which is a schematic diagram of standardizing each message middleware to a standard interface through an adapter provided by an embodiment of the present application. As Figure 5 shown, the standard interface includes a production message interface and a consumption message interface; the first type of adapter of each message middleware is connected to the production message interface, and the second type of adapter of each message middleware is connected to the consumption message interface. For example, the first type of adapter of the Kafka message middleware is connected to the production message interface, and the second type of adapter is connected to the consumption message interface. The first type of adapter of the RocketMQ message middleware is connected to the production message interface, and the second type of adapter is connected to the consumption message interface. The first type of adapter of the ActiveMQ message middleware is connected to the production message interface, and the second type of adapter is connected to the consumption message interface.
[0069] Step S202, call the first type of adapter of each of the message middleware, map the initial production message function in each of the message middleware to a preset standard production message function, and encapsulate the mapped standard production message function into the production message interface.
[0070] It should be noted that mapping refers to the process of establishing a correspondence relationship of data elements between two models. In the embodiments of the present application, by mapping the initial production message function in each message middleware to a preset standard production message function, the initial production message function can be called through the standard production message function.
[0071] Exemplarily, the preset standard production message function can be the StandardMQ.publish function.
[0072] In some embodiments, the first type of adapter of each message middleware can be called to map the initial production message function in each message middleware to a preset standard production message function, and encapsulate the mapped standard production message function into the production message interface.
[0073] It should be noted that encapsulation is a function of a function, which is used to encapsulate one or more functions in the form of functions or classes and only provide a simple function interface to the outside world.
[0074] Exemplarily, for the Kafka message middleware, the initial production message function KafkaProducer.send of the Kafka message middleware can be mapped to the standard production message function StandardMQ.publish, so that there is a mapping relationship between the standard production message function StandardMQ.publish and the initial production message function KafkaProducer.send. By executing the standard production message function StandardMQ.publish, the initial production message function KafkaConsumer.subscribe can be called. For the RocketMQ message middleware, the initial production message function DefaultMQProducer.send of the RocketMQ message middleware can be mapped to the standard production message function StandardMQ.publish, so that there is a mapping relationship between the standard production message function StandardMQ.publish and the initial production message function DefaultMQProducer.send.
[0075] Exemplarily, the mapped standard production message function can be encapsulated into the production message interface.
[0076] It should be noted that since the standard production message function StandardMQ.publish has a mapping relationship with multiple initial production message functions, when the standard production message function StandardMQ.publish is executed, the initial production message function to be called can be determined through the first-class adapter of the current message middleware.
[0077] Exemplarily, the initial production message function corresponding to each message middleware can be associated with the first-class adapter corresponding to each message middleware, and the association relationship can be added to the standard production message function. Thus, when the standard production message function is executed, the initial production message function to be called can be determined according to the transfer standard interface and the first-class adapter of the message middleware.
[0078] By calling the first-class adapter of each message middleware, mapping the initial production message function in each message middleware to the preset standard production message function, and encapsulating the mapped standard production message function into the production message interface, it is possible to uniformly call the initial production message function of the message middleware through the standard production message function in the production message interface.
[0079] Step S203: Invoke the second - type adapter corresponding to each of the message middleware, map the initial consumption message function of each message middleware to a preset standard consumption message function, and encapsulate the mapped standard consumption message function into the consumption message interface.
[0080] Exemplarily, the preset standard consumption message function can be the StandardMQ.subscribe function.
[0081] Exemplarily, for the Kafka message middleware, the initial consumption message function KafkaConsumer.subscribe of the Kafka message middleware can be mapped to the standard consumption message function StandardMQ.subscribe, so that there is a mapping relationship between the standard consumption message function StandardMQ.subscribe and the initial consumption message function KafkaConsumer.subscribe. By executing the standard consumption message function StandardMQ.publish, the initial consumption message function KafkaConsumer.subscribe can be invoked. For the RocketMQ message middleware, the initial consumption message function DefaultMQPushConsumer.consumeMessage of the RocketMQ message middleware can be mapped to the standard consumption message function StandardMQ.subscribe, so that there is a mapping relationship between the standard consumption message function StandardMQ.subscribe and the initial consumption message function DefaultMQPushConsumer.consumeMessage.
[0082] Exemplarily, the mapped standard consumption message function can be encapsulated into the consumption message interface.
[0083] It should be noted that since the standard consumption message function StandardMQ.subscribe has a mapping relationship with multiple initial consumption message functions, when the standard consumption message function StandardMQ.subscribe is executed, the initial consumption message function to be invoked can be determined through the second - type adapter of the current message middleware.
[0084] In some embodiments, the initial consumption message function corresponding to each message middleware can be associated with the second - type adapter corresponding to each message middleware, and the association relationship is added to the standard consumption message function. Thus, when the standard consumption message function is executed, the initial consumption message function to be invoked can be determined according to the transfer standard interface and the second - type adapter of the message middleware.
[0085] By invoking the second - type adapters of each message middleware, mapping the initial consumption message functions in each message middleware to preset standard consumption message functions, and encapsulating the mapped standard consumption message functions into a consumption message interface, it is possible to uniformly call the initial consumption message functions of the message middleware through the standard consumption message functions in the consumption message interface.
[0086] Please refer to Figure 6 , Figure 6 FIG. is another schematic diagram provided by an embodiment of the present application for standardizing each message middleware to a standard interface through an adapter. As Figure 6 shown, when there is only one standard interface, the adapter of each message middleware is connected to the standard interface. Exemplarily, by invoking the adapter of each message middleware, mapping the initial message functions in each message middleware to preset standard message functions, and encapsulating the mapped standard message functions into the standard interface. For example, by invoking the adapter of the Kafka message middleware, mapping the initial message functions in the Kafka message middleware to preset standard message functions; and for another example, by invoking the adapter of the Kafka message middleware, mapping the initial message functions in the RocketMQ message middleware to preset standard message functions. Finally, encapsulate the above - mapped standard message functions into the standard interface.
[0087] Please refer to Figure 7 , Figure 7 FIG. is another schematic diagram provided by an embodiment of the present application for standardizing each message middleware to a standard interface through an adapter. As Figure 7 shown, on the basis of Figure 6 , when the adapter of each message middleware includes a first - type adapter and a second - type adapter, the first - type adapter of each message middleware is connected to the standard interface, and the second - type adapter of each message middleware is connected to the standard interface. Exemplarily, by invoking the first - type adapter of each message middleware, mapping the initial production message functions in each message middleware to preset standard production message functions, and encapsulating the mapped standard production message functions into the standard interface; by invoking the corresponding second - type adapter of each message middleware, mapping the initial consumption message functions of each message middleware to preset standard consumption message functions, and encapsulating the mapped standard consumption message functions into the standard interface. Among them, the specific mapping process and encapsulation process are similar to those in the above - mentioned embodiment, and the specific process will not be elaborated here.
[0088] By generating the first - type adapter and the second - type adapter corresponding to each message middleware, it is possible to standardize the initial production message function corresponding to the message middleware to the standard interface according to the first - type adapter, and standardize the initial consumption message function corresponding to the message middleware to the standard interface according to the second - type adapter.
[0089] In some embodiments, after generating multiple adapters corresponding to each message middleware in step S201, the embodiments of the present application may further include: obtaining a first dependency package corresponding to the first message middleware; and activating the adapter corresponding to the first message middleware according to the first dependency package.
[0090] It should be noted that the dependency package is a bridge for establishing the upper-layer application and the underlying message middleware, and is an environment file required for the normal operation of the adapter. Among them, the dependency package can be a library file, such as a dynamic library file, a static library file, etc. Each message middleware has a unique dependency package, and the message middleware can be associated with the corresponding dependency package in advance.
[0091] Exemplarily, the first type of adapter and the second type of adapter corresponding to the first message middleware can be activated.
[0092] By obtaining the first dependency package corresponding to the first message middleware and activating the adapter corresponding to the first message middleware according to the first dependency package, the adapter can work properly to implement message processing by invoking the initial processing function of the first message middleware based on the adapter.
[0093] In some embodiments, after activating the adapter corresponding to the first message middleware according to the first dependency package, it may further include: when a switching operation on the first dependency package or the first message middleware is detected, determining a second message middleware to be switched and a second dependency package corresponding to the second message middleware according to the switching operation; and activating the adapter corresponding to the second message middleware according to the second dependency package.
[0094] It should be noted that the user can replace the message middleware on the server or terminal according to business requirements.
[0095] Exemplarily, when a switching operation on the first dependency package is detected, determining a second dependency package to be switched according to the switching operation; determining a second message middleware corresponding to the second dependency package based on the preset correspondence between the message middleware and the dependency package; installing and starting the second message middleware, and activating the first type of adapter and the second type of adapter corresponding to the second message middleware according to the second dependency package.
[0096] Exemplarily, when a switching operation on the first message middleware is detected, determining a second message middleware to be switched according to the switching operation; determining a second dependency package corresponding to the second message middleware based on the preset correspondence between the message middleware and the dependency package; installing and starting the second message middleware, and activating the first type of adapter and the second type of adapter corresponding to the second message middleware according to the second dependency package.
[0097] By determining the second message middleware for the switch according to the switching operation and the second dependency package corresponding to the second message middleware, and installing the second message middleware and activating the adapter according to the second dependency package, the replacement of the message middleware can be conveniently achieved without changing the code of the upper-layer application, improving the efficiency of message middleware switching and reducing the cost of switching message middleware.
[0098] Step S30: Determine the initial processing function to be called corresponding to the first message middleware according to the target adapter.
[0099] It can be understood that since there is an association relationship between the initial production message function corresponding to each message middleware and the first type of adapter corresponding to each message middleware, and there is an association relationship between the initial consumption message function corresponding to each message middleware and the second type of adapter corresponding to each message middleware, therefore, the initial processing function to be called corresponding to the first message middleware can be determined according to the target adapter corresponding to the call request.
[0100] In some embodiments, determining the initial processing function to be called corresponding to the first message middleware according to the target adapter may include: when the target adapter is the first type of adapter, determining the initial processing function to be called as the initial production message function in the first message middleware; when the target adapter is the second type of adapter, determining the initial processing function to be called as the initial consumption message function in the first message middleware.
[0101] Exemplarily, for the Kafka message middleware, when the target adapter is the first type of adapter, the initial processing function to be called can be determined as the KafkaProducer.send function; when the target adapter is the second type of adapter, the initial processing function to be called can be determined as the KafkaConsumer.subscribe function.
[0102] Exemplarily, for the RocketMQ message middleware, when the target adapter is the first type of adapter, the initial processing function to be called can be determined as the DefaultMQProducer.send function; when the target adapter is the second type of adapter, the initial processing function to be called can be determined as the DefaultMQPushConsumer.consumeMessage function.
[0103] By determining the initial processing function to be called corresponding to the first message middleware according to the type of the target adapter, an initial processing function matching the target adapter can be obtained, and the corresponding initial processing function can be called based on the target adapter subsequently, avoiding abnormal call situations.
[0104] Step S40: Execute the standard processing function in the standard interface to call the initial processing function based on the target adapter for message processing. The standard processing function is used to call the initial processing function.
[0105] It can be understood that by calling the initial processing function through the standard processing function in the standard interface, the differences in the calling methods between different message middleware are shielded. There is no need to pay attention to the initial processing functions of different message middleware, nor to modify the calling request code specifically.
[0106] It should be noted that when the target adapter is a first-class adapter, the corresponding standard processing function is the standard production message function, and the corresponding initial processing function is the initial production message function; the message processing at this time refers to producing messages. When the target adapter is a second-class adapter, the corresponding standard processing function is the standard consumption message function, and the corresponding initial processing function is the initial consumption message function; the message processing at this time refers to consuming messages.
[0107] Exemplarily, when the first message middleware is Kafka, if the target adapter is a first-class adapter, the standard production message function StandardMQ.publish can be executed to call the initial production message function KafkaProducer.send based on the first-class adapter for message processing. For example, execute the initial production message function KafkaProducer.send to control the producer in the first message middleware to write the message into the message queue.
[0108] Exemplarily, when the first message middleware is Kafka, if the target adapter is a second-class adapter, the standard consumption message function StandardMQ.subscribe can be executed to call the initial consumption message function KafkaConsumer.subscribe based on the second-class adapter for message processing. For example, execute the initial consumption message function KafkaConsumer.subscribe to control the consumer in the first message middleware to read the message from the message queue.
[0109] By executing the standard processing function in the standard interface to call the initial processing function based on the target adapter for message processing, it can be realized that the standard processing function uniformly calls the initial processing functions of different message middleware for message processing, avoiding the problem of specifically modifying the calling request code when calling the initial processing functions of different message middleware, and improving the efficiency of message processing.
[0110] The message processing method provided by the above embodiments can obtain a target adapter for connecting the standard interface and the first message middleware by determining the target adapter corresponding to the call request. Subsequently, based on the target adapter, the initial processing function in the first message middleware can be indirectly called according to the standard processing function in the standard interface for message processing. By generating the first type of adapter and the second type of adapter corresponding to each message middleware, the initial production message function corresponding to the message middleware can be standardized to the standard interface according to the first type of adapter, and the initial consumption message function corresponding to the message middleware can be standardized to the standard interface according to the second type of adapter. By obtaining the first dependency package corresponding to the first message middleware and activating the adapter corresponding to the first message middleware according to the first dependency package, the adapter can work properly to implement message processing by calling the initial processing function of the first message middleware based on the adapter. By determining the switched second message middleware and the second dependency package corresponding to the second message middleware according to the switching operation, and installing the second message middleware and activating the adapter according to the second dependency package, the replacement of the message middleware can be conveniently realized without changing the code of the upper-layer application service, improving the efficiency of message middleware switching and reducing the cost of switching message middleware. By executing the standard processing function in the standard interface to call the initial processing function for message processing based on the target adapter, the initial processing functions of different message middleware can be uniformly called by the standard processing function, avoiding the problem of specifically modifying the call request code when calling the initial processing functions of different message middleware, and improving the efficiency of message processing.
[0111] Please refer to Figure 8 , Figure 8 FIG. is a schematic block diagram of a message processing device 1000 further provided by an embodiment of the present application. The message processing device is used to execute the foregoing message processing method. Among them, the message processing device can be configured in a server or a terminal.
[0112] As Figure 8 shown, the message processing device 1000 includes: a message middleware determination module 1001, an adapter determination module 1002, an initial processing function determination module 1003, and a standard processing function execution module 1004.
[0113] The message middleware determination module 1001 is configured to determine the first message middleware to be called when a message middleware call request is received based on a preset standard interface.
[0114] The adapter determination module 1002 is configured to determine a target adapter corresponding to the call request, where the target adapter is used to connect the standard interface and the first message middleware.
[0115] The initial processing function determination module 1003 is configured to determine the initial processing function to be called corresponding to the first message middleware according to the target adapter.
[0116] The standard processing function execution module 1004 is configured to execute the standard processing function in the standard interface to call the initial processing function for message processing based on the target adapter, and the standard processing function is used to call the initial processing function.
[0117] It should be noted that those skilled in the art can clearly understand that for the convenience and brevity of description, the specific working processes of the above-described device and each module can refer to the corresponding processes in the foregoing method embodiments, and will not be elaborated herein.
[0118] The above device can be implemented in the form of a computer program, and the computer program can run on a computer device as shown in Figure 9 shown.
[0119] Please refer to Figure 9 , Figure 9 which is a schematic block diagram of the structure of a computer device provided by an embodiment of the present application.
[0120] Please refer to Figure 9 , the computer device includes a processor and a memory connected through a system bus, wherein the memory may include a non-volatile storage medium and an internal memory.
[0121] The processor is used to provide computing and control capabilities to support the operation of the entire computer device.
[0122] The internal memory provides an environment for the operation of the computer program in the non-volatile storage medium. When the computer program is executed by the processor, the processor can execute any message processing method.
[0123] It should be understood that the processor may be a central processing unit (CPU), and the processor may also be other general-purpose processors, digital signal processors (DSPs), application specific integrated circuits (ASICs), field programmable gate arrays (FPGAs) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Among them, the general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0124] Among them, in one embodiment, the processor is used to run a computer program stored in a memory to implement the following steps:
[0125] When a message middleware call request is received based on a preset standard interface, determine a first message middleware to be called; determine a target adapter corresponding to the call request, where the target adapter is used to transfer the standard interface and the first message middleware; according to the target adapter, determine an initial processing function to be called corresponding to the first message middleware; execute a standard processing function in the standard interface to call the initial processing function based on the target adapter for message processing, where the standard processing function is used to call the initial processing function.
[0126] In one embodiment, when the processor implements determining the target adapter corresponding to the call request, it is used to implement:
[0127] Determine the target adapter according to the message processing type of the call request, where the message processing type includes a production message processing type and a consumption message processing type.
[0128] In one embodiment, the adapters for transferring the standard interface and the first message middleware include a first type of adapter and a second type of adapter; when the processor implements determining the target adapter according to the message processing type of the call request, it is used to implement:
[0129] When the message processing type is the production message processing type, determine the first type of adapter as the target adapter; when the message processing type is the consumption message processing type, determine the second type of adapter as the target adapter.
[0130] In one embodiment, the initial message functions include an initial production message function and an initial consumption message function, and the standard interfaces include a production message interface and a consumption message interface; before the processor implements determining the target adapter corresponding to the call request, it is also used to implement:
[0131] Generate multiple adapters corresponding to each message middleware, where the adapters include a first type of adapter and a second type of adapter; call the first type of adapter of each message middleware, map the initial production message function in each message middleware to a preset standard production message function, and encapsulate the mapped standard production message function into the production message interface; call the second type of adapter corresponding to each message middleware, map the initial consumption message function of each message middleware to a preset standard consumption message function, and encapsulate the mapped standard consumption message function into the consumption message interface.
[0132] In one embodiment, after the processor implements generating a plurality of adapters corresponding to each message middleware, it is further configured to implement:
[0133] Obtain a first dependency package corresponding to the first message middleware; activate the adapter corresponding to the first message middleware according to the first dependency package.
[0134] In one embodiment, after the processor implements activating the adapter corresponding to the first message middleware according to the first dependency package, it is further configured to implement:
[0135] When a switching operation on the first dependency package or the first message middleware is detected, determine a second message middleware to be switched and a second dependency package corresponding to the second message middleware according to the switching operation; activate the adapter corresponding to the second message middleware according to the second dependency package.
[0136] In one embodiment, when the processor implements determining an initial processing function to be called corresponding to the first message middleware according to the target adapter, it is configured to implement:
[0137] When the target adapter is a first type of adapter, determine the initial processing function to be called as the initial production message function in the first message middleware; when the target adapter is a second type of adapter, determine the initial processing function to be called as the initial consumption message function in the first message middleware.
[0138] An embodiment of the present application further provides a computer-readable storage medium, which stores a computer program, and the computer program includes program instructions. When the processor executes the program instructions, it implements any message processing method provided by the embodiments of the present application.
[0139] For example, when the program is loaded by the processor, the following steps can be executed:
[0140] When a message middleware call request is received based on a preset standard interface, determine a first message middleware to be called; determine a target adapter corresponding to the call request, where the target adapter is used to transfer the standard interface and the first message middleware; determine an initial processing function to be called corresponding to the first message middleware according to the target adapter; execute a standard processing function in the standard interface to call the initial processing function based on the target adapter for message processing, where the standard processing function is used to call the initial processing function.
[0141] Among them, the computer-readable storage medium may be the internal storage unit of the computer device described in the foregoing embodiments, such as the hard disk or memory of the computer device. The computer-readable storage medium may also be an external storage device of the computer device, such as a plug-in hard disk, a SmartMedia Card (SMC), a Secure Digital Card (SD Card), a Flash Card, etc. equipped on the computer device.
[0142] Furthermore, the computer-readable storage medium may mainly include a storage program area and a storage data area. Among them, the storage program area may store an operating system, application programs required for at least one function, etc.; the storage data area may store data created according to the use of the blockchain node, etc.
[0143] The blockchain referred to in this application is a new application mode of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, and encryption algorithm. Blockchain, in essence, is a decentralized database, a string of data blocks generated by using cryptographic methods. Each data block contains information about a batch of network transactions, used to verify the validity (anti-counterfeiting) of the information and generate the next block. The blockchain may include a blockchain underlying platform, a platform product service layer, an application service layer, etc.
[0144] The above is only the specific implementation manner of this application, but the protection scope of this application is not limited thereto. Any person skilled in the art within the technical scope disclosed by this application can easily think of various equivalent modifications or substitutions, and these modifications or substitutions should be covered within the protection scope of this application. Therefore, the protection scope of this application shall be subject to the protection scope of the claims.
Claims
1. A message processing method, characterized in that, Including: When receiving a message middleware call request based on a preset standard interface, determine a first message middleware to be called; Determine a target adapter corresponding to the call request, where the target adapter is used to transfer the standard interface and the first message middleware; According to the target adapter, determine an initial processing function to be called corresponding to the first message middleware; Execute a standard processing function in the standard interface to call the initial processing function based on the target adapter for message processing, where the standard processing function is used to call the initial processing function; Determine a target adapter corresponding to the call request, including: according to the message processing type of the call request, determine the target adapter, where the message processing type includes a production message processing type and a consumption message processing type; The initial processing function includes an initial production message function and an initial consumption message function, and the standard interface includes a production message interface and a consumption message interface; before determining the target adapter corresponding to the call request, the method further includes: Generate multiple adapters corresponding to each message middleware, where the adapters include a first type of adapter and a second type of adapter; call the first type of adapter of each message middleware, map the initial production message function in each message middleware to a preset standard production message function, and encapsulate the mapped standard production message function into the production message interface; call the second type of adapter corresponding to each message middleware, map the initial consumption message function of each message middleware to a preset standard consumption message function, and encapsulate the mapped standard consumption message function into the consumption message interface; After generating multiple adapters corresponding to each message middleware, the method further includes: Obtain a first dependency package corresponding to the first message middleware; according to the first dependency package, activate the adapter corresponding to the first message middleware.
2. The message processing method according to claim 1, wherein The adapter for transferring the standard interface and the first message middleware includes a first type of adapter and a second type of adapter; The determining the target adapter according to the message processing type of the call request includes: When the message processing type is a production message processing type, determine the first type of adapter as the target adapter; When the message processing type is a consumption message processing type, determine the second type of adapter as the target adapter.
3. The message processing method according to claim 1, wherein After activating the adapter corresponding to the first message middleware according to the first dependency package, it further includes: When detecting a switching operation on the first dependency package or the first message middleware, determine a second message middleware to be switched and a second dependency package corresponding to the second message middleware according to the switching operation; According to the second dependency package, activate the adapter corresponding to the second message middleware.
4. The message processing method according to any one of claims 1-3, characterized in that, The determining the initial processing function to be called corresponding to the first message middleware according to the target adapter includes: When the target adapter is a first type of adapter, determine the initial processing function to be called as the initial production message function in the first message middleware; When the target adapter is a second - type adapter, determine that the initial processing function to be called is the initial message consumption function in the first message middleware.
5. A message processing device, characterized in that, For implementing the message processing method according to any one of claims 1 to 4, the message processing device includes: A message middleware determination module, configured to determine a first message middleware to be called when receiving a message middleware call request based on a preset standard interface; An adapter determination module, configured to determine a target adapter corresponding to the call request, where the target adapter is used to transfer the standard interface and the first message middleware; An initial processing function determination module, configured to determine an initial processing function to be called corresponding to the first message middleware according to the target adapter; A standard processing function execution module, configured to execute the standard processing function in the standard interface to call the initial processing function for message processing based on the target adapter, where the standard processing function is used to call the initial processing function.
6. A computer device, characterized in that, The computer device includes a memory and a processor; The memory is used to store a computer program; The processor is configured to execute the computer program and, when executing the computer program, implement the message processing method according to any one of claims 1 to 4.
7. A computer-readable storage medium, characterized in that, The computer - readable storage medium stores a computer program, and when the computer program is executed by a processor, the processor is caused to implement the message processing method according to any one of claims 1 to 4.
Citation Information
Patent Citations
Service information pushing method and device, storage medium and electronic device
CN112788128A