[英]Spring Cloud Stream Source - Not Pulling
I'm trying to develop a customized Source for a proof of concept in Spring Cloud Dataflow.我正在尝试为 Spring Cloud Dataflow 中的概念证明开发自定义源。
I managed to deploy it correctly, but it seems that the bean is not pulled.我设法正确部署了它,但似乎没有拉出 bean。
Here's a part of the parent pom.xml这是父pom.xml的一部分
...
<properties>
<spring-cloud.version>Hoxton.SR8</spring-cloud.version>
...
</properties>
<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>
...
Here's the project pom.xml这是项目pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-binder-kafka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cloud-connectors</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
<version>2.3.10.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.3.4.RELEASE</version>
<configuration>
<excludes>
<exclude>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-app-starter-metadata-maven-plugin</artifactId>
<version>2.0.2.RELEASE</version>
<executions>
<execution>
<id>aggregate-metadata</id>
<phase>compile</phase>
<goals>
<goal>aggregate-metadata</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
SourceApplication.java源应用程序.java
@SpringBootApplication
@EnableBinding(Source.class)
@EnableConfigurationProperties(ReportingProperties.class)
public class SourceApplication {
public static void main(String[] args) {
SpringApplication.run(SourceApplication.class, args);
}
}
ReportingProperties.java报表属性.java
@Validated
@ConfigurationProperties("reporting-properties")
public class ReportingProperties {
/**
* The starting date of the reporting.
*/
private LocalDateTime fromDate = LocalDateTime.now().minusDays(1000);
/**
* The end date of the reporting.
*/
private LocalDateTime toDate = LocalDateTime.now();
public LocalDateTime getFromDate() {
return fromDate;
}
public ReportingProperties setFromDate(LocalDateTime fromDate) {
this.fromDate = fromDate;
return this;
}
public LocalDateTime getToDate() {
return toDate;
}
public ReportingProperties setToDate(LocalDateTime toDate) {
this.toDate = toDate;
return this;
}
}
And finally the service :最后是服务:
@Configuration
@EnableBinding(Source.class)
public class PullUsersService {
@Bean
@Publisher(channel = Source.OUTPUT)
@SendTo(Source.OUTPUT)
public Supplier<String> pullUsers() {
return () -> "Test";
}
}
I'm wondering how to trigger the pulling mechanism so when deployed I can see "Test" in the logs (I believe everything is setup correctly on SCDF, if I do "time | log" i can see some results in the log, but if I do "myservice | log" nothing appears.我想知道如何触发拉动机制,以便在部署时我可以在日志中看到“测试”(我相信在 SCDF 上一切设置正确,如果我执行“时间 | 日志”,我可以在日志中看到一些结果,但是如果我执行“myservice | log”,则不会出现任何内容。
What am I doing wrong ?我究竟做错了什么 ? (maybe there's some redundancy in my code) (也许我的代码中有一些冗余)
That's interesting what made you to use this:有趣的是让您使用它的原因是:
@Publisher(channel = Source.OUTPUT)
@SendTo(Source.OUTPUT)
If you take a look into that time
source code you mention, you'll see something like this:如果您查看您提到的那个time
源代码,您会看到如下内容:
@PollableSource
public String publishTime() {
return new SimpleDateFormat(this.triggerProperties.getDateFormat()).format(new Date());
}
Consider to use that @PollableSource
instead and don't use a Supplier
.考虑使用@PollableSource
而不是使用Supplier
。 The point is that all your current annotations do nothing with polling.关键是您当前的所有注释都与轮询无关。
The @Publisher
works only when we call the method. @Publisher
仅在我们调用该方法@Publisher
起作用。 The @SendTo
is fully ignored here since @Publisher
does exactly the same and it "sends to". @SendTo
在这里完全被忽略,因为@Publisher
做的完全一样,它“发送到”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.