Spring Cloud Data Flow Streaming源null问题

时间:2019-09-10 14:07:30

标签: spring spring-cloud spring-cloud-stream spring-cloud-dataflow spring-rabbit

我使用Rabbit MQ为定制的春季云数据流提供了一个小型POC,其中定制源应用程序具有发送当前时间的调度程序。当我部署此代码并运行Source时,它似乎没有自动接线,并且this.source显示null和我在下面的代码行中遇到错误。

 this.source.output().send(MessageBuilder.withPayload(new
 Date().getTime()).build()
  

错误堆栈

org.springframework.messaging.MessageDeliveryException:调度程序没有频道“ unknown.channel.name”的订阅者。嵌套的异常是org.springframework.integration.MessageDispatchingException:调度程序没有订阅者,failedMessage = GenericMessage [payload = byte [13],headers = {contentType = application / json,id = 44e58c73-15b5-b250-4db4-7b617bdaa27e,timestamp = 1568127722030}],failedMessage = GenericMessage [payload = byte [13],标头= {contentType = application / json,id = 44e58c73-15b5-b250-4db4-7b617bdaa27e,时间戳= 1568127722030}]

  

源代码

@EnableScheduling
@EnableBinding(Source.class)
@SpringBootApplication
public class MSource {

    Logger logger = LoggerFactory.getLogger(MSource.class);

    @Autowired
    private Source source;

    @Bean
    @InboundChannelAdapter(
            value = Source.OUTPUT,
            poller = @Poller(fixedDelay = "10000", maxMessagesPerPoll = "10000")
    )

    public  void sendMessage() {       
      this.source.output().send(MessageBuilder.withPayload(new Date().getTime()).build());
    }

应用yml条目

spring.cloud.stream.bindings.output.destination: pocqueue
spring.cloud.stream.bindings.output.group: poc

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">

    <groupId>poc</groupId>
    <artifactId>server</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <parent>
        <groupId>org.springframework.cloud.stream.app</groupId>
        <artifactId>app-starters-build</artifactId>
        <version>2.1.0.RELEASE</version>
        <relativePath/>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <packaging.type>jar</packaging.type>
        <spring.boot.maven.plugin.version>2.1.2.RELEASE</spring.boot.maven.plugin.version>
    </properties>

    <dependencies>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-stream-rabbit</artifactId>
            <version>2.1.1.RELEASE</version>
        </dependency>

        <dependency>
        <groupId>org.springframework.cloud.stream.app</groupId>
        <artifactId>app-starters-build</artifactId>
        <version>2.1.1.RELEASE</version>
        <type>pom</type>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webflux</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jetty</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.projectreactor</groupId>
            <artifactId>reactor-test</artifactId>
            <version>3.2.9.RELEASE</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jetty</artifactId>
        </dependency>
        <dependency>
            <groupId>io.projectreactor</groupId>
            <artifactId>reactor-test</artifactId>
            <version>3.2.9.RELEASE</version>
            <scope>test</scope>
        </dependency>

    </dependencies>

    <!--<build>-->
        <!--<plugins>-->
            <!--<plugin>-->
                <!--<groupId>org.springframework.boot</groupId>-->
                <!--<artifactId>spring-boot-maven-plugin</artifactId>-->
            <!--</plugin>-->
        <!--</plugins>-->
    <!--</build>-->
    <profiles>
        <profile>
            <id>rabbit-binder</id>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.cloud</groupId>
                    <artifactId>spring-cloud-stream-binder-rabbit</artifactId>
                </dependency>
            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                        <configuration>
                            <classifier>rabbit</classifier>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

2 个答案:

答案 0 :(得分:0)

鉴于您在@EnableScheduling @Autowired频道中使用Source,则可以将代码重构为:

@EnableScheduling
@EnableBinding(Source.class)
@SpringBootApplication
public class MSource {

    Logger logger = LoggerFactory.getLogger(EdpiSource.class);

    @Autowired
    private Source source;

    @Scheduled(fixedRate = 1000L) 
    public  void sendMessage() {       
      this.source.output().send(MessageBuilder.withPayload(new Date().getTime()).build());
    }

这足以在1秒的时间间隔内连续触发有效载荷的产生。

答案 1 :(得分:0)

问题出在本地,因为我在配置中指定了Rabbit MQ绑定,所以没有绑定发生,并且期望本地不是可用的Rabbit MQ。