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回答

廖师兄

2019-06-17

  1. pom.xml cloud版本应该写在dependencyManagement里

  2. @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>


0
1
qq_阿俊
非常感谢!
2019-06-18
共1条回复

廖师兄

2019-06-15

把相关项目的代码push到git,发我链接

0
2
廖师兄
回复
qq_阿俊
看我的发的。你这个仓库不用删除,留着给后面的同学参考。
2019-06-17
共2条回复

SpringCloud Finchley(M2+RELEASE+SR2)微服务实战

SpringCloud组件实现微服务,【已升级Finchley.Release】

5668 学习 · 2489 问题

查看课程