spring cloud stream rabbit 3.1.1 可以正常发送接收,4.0新版
这个方法改变了。
<!--cloud rabbitMq 依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-binder-rabbit</artifactId>
<version>4.0.1</version>
</dependency>
spring:
functional:
enabled: true
cloud:
function:
definition: log;logPub;sendLog
stream:
binders:
rabbit:
type: rabbit
# rabbimq
environment:
spring:
rabbitmq:
host: localhost
username: admin
password: admin
virtual-host: my_vhost
bindings: # 服务的整合处理
logPub-out-0:
destination: log # 表示要使用的Exchange名称定义,不存在会自动创建
content-type: application/json # 设置消息类型,本次为json,文本则设置“text/plain”
log-in-0:
consumer:
auto-bind-dlq: false
destination: log
content-type: application/json # 设置消息类型,本次为json,文本则设置“text/plain”
group: log123
sendLog:
destination: log
content-type: application/json # 设置消息类型,本次为json,文本则设置“text/plain”
group: log123
生产者
@RestController
@RequiredArgsConstructor
public class logController {
private final StreamBridge streamBridge;
@GetMapping("/sendLog")
public void sendLog() {
logListener.Person person = new logListener.Person();
person.setName("李四");
System.out.println("生产者发送消息"+person);
streamBridge.send("sendLog", person);
}
}
消费者
@Component
public class logListener {
public static class Person {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return this.name;
}
}
@Bean
public Consumer<Person> log() {
return person -> {
System.out.println("Received: " + person);
};
}
}
哪里配置的不对吗? 3.1.1 启动后 group 会创建queue,4.0的启动 也没有新的queue创建