我试着从Kafka的Spark中读到如下主题:
Map<TopicAndPartition, Long> map = new HashMap<>();
map.put(new TopicAndPartition("A", 0), 1L);
map.put(new TopicAndPartition("B", 0), 1L);
JavaInputDStream<Map.Entry> topicMessages = KafkaUtils.createDirectStream(
jssc,
String.class,
String.class,
StringDecoder.class,
StringDecoder.class,
Map.Entry.class,
kafkaParams,
map,
messageAndMetadata ->
new AbstractMap.SimpleEntry<>(messageAndMetadata.topic(),
messageAndMetadata.message())
);
现在topicmessage以键和值格式显示所有值,如下所示:
A="04/15/2015","18:44:28"
A="04/15/2015","18:44:28"
A="04/15/2015","18:44:28"
B="04/15/2016","18:44:28"
B="04/15/2014","18:44:28"
如何提取特定主题的值。
类似于下面的主题 B
```
"04/15/2016","18:44:28"
"04/15/2014","18:44:28"
1条答案
按热度按时间8tntrjer1#
如果您需要给定主题的行,只需执行以下操作: