springcloud stream
来源:14-5 springcloud升级到SR2
qq_阿俊
2019-06-14
order服务和configServer都已经连接到了rabbitMQ,
使用的springcloud版本时SR2
springCloudStream 的input 和output的值不一样
写了个发送端
@RestController
@Slf4j
public class TestStreamController {
@Autowired
StreamClient StreamClient;
@RequestMapping("/sendMessage")
public void process(){
OrderMasterDTO orderMasterDTO = new OrderMasterDTO();
orderMasterDTO.setBuyName("sssss");
StreamClient.output().send(MessageBuilder.withPayload(orderMasterDTO).build());
}
}
一个接收端
@Component
@EnableBinding(value = StreamClient.class)
@Slf4j
public class ReciveTest {
@StreamListener("myMessage")
@SendTo("myReciveMessage")
public String receive(OrderMasterDTO orderMasterDTO){
log.info("Receive:"+orderMasterDTO);
System.out.println("Receive:"+orderMasterDTO);
return "recive: ok!";
}
}
发送消息错误:
rabbitMQ端接收不到消息? 想请教一下!
写回答
2回答
-
pom.xml cloud版本应该写在dependencyManagement里
@StreamListener(StreamClient.OUTPT) 参数是OUTPT才对,不是 INPUT
正确的pom.xml如下
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.6.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.imooc</groupId> <artifactId>springcloudstreamtest</artifactId> <version>0.0.1-SNAPSHOT</version> <name>springcloudstreamtest</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> <spring-cloud.version>Finchley.SR2</spring-cloud.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-stream-rabbit</artifactId> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
012019-06-18 -
廖师兄
2019-06-15
把相关项目的代码push到git,发我链接
022019-06-17
SpringCloud Finchley(M2+RELEASE+SR2)微服务实战
SpringCloud组件实现微服务,【已升级Finchley.Release】
5668 学习 · 2489 问题
相似问题