我正在尝试将Spring Cloud Stream应用程序Chelsea.SR1迁移到Horsham。该项目没有活页夹,但使用Spring消息传递和集成来集成自定义源和接收器。
似乎AggregateApplicationBuilder
不再可用。没有AggregateApplicationBuilder
的情况下如何绑定源,变压器和接收器?
或者在Horsham中有更好的方法来实现这一点?我唯一的限制是,我需要使用可轮询的源/消费者。
谢谢!
pom.xml
<modelVersion>4.0.0</modelVersion>
<artifactId>example-info-processor</artifactId>
<groupId>com.example.streams</groupId>
<version>1.2-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath />
</parent>
<properties>
<spring-cloud.version>Chelsea.SR1</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-messaging</artifactId>
<version>4.3.17.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.3.15.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.3.20.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.24.RELEASE</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
应用
@SpringBootApplication
@ComponentScan(basePackages = {
"com.example.streams",
})
public class ExampleInfoProcessorApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
new AggregateApplicationBuilder(ExampleInfoProcessor.class, args)
.from(ExampleInfoConsumer.class).via(ExampleInfoTransformer.class)
.to(ExampleInfoSink.class).run(args);
}
}
来源
@EnableBinding(Source.class)
public class ExampleInfoConsumer {
@Autowired
private MyConsumer customConsumer;
@InboundChannelAdapter(value = Source.OUTPUT, poller = @Poller(fixedDelay = "30"))
public List<ExampleRecord> consume() {
//Read the available chunk from the source location
.....
return exampleRecordsList;
}
}
变形金刚
@EnableBinding(Processor.class)
public class ExampleInfoTransformer {
@Transformer(inputChannel = Processor.INPUT, outputChannel = Processor.OUTPUT)
public Map<String, List<ExampleInfo>> transform(List<ExampleRecord> exampleRecords) {
//transform the consumer records, store the list of ExampleInfo objects in a map using ExampleInfo key
return map;
}
}
水槽
@EnableBinding(Sink.class)
public class ExampleInfoSink {
@ServiceActivator(inputChannel = Sink.INPUT)
public void sink(Map<String, List<ExampleInfo>> exampleInfoMap) {
//Read from map and write to destination.
}
}
答案 0 :(得分:1)
如果仅使用spring-integration和spring-messaging,那么为什么要使用spring-cloud-stream作为依赖项,而不仅仅是顶层框架的spring-integration? 如何不绑定源,变压器和接收器。 。 -源具有输出通道,而变压器具有输入通道。只要输出和输入是与您的组件连接的同一通道。但这与spring-cloud-stream无关。那是纯粹的弹簧整合。
切尔西是一个非常老的版本(1.x)。我们已在2.x中弃用AggregateApplicationBuilder
,并在3.x中将其删除,以支持功能组合。
我们也不再为基于功能的编程模型推荐基于spring-cloud-stream的基于注释的配置模型。
请阅读我们最近发布的以下帖子: