Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented ConcurrentStream to support only committing offsets when …
…load-balanced tasks all complete successfully This includes commits for: contiguous ordering multithread support It also introduces ConsumerAccess to ensure thread-safe kafka consumer access
- Loading branch information
Showing
38 changed files
with
1,522 additions
and
579 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package kafka4m.consumer | ||
|
||
import java.nio.charset.StandardCharsets | ||
|
||
import kafka4m.Bytes | ||
|
||
/** | ||
* If we have a BytesDecoder, then we can have an [[RecordDecoder]]. | ||
* This shit chains. | ||
* | ||
* @tparam A the result type | ||
*/ | ||
trait BytesDecoder[A] { | ||
def decode(bytes: kafka4m.Bytes): A | ||
} | ||
|
||
object BytesDecoder { | ||
def apply[A](implicit instance: BytesDecoder[A]): BytesDecoder[A] = instance | ||
|
||
def lift[A](f: kafka4m.Bytes => A): BytesDecoder[A] = new BytesDecoder[A] { | ||
override def decode(bytes: Bytes): A = f(bytes) | ||
} | ||
|
||
implicit object StringDecoder extends BytesDecoder[String] { | ||
override def decode(bytes: Bytes): String = new String(bytes, StandardCharsets.UTF_8) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package kafka4m.consumer | ||
|
||
import kafka4m.consumer.ConcurrentStream.ZipOffset | ||
|
||
import scala.concurrent.Future | ||
|
||
/** | ||
* A tuple of all the information at hand from a [[ConcurrentStream]] computation | ||
* | ||
* @param localConsumedOffset | ||
* @param kafkaRecord | ||
* @param taskResult | ||
* @tparam A | ||
* @tparam B | ||
*/ | ||
case class ComputeResult[A, B](localConsumedOffset: ZipOffset, kafkaRecord: AckableRecord[A], taskResult: B) extends ConsumerAccess { | ||
def offset = kafkaRecord.offset | ||
override type Key = kafkaRecord.Key | ||
override type Value = kafkaRecord.Value | ||
def input: A = kafkaRecord.record | ||
override def toString: String = s"ComputeResult #$localConsumedOffset (${kafkaRecord.record} -> $taskResult)" | ||
|
||
override def withConsumer[A](thunk: RichKafkaConsumer[kafkaRecord.access.Key, kafkaRecord.access.Value] => A): Future[A] = { | ||
kafkaRecord.withConsumer(thunk) | ||
} | ||
} |
Oops, something went wrong.