简体   繁体   English

多个 oracle 表的单个 kafka 主题

[英]Single kafka topic for multiple oracle tables

My requirement is to load 200+ oracle tables into 200+ mongo collections via Kafka.我的要求是通过 Kafka 将 200+ oracle 表加载到 200+ mongo collections 中。 I thought of creating single JDBC source connector, 200+topics, 200+ sink connectors.我想创建单个 JDBC 源连接器、200 多个主题、200 多个接收器连接器。 But confluent team said, kafka might not handle these many topics and sink connectors.但是 confluent 团队表示,kafka 可能无法处理这么多主题和接收连接器。 They asked me to consolidate.他们要求我巩固。 How to write 200+ oracle tables into single topic and write into mongo collection?如何将 200+ oracle 表写入单个主题并写入 mongo 集合? Can you please help me?你能帮我么?

Unless some particular context is missing from your question, then the suggestion that Kafka would not handle 200+ topics and sink connectors sounds incorrect.除非您的问题中缺少某些特定上下文,否则 Kafka 不会处理 200 多个主题和接收器连接器的建议听起来不正确。

You should map each logical table to a Kafka topic.您应该将每个逻辑表 map 分配给一个 Kafka 主题。 The only reason I can think to consolidate multiple tables into one topic is if it's the same logical entity (for example, a table that's sharded across physical locations such as isolated warehouses).我认为将多个表合并到一个主题中的唯一原因是它是否是同一个逻辑实体(例如,跨物理位置(例如隔离仓库)分片的表)。 There are other reasons for putting multiple message types in one topic but they may well not apply here.将多种消息类型放在一个主题中还有其他原因,但它们很可能不适用于这里。

Depending on the volume of data you'd need to manage the scale of your Kafka Connect worker cluster but that's easily done with distributed mode and you just scale out horizontally to cope with the workload as required.根据您需要管理 Kafka Connect 工作集群规模的数据量,这可以通过分布式模式轻松完成,您只需根据需要横向扩展以应对工作负载。


Disclaimer: I work for Confluent;)免责声明:我为 Confluent 工作;)

I am guessing here Confluent might have suggested that approach considering your Kafka cluster size otherwise, what you were doing makes sense.我在这里猜测 Confluent 可能会建议考虑您的 Kafka 集群大小的方法,否则,您所做的事情是有道理的。

But if you want to use only single topic you can try leveraging the kafka headers which can hold the table-name for an event.但是,如果您只想使用单个主题,您可以尝试利用 kafka 标头,它可以保存事件的表名。

Sugaan, Please find the sample code as requested. Sugaan,请按要求找到示例代码。

Producer:-制作人:-

  ProducerRecord<String, JsonNode> record = new ProducerRecord<>(topic, key, value);
  record.headers().add("test", "test1".getBytes());

  producer.send(record

Consumer:-消费者:-

  final ConsumerRecords<String, byte[]> consumerRecords = consumer.poll(Duration.ofMillis(100000));
                  
  for (ConsumerRecord<String, byte[]> record : consumerRecords) {
      record.headers().forEach(
              (header -> System.out.println(header.key() + "  " + header.value())));
  }

Please let me know if you have any additional questions.如果您有任何其他问题,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM