【问题标题】:Spring cloud stream kafka binder KTable not workingSpring Cloud Stream kafka binder KTable不工作
【发布时间】:2018-12-16 20:39:59
【问题描述】:

我正在尝试通过 SCSt 渠道构建并获取 KTable。但它不起作用。输入 KTable 没有数据,但如果我尝试查看 KSTream 聚合(toStream()),我可以看到一些数据。 我明白了,KTable 不可查询,也没有可查询的名称。

类:

@Slf4j
@EnableBinding({LimitBinding.class})
public class CommonWorker {

  @Value("${app.dataflow.out-destination}")
  private String customerOut;

  private LimitCustomersHelper custHelper = new LimitCustomersHelper();

  @StreamListener(CUSTOMER_IN)
  public void groupCustomersByLimitIdKTable(KStream<Key, Envelope> input) {
   input
        .filter(custHelper::afterIsNotNull)
        .groupBy(custHelper::groupBy)
        .aggregate(
            custHelper::create,
            custHelper::aggregate,
            custHelper.materialized(customerOut)
        );
  }

  @StreamListener
  public void checkCustomerasTable(@Input(CUSTOMER_OUT) KTable<StringWrapper,LimitCustomers> customers){
    customers.toStream().peek(StreamUtils::peek);
  }

绑定:

public interface LimitBinding {

  String CUSTOMER_IN = "customer-in";
  String CUSTOMER_OUT = "customer-out";


  @Input(CUSTOMER_IN)
  KStream<Key, Envelope> customerInput();

  @Input(CUSTOMER_OUT)
  KTable<StringWrapper, LimitCustomers> customersStream();

}

application.yml:

server.port: 0
spring:
  application.name: connect-producer
  cloud.stream:
    kafka.streams.binder.configuration:
      schema:
        registry.url: http://192.168.99.100:8081
      default:
        key.serde: io.confluent.kafka.streams.serdes.avro.SpecificAvroSerde
        value.serde: io.confluent.kafka.streams.serdes.avro.SpecificAvroSerde
    schema.avro.dynamic-schema-generation-enabled: true
    bindings:
      customer-in:
        contentType: application/*+avro
        destination: ${app.dataflow.in-destination}
        group: ${app.dataflow.in-destination}
      customer-out:
        consumer.materializedAs: ${app.dataflow.out-destination}

app.dataflow:
  in-destination: customer_link
  out-destination: customer_link.next


spring.cloud.stream.kafka.streams.binder:
  brokers: 192.168.99.100:9092
  configuration.application.server: 192.168.99.100:9092

【问题讨论】:

    标签: apache-kafka apache-kafka-streams spring-cloud-stream


    【解决方案1】:

    通过添加主题名称模拟表名解决了问题

    【讨论】:

    • 主题名模拟表名是什么意思?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-08
    • 1970-01-01
    • 2021-02-17
    • 1970-01-01
    • 2021-05-21
    • 2019-04-19
    • 2020-03-23
    相关资源
    最近更新 更多