二、消费者【2058】
1、pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-stream-rabbit</artifactId>
<version>3.0.7.RELEASE</version>
</dependency>
2、MessageListener监听
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.cloud.stream.messaging.Sink;
import org.springframework.stereotype.Component;
@Component
@EnableBinding(Sink.class)
public class MessageListener {
//监听binding中的消息,绑定器input
@StreamListener(Sink.INPUT)
public void input(String message){
System.out.println("获取到信息:"+message);
}
}
3、application.yml
server:
port: 2058
spring:
application:
name: consumberstream2058
rabbitmq:
addresses: 127.0.0.1
username: guest
password: guest
cloud:
stream:
bindings:
input: #(默认邦定器:input)内置的获取信息的通道,从交换机(rabbit-exchang01)获取
destination: rabbit-exchang01
binders: #默认邦定器
defaultRabbit:
type: rabbit
三、Rabbit[15671] web客户端
#交换机rabbit-exchange01 直接发送信息
标签:stream,简化版,springframework,rabbit,import,sc,org,cloud From: https://www.cnblogs.com/smallfa/p/17045715.html