Create a Spring boot project, add pom dependencies
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId> Spring-cloud-starter-stream-rabbit</artifactid> </dependency>
View Code
Add message Receive Sinkreceiver
ImportOrg.slf4j.Logger;Importorg.slf4j.LoggerFactory;Importorg.springframework.cloud.stream.annotation.EnableBinding;ImportOrg.springframework.cloud.stream.annotation.StreamListener;ImportOrg.springframework.cloud.stream.messaging.Sink; the @EnableBinding (Sink.class) Public classSinkreceiver {Private StaticLogger logger= Loggerfactory.getlogger (sinkreceiver.class); @StreamListener (sink.input) Public voidreceive (Object payload) {Logger.info ("Received:" +payload); }}
View Code
Configuration
spring.application.name=stream-hellospring.rabbitmq.host=10.202.203.29spring.rabbitmq.port= 5672spring.rabbitmq.username=Springcloudspring.rabbitmq.password=123456
View Code
Run the program, open the RABBITMQ monitoring interface, you can see
Push message
Viewing results in the console
Spring Cloud Stream