Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Stream of java springcloud

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to use java springcloud's Stream". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use java springcloud's Stream.

Spring Cloud Stream is a framework for building message-driven microservice applications. Spring Cloud Stream builds independent production-level Spring applications based on Spring Boot and uses Spring Integration to provide connectivity to message brokers.

You can add the @ EnableBinding annotation to your application to connect to the message broker immediately, and you can add @ StreamListener to the method so that it receives events handled by the stream. The following is a simple receiver application that receives external messages.

@ SpringBootApplication@EnableBinding (Sink.class) public class VoteRecordingSinkApplication {public static void main (String [] args) {SpringApplication.run (VoteRecordingSinkApplication.class, args);} @ StreamListener (Sink.INPUT) public void processVote (Vote vote) {votingService.recordVote (vote);}} copy the code

The @ EnableBinding annotation requires one or more interfaces as parameters (in this case, a single Sink interface). The interface declares input and / or output channels. Spring Cloud Stream provides interfaces Source,Sink and Processor;. You can also define your own interface.

The following is the definition of the Sink interface:

Public interface Sink {String INPUT = "input"; @ Input (Sink.INPUT) SubscribableChannel input ();} copy the code

The @ Input comment identifies the input channel through which messages received enter the application; the @ Output annotation identifies the output channel through which published messages leave the application. @ Input and @ Output annotations can use the channel name as a parameter; if no name is provided, the name of the annotation method will be used.

Spring Cloud Stream will create an implementation of the interface for you. You can use it through automatic connections in your application, as shown in the following test case example.

@ RunWith (SpringJUnit4ClassRunner.class) @ SpringApplicationConfiguration (classes = VoteRecordingSinkApplication.class) @ WebAppConfiguration@DirtiesContextpublic class StreamApplicationTests {@ Autowired private Sink sink; @ Test public void contextLoads () {assertNotNull (this.sink.input ());}} copy the code here, I believe you have a better understanding of "how to use java springcloud's Stream", you might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report