CN116225735A - Extension method of message-driven programming model based on Spring Cloud Stream - Google Patents
Extension method of message-driven programming model based on Spring Cloud Stream Download PDFInfo
- Publication number
- CN116225735A CN116225735A CN202310054092.0A CN202310054092A CN116225735A CN 116225735 A CN116225735 A CN 116225735A CN 202310054092 A CN202310054092 A CN 202310054092A CN 116225735 A CN116225735 A CN 116225735A
- Authority
- CN
- China
- Prior art keywords
- message
- message queue
- spring
- channel
- programming model
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/54—Interprogram communication
- G06F9/546—Message passing systems or structures, e.g. queues
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/44—Arrangements for executing specific programs
- G06F9/445—Program loading or initiating
- G06F9/44505—Configuring for program initiating, e.g. using registry, configuration files
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F2209/00—Indexing scheme relating to G06F9/00
- G06F2209/54—Indexing scheme relating to G06F9/54
- G06F2209/547—Messaging middleware
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02D—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
- Y02D10/00—Energy efficient computing, e.g. low power processors, power management or thermal management
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Data Exchanges In Wide-Area Networks (AREA)
- Telephonic Communication Services (AREA)
- Information Transfer Between Computers (AREA)
Abstract
The invention discloses an expansion method of a message-driven programming model based on SpringCloudStream, which comprises the following steps: s1, starting a Spring item, and initializing environment configuration of a message queue middleware; s2, initializing the configuration of a message queue consumer, calling a built-in message queue consumer processor to dynamically create a message input channel, and registering the message input channel in a Spring container; s3, dynamically creating and caching a message subscription channel by adopting an @ MQListener annotation method; s4, after the Spring item is started, traversing 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 the message. The method of the invention realizes the characteristic of dynamically creating and binding the message channel in the message production and the message consumption, thereby supporting more flexible message-driven business scenes.
Description
Technical Field
The invention relates to the technical field of computers, in particular to an expansion method of a message-driven programming model based on Spring Cloud Stream.
Background
Spring Cloud Stream is a framework for building message-driven microservices that solves the problem of imperceptible use of various message middleware by developers. Spring Cloud Stream relies on configuration adjustments to support dynamic switching of different types of message middleware and maintenance of corresponding message channels (including default or custom message channels) so that applications can pay more attention to their own business implementation.
The current programming model of Spring Cloud Stream adopts a mode of binding a message channel in advance by a configuration file mode, and then injecting and annotating a Spring Bean (management object in the running process of a framework) in consumption processing classes of message production and message monitoring so as to realize the display and statement of the corresponding message channel. The problems with this approach are: the Message channels cannot be dynamically created and bound in the consumption of Message production and Message monitoring, when a program needs to be dynamically switched to corresponding MQ consumers and MQ producers (Message queues) according to dynamic running conditions (such as group IDs), a method of pre-configuring the Message input/output channels is needed, configuration items are long, complex and difficult to maintain, and a large number of supporting class files with the same functions are also needed to be created, so that the number of program files is greatly increased.
Disclosure of Invention
To solve the above problems, the present invention provides an extension method of a message driven programming model based on Spring Cloud Stream.
The invention adopts the following technical scheme:
an extension method of a message driven programming model based on Spring Cloud Stream comprises the following steps:
s1, starting a Spring item, and initializing environment configuration of a message queue middleware;
s2, initializing configuration of a message queue consumer and calling a built-in message queue consumer processor to dynamically create a message input channel in an initialization callback method of a Spring Bean life cycle, and registering the message input channel in a Spring container;
s3, dynamically creating and caching a message subscription channel by adopting an @ MQListener annotation method in a post processor initialization callback method of a Spring Bean life cycle;
s4, after the Spring item is started, traversing 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 the message.
Further, the environment configuration of the message queue middleware includes default binder and binder list messages under Spring Cloud Stream configuration item.
Further, the binder list information includes message queue producer policy configuration information, message queue consumer policy configuration information, and message queue server connection information.
Further, the message queue consumer's configuration includes channel topic, a very-retry policy, a consumer packet, and a binder.
Further, the message subscription channel is configured to monitor messages in a message queue under a corresponding channel theme of the message queue consumer.
Further, the Spring Bean lifecycle includes the steps of performing the instantiation, attribute filling and initialization of Bean objects in the starting stage of the Spring item.
Further, in step S4, the message queue consumers are started one by one only after all the message queue consumers in the buffer memory in the message subscription channel are successfully bound, and if any one message queue consumer fails to start, the starting of all the message queue consumers is stopped.
Further, the message queue producer's configuration includes a channel topic, a producer group, and a binder.
Further, the built-in message queue consumer processor is used for executing the dynamic creation of the message input channel and the registration of the Bean logic of the message queue consumption monitoring processor in a unified way.
Further, the built-in message queue producer processor is configured to perform the dynamic creation of the message output channel, the registration of the Bean logic of the message queue producer processor, and the binding of the message output channel in a unified manner.
After the technical scheme is adopted, compared with the background technology, the invention has the following advantages:
the invention expands the message-driven programming model of Spring Cloud Stream to enable the message-driven programming model to have the characteristic of dynamically creating and binding message channels in message production and message consumption, thereby supporting more flexible message-driven business scenes.
Drawings
FIG. 1 is a flow chart of the method of the present invention.
Detailed Description
The present invention will be described in further detail with reference to the drawings and examples, in order to make the objects, technical solutions and advantages of the present invention more apparent. It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the scope of the invention.
Examples
As shown in fig. 1, the extension method of the message driven programming model based on Spring Cloud Stream includes the following steps:
s1, starting a Spring item, and initializing environment configuration of a message queue middleware;
the environment configuration of the message queue middleware includes default binder and binder list messages under Spring Cloud Stream configuration items. The binder list information includes message queue producer policy configuration information, message queue consumer policy configuration information, and message queue server connection information.
S2, initializing configuration of a message queue consumer and calling a built-in message queue consumer processor to dynamically create a message input channel in an initialization callback method of a Spring Bean life cycle, and registering the message input channel in a Spring container;
the message queue consumer's configuration includes channel topic, special retry policy, consumer group, and binder. The built-in message queue consumer processor is used for uniformly executing dynamic creation of a message input channel and registration of Bean logic of the message queue consumption monitoring processor.
S3, dynamically creating and caching a message subscription channel by adopting an @ MQListener annotation method in a post processor initialization callback method of a Spring Bean life cycle;
the message subscription channel is used for monitoring messages in the message queue under the corresponding channel theme of the message queue consumer. The Spring Bean life cycle comprises the steps of carrying out the instantiation, attribute filling and initialization of Bean objects in the starting stage of the Spring project.
S4, after the Spring item is started, traversing the cache in the message subscription channel to bind and start the message queue consumer;
in step S4, the message queue consumers are started one by one only after all the message queue consumers in the buffer memory in the message subscription channel are successfully bound, and if any one message queue consumer fails to start, the starting of all the message queue consumers is stopped.
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 the message.
The message queue producer's configuration includes channel topics, producer groupings, and binders. The built-in message queue producer processor is used for uniformly executing dynamic creation of the message output channel, registration of Bean logic of the message queue producer processor and binding of the message output channel.
The embodiment expands the message driven programming model of Spring Cloud Stream to enable the message driven programming model to have the characteristic of dynamically creating and binding message channels in message production and message consumption, thereby supporting more flexible message driven business scenarios.
The present invention is not limited to the above-mentioned embodiments, and any changes or substitutions that can be easily understood by those skilled in the art within the technical scope of the present invention are intended to be included in the scope of the present invention. Therefore, the protection scope of the present invention should be subject to the protection scope of the claims.
Claims (10)
1. The expansion method of the message driven programming model based on Spring Cloud Stream is characterized by comprising the following steps of: the method comprises the following steps:
s1, starting a Spring item, and initializing environment configuration of a message queue middleware;
s2, initializing configuration of a message queue consumer and calling a built-in message queue consumer processor to dynamically create a message input channel in an initialization callback method of a Spring Bean life cycle, and registering the message input channel in a Spring container;
s3, dynamically creating and caching a message subscription channel by adopting an @ MQListener annotation method in a post processor initialization callback method of a Spring Bean life cycle;
s4, after the Spring item is started, traversing 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 the message.
2. The method of extension of a Spring Cloud Stream-based message-driven programming model of claim 1, further comprising: the environment configuration of the message queue middleware includes default binder and binder list messages under Spring Cloud Stream configuration items.
3. The method of expanding a message driven programming model based on Spring Cloud Stream of claim 2, further comprising: 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 method for expanding a message driven programming model based on Spring Cloud Stream of claim 3, further comprising: the message queue consumer's configuration includes channel topic, special retry policy, consumer group, and binder.
5. The method of extension of a Spring Cloud Stream-based message-driven programming model of claim 4, wherein: the message subscription channel is used for monitoring messages in the message queue under the corresponding channel theme of the message queue consumer.
6. The method of extension of a Spring Cloud Stream-based message-driven programming model of claim 5, further comprising: the Spring Bean life cycle comprises the steps of carrying out the instantiation, attribute filling and initialization of Bean objects in the starting stage of the Spring project.
7. The method of extension of a Spring Cloud Stream-based message-driven programming model of claim 6, wherein: in step S4, the message queue consumers are started one by one only after all the message queue consumers in the buffer memory in the message subscription channel are successfully bound, and if any one message queue consumer fails to start, the starting of all the message queue consumers is stopped.
8. The method of extension of a Spring Cloud Stream-based message-driven programming model of claim 7, wherein: the message queue producer's configuration includes channel topics, producer groupings, and binders.
9. The method of extension of a Spring Cloud Stream-based message-driven programming model of claim 8, wherein: the built-in message queue consumer processor is used for uniformly executing dynamic creation of a message input channel and registration of Bean logic of the message queue consumption monitoring processor.
10. The method of extension of a Spring Cloud Stream-based message-driven programming model of claim 9, wherein: the built-in message queue producer processor is used for uniformly executing dynamic creation of the message output channel, registration of Bean logic of the message queue producer processor and binding of the message output channel.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202310054092.0A CN116225735A (en) | 2023-02-03 | 2023-02-03 | Extension method of message-driven programming model based on Spring Cloud Stream |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202310054092.0A CN116225735A (en) | 2023-02-03 | 2023-02-03 | Extension method of message-driven programming model based on Spring Cloud Stream |
Publications (1)
Publication Number | Publication Date |
---|---|
CN116225735A true CN116225735A (en) | 2023-06-06 |
Family
ID=86590391
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202310054092.0A Pending CN116225735A (en) | 2023-02-03 | 2023-02-03 | Extension method of message-driven programming model based on Spring Cloud Stream |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN116225735A (en) |
-
2023
- 2023-02-03 CN CN202310054092.0A patent/CN116225735A/en active Pending
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US8176465B2 (en) | Pluggable model elements | |
KR101143222B1 (en) | Adaptive dispatch of received messages to code using inter-positioned message modification | |
JP4959703B2 (en) | Track and synchronize partial item changes | |
CN108536538A (en) | Processor core dispatching method, device, terminal and storage medium | |
US20060200834A1 (en) | System and method for a context-awareness platform | |
EP3267335B1 (en) | Publish-subscribe system | |
AU2019256257B2 (en) | Processor core scheduling method and apparatus, terminal, and storage medium | |
CN102999608A (en) | System and method for tree table demonstration of large data | |
CN103761136A (en) | Method for dynamically loading data model based on plug-in | |
US20230405455A1 (en) | Method and apparatus for processing cloud gaming resource data, computer device, and storage medium | |
CN111858007A (en) | Task scheduling method and device based on message middleware | |
WO2023087875A1 (en) | Process scheduling method and terminal device | |
TW201826102A (en) | Execution of multiple applications on a device | |
CN103975301B (en) | The method for carrying out Event Service to local client computer application by home server | |
CN106055348B (en) | A kind of method and apparatus that notice system property updates | |
CN114064328A (en) | Message queue cluster migration method and device | |
CN110673827B (en) | Resource calling method and device based on android system and electronic equipment | |
CN112689248A (en) | Message processing method and system | |
WO2023179183A1 (en) | Subprogram synchronization processing | |
CN116225735A (en) | Extension method of message-driven programming model based on Spring Cloud Stream | |
CN109445966B (en) | Event processing method, device, medium and computing equipment | |
US8280950B2 (en) | Automatic client-server code generator | |
Alaerjan et al. | Modeling functional behaviors of DDS | |
CN103914289A (en) | Desktop application access method and device | |
Carreton et al. | Software abstractions for mobile RFID‐enabled applications |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |