Extension methods based on Spring Cloud Stream's message-driven programming model

By dynamically creating and binding message channels in the Spring Bean lifecycle, the problems of complex configuration and verbose files in the Spring Cloud Stream programming model are solved, enabling more flexible message-driven business support.

CN116225735BActive Publication Date: 2025-12-02XIAMEN NANXUN CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310054092.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-02-03
Publication Date
2025-12-02
Estimated Expiration
2043-02-03

AI Technical Summary

Technical Problem

The existing Spring Cloud Stream programming model cannot dynamically create and bind message channels, resulting in complex configurations and an increased number of files, making it difficult to adapt to dynamic operating conditions.

Method used

In the initialization callback method of the Spring Bean lifecycle, a message input channel is dynamically created and a message queue consumer processor is registered. The message subscription channel is cached using the @MQListener annotation method, and the cache is iterated and bound and started after the project starts. A message output channel is dynamically created and messages are sent.

Benefits of technology

It enables the dynamic creation and binding of message channels during message production and consumption, supports more flexible message-driven business scenarios, simplifies configuration, and reduces the number of files.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116225735B_ABST
    Figure CN116225735B_ABST
Patent Text Reader

Abstract

This invention discloses an extension method for the message-driven programming model based on Spring Cloud Stream, comprising the following steps: S1, starting the Spring project and initializing the environment configuration of the message queue middleware; S2, initializing the configuration of the message queue consumer and calling the built-in message queue consumer processor to dynamically create a message input channel, and registering the Bean logic of the message queue consumer listener processor into the Spring container; S3, dynamically creating and caching the message subscription channel using the @MQListener annotation method; S4, after the Spring project starts, iterating through the cache in the message subscription channel to bind and start the message queue consumer; S5, initializing the configuration of the message queue producer, calling the built-in message queue producer processor to dynamically create and bind the message output channel, and sending messages. The method of this invention achieves the feature of dynamically creating and binding message channels in message production and message consumption, thereby supporting more flexible message-driven business scenarios.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer technology, and in particular to an extension method based on the message-driven programming model of Spring Cloud Stream. Background Technology

[0002] Spring Cloud Stream is a framework for building message-driven microservices. It solves the problem of developers using various message middleware without being aware of it. Spring Cloud Stream relies on configuration adjustments to support dynamic switching between different types of message middleware and the maintenance of corresponding message channels (including default message channels or custom message channels), allowing applications to focus more on their own business implementation.

[0003] Currently, Spring Cloud Stream's programming model pre-binds message channels via configuration files, and then explicitly declares the corresponding message channels in the message production and message listening consumer classes through Spring Bean injection and annotations (managed objects at runtime). The problem with this approach is that message channels cannot be dynamically created and bound in message production and message listening consumption. When the program needs to dynamically switch to the corresponding MQ consumer and MQ producer (MQ, Message Queue) based on dynamic runtime conditions (such as group ID), it requires pre-configuring message input / output channels. This not only results in lengthy, complex, and difficult-to-maintain configuration items, but also necessitates creating a large number of supporting class files with the same functionality, significantly increasing the number of program files. Summary of the Invention

[0004] To address the aforementioned issues, this invention provides an extended method based on the Spring Cloud Stream message-driven programming model.

[0005] The present invention adopts the following technical solution:

[0006] The extension method based on the Spring Cloud Stream message-driven programming model includes the following steps:

[0007] S1. Start the Spring project and initialize the environment configuration for the message queue middleware;

[0008] S2. In the initialization callback method of the Spring Bean lifecycle, initialize the configuration of the message queue consumer and call the built-in message queue consumer processor to dynamically create the message input channel, and register the Bean logic of the message queue consumer listener processor into the Spring container.

[0009] S3. In the post-processor initialization callback method of the Spring Bean lifecycle, use the @MQListener annotation to dynamically create and cache message subscription channels;

[0010] S4. After the Spring project starts, iterate through the cache in the message subscription channel to bind and start the message queue consumers;

[0011] S5. Initialize the message queue producer configuration, call the built-in message queue producer processor to dynamically create and bind message output channels, and send messages.

[0012] Furthermore, the environment configuration of the message queue middleware includes the default binder and binder list messages under the Spring Cloud Stream configuration item.

[0013] Furthermore, the binder list information includes message queue producer policy configuration information, message queue consumer policy configuration information, and message queue server connection information.

[0014] Furthermore, the configuration of the message queue consumer includes channel topic, exception retry policy, consumption group, and binder.

[0015] Furthermore, the message subscription channel is used to listen to messages in the message queue under the corresponding channel topic of the message queue consumer.

[0016] Furthermore, the Spring Bean lifecycle includes the instantiation, property population, and initialization of Bean objects during the startup phase of the Spring project.

[0017] Furthermore, in step S4, the message queue consumers are started one by one only after all the message queue consumers in the message subscription channel have been successfully bound. If any message queue consumer fails to start, the start of all message queue consumers is stopped.

[0018] Furthermore, the configuration of the message queue producer includes channel topics, producer groups, and binders.

[0019] Furthermore, the built-in message queue consumer processor is used to uniformly execute the dynamic creation of message input channels and the registration of the Bean logic of the message queue consumer listener processor.

[0020] Furthermore, the built-in message queue producer processor is used to uniformly execute the dynamic creation of message output channels, the registration of the bean logic of the message queue producer processor, and the binding of message output channels.

[0021] By adopting the above technical solution, the present invention has the following advantages compared with the prior art:

[0022] This invention extends the message-driven programming model of Spring Cloud Stream, enabling it to dynamically create and bind message channels during message production and consumption, thereby supporting more flexible message-driven business scenarios. Attached Figure Description

[0023] Figure 1 This is a flowchart of the method of the present invention. Detailed Implementation

[0024] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention. Example

[0025] like Figure 1 As shown, the extension method based on the Spring Cloud Stream message-driven programming model includes the following steps:

[0026] S1. Start the Spring project and initialize the environment configuration for the message queue middleware;

[0027] The environment configuration of the message queue middleware includes the default binder and binder list messages under the Spring Cloud Stream configuration item. The binder list information includes message queue producer strategy configuration information, message queue consumer strategy configuration information, and message queue server connection information.

[0028] S2. In the initialization callback method of the Spring Bean lifecycle, initialize the configuration of the message queue consumer and call the built-in message queue consumer processor to dynamically create the message input channel, and register the Bean logic of the message queue consumer listener processor into the Spring container.

[0029] The configuration of the message queue consumer includes channel topics, exception retry policies, consumption groups, and binders. The built-in message queue consumer processor is used to uniformly execute the dynamic creation of message input channels and the registration of the Bean logic of the message queue consumption listener processor.

[0030] S3. In the post-processor initialization callback method of the Spring Bean lifecycle, use the @MQListener annotation to dynamically create and cache message subscription channels;

[0031] The message subscription channel is used to listen for messages in the message queue under the corresponding channel topic of the message queue consumer. The Spring Bean lifecycle includes the instantiation, property population, and initialization of Bean objects during the startup phase of the Spring project.

[0032] S4. After the Spring project starts, iterate through the cache in the message subscription channel to bind and start the message queue consumers;

[0033] In step S4, message queue consumers are started one by one only after all message queue consumers in the message subscription channel have been successfully bound. If any message queue consumer fails to start, the start of all message queue consumers is stopped.

[0034] S5. Initialize the message queue producer configuration, call the built-in message queue producer processor to dynamically create and bind message output channels, and send messages.

[0035] The configuration of the message queue producer includes channel topics, producer groups, and binders. The built-in message queue producer processor is used to uniformly execute the dynamic creation of message output channels, the registration of the message queue producer processor's Bean logic, and the binding of message output channels.

[0036] This embodiment extends the message-driven programming model of Spring Cloud Stream, enabling it to dynamically create and bind message channels during message production and consumption, thereby supporting more flexible message-driven business scenarios.

[0037] The above description is merely a preferred embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.

Claims

1. An extension method based on the message-driven programming model of Spring Cloud Stream, characterized by: Includes the following steps: S1. Start the Spring project and initialize the environment configuration for the message queue middleware; S2. In the initialization callback method of the Spring Bean lifecycle, initialize the configuration of the message queue consumer and call the built-in message queue consumer processor to dynamically create the message input channel, and register the Bean logic of the message queue consumer listener processor into the Spring container. S3. In the post-processor initialization callback method of the Spring Bean lifecycle, use the @MQListener annotation to dynamically create and cache message subscription channels; S4. After the Spring project starts, iterate through the cache in the message subscription channel to bind and start the message queue consumers; S5. Initialize the message queue producer configuration, call the built-in message queue producer processor to dynamically create and bind message output channels, and send messages.

2. The extended method based on the message-driven programming model of Spring Cloud Stream as described in claim 1, characterized in that: The environment configuration of the message queue middleware includes the default binder and binder list messages under the Spring Cloud Stream configuration item.

3. The extended method based on the message-driven programming model of Spring Cloud Stream as described in claim 2, characterized in that: The binder list information includes message queue producer policy configuration information, message queue consumer policy configuration information, and message queue server connection information.

4. The extended method based on the message-driven programming model of Spring Cloud Stream as described in claim 3, characterized in that: The configuration of the message queue consumer includes channel topic, exception retry policy, consumption group, and binder.

5. The extended method based on the message-driven programming model of Spring Cloud Stream as described in claim 4, characterized in that: The message subscription channel is used to listen to messages in the message queue under the corresponding channel topic of the message queue consumer.

6. The extended method based on the message-driven programming model of Spring Cloud Stream as described in claim 5, characterized in that: The Spring Bean lifecycle includes the instantiation, property population, and initialization of Bean objects during the startup phase of the Spring project.

7. The extended method based on the message-driven programming model of Spring Cloud Stream as described in claim 6, characterized in that: In step S4, message queue consumers are started one by one only after all message queue consumers in the message subscription channel have been successfully bound. If any message queue consumer fails to start, the start of all message queue consumers is stopped.

8. The extended method based on the message-driven programming model of Spring Cloud Stream as described in claim 7, characterized in that: The configuration of the message queue producer includes channel topic, producer group, and binder.

9. The extended method based on the message-driven programming model of Spring Cloud Stream as described in claim 8, characterized in that: The built-in message queue consumer processor is used to uniformly execute the dynamic creation of message input channels and the registration of the Bean logic of the message queue consumer listener processor.

10. The extended method based on the message-driven programming model of Spring Cloud Stream as described in claim 9, characterized in that: The built-in message queue producer processor is used to uniformly perform the dynamic creation of message output channels, the registration of the bean logic of the message queue producer processor, and the binding of message output channels.

Citation Information

Patent Citations

  • Configuration-based message queue component and integration method thereof

    CN106933589A

  • Http request processing method and device

    CN111444449A