【发布时间】:2021-01-29 16:09:58
【问题描述】:
我正在开发一个 POC 来演示一些 Spring Cloud Kafka 功能。我正在使用带有 SpringBoot 2.4.1 的 Java 11。我的 build.gradle 有以下库
implementation 'org.apache.kafka:kafka-streams'
implementation 'org.springframework.cloud:spring-cloud-stream'
implementation 'org.springframework.cloud:spring-cloud-stream-binder-kafka-streams'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
我已经创建了一个如下图所示的SpringBoot组件
public class FirstConsumer implements Processor<String, AirSupportRequest> {
private static Logger logger = LoggerFactory.getLogger(FirstConsumer.class);
@Override
public void init(ProcessorContext context) {
}
@Override
public void process(String key, LocationSupport value) {
logger.info("Key : " + key + value.toString());
Predicate<String, LocationSupport> northAmerica = (k, v) -> v.getLocation().equalsIgnoreCase("NORTHAMERICA");
Predicate<String, LocationSupport> asia = (k, v) -> v.getLocation().equalsIgnoreCase("ASIA");
KStream<String, LocationSupport>[] branches = <How do I get reference to the stream instantiated by Spring Cloud Stream>
我的 application.yml 有以下代码
spring:
cloud:
stream:
kafka:
streams:
binder:
functions:
process:
applicationId: asr
bindings:
process-in-0:
destination: location_stream
根据我的配置,Spring Cloud 已经实例化了一个流。我的问题是如何在我的代码中引用该流来过滤和创建流分支。
谢谢!
【问题讨论】:
标签: java spring-boot apache-kafka apache-kafka-streams spring-cloud-stream