JsonUtils Helper Object
JsonUtils is a Scala object with methods for serializing and deserializing Kafka TopicPartitions to and from a single JSON text.
JsonUtils uses json4s library that provides a single AST with the Jackson parser for parsing to the AST (using json4s-jackson module).
| Name | Description | ||
|---|---|---|---|
|
Deserializing partition offsets (i.e. offsets per Kafka
|
|||
|
Serializing partition offsets (i.e. offsets per Kafka
|
|||
|
Deserializing
|
|||
|
Serializing
|
Deserializing Partition Offsets From JSON — partitionOffsets Method
|
1 2 3 4 5 |
partitionOffsets(str: String): Map[TopicPartition, Long] |
partitionOffsets…FIXME
|
Note
|
|
Serializing Partition Offsets to JSON — partitionOffsets Method
|
1 2 3 4 5 |
partitionOffsets(partitionOffsets: Map[TopicPartition, Long]): String |
partitionOffsets…FIXME
|
Note
|
partitionOffsets is used when…FIXME
|
Serializing TopicPartitions to JSON — partitions Method
|
1 2 3 4 5 |
partitions(partitions: Iterable[TopicPartition]): String |
partitions…FIXME
|
Note
|
partitions seems not to be used.
|
Deserializing TopicPartitions from JSON — partitions Method
|
1 2 3 4 5 |
partitions(str: String): Array[TopicPartition] |
partitions uses json4s-jakson’s Serialization object to read a Map[String, Seq[Int] from the input string that represents a Map of topics and partition numbers, e.g. {"topicA":[0,1],"topicB":[0,1]}.
For every pair of topic and partition number, partitions creates a new Kafka TopicPartition.
In case of any parsing issues, partitions throws a new IllegalArgumentException:
|
1 2 3 4 5 |
Expected e.g. {"topicA":[0,1],"topicB":[0,1]}, got [str] |
|
Note
|
partitions is used exclusively when KafkaSourceProvider is requested for a ConsumerStrategy (given assign option).
|
spark技术分享