Consumer

object Consumer
Companion:
class
class Object
trait Matchable
class Any

Type members

Classlikes

Companion:
class
sealed trait AutoOffsetStrategy
Companion:
object
Companion:
class
sealed trait OffsetRetrieval
Companion:
object

Value members

Concrete methods

def assignment: RIO[Consumer, Set[TopicPartition]]

Accessor method for Consumer.assignment

Accessor method for Consumer.assignment

def beginningOffsets(partitions: Set[TopicPartition], timeout: Duration): RIO[Consumer, Map[TopicPartition, Long]]

Accessor method for Consumer.beginningOffsets

Accessor method for Consumer.beginningOffsets

def committed(partitions: Set[TopicPartition], timeout: Duration): RIO[Consumer, Map[TopicPartition, Option[OffsetAndMetadata]]]

Accessor method for Consumer.committed

Accessor method for Consumer.committed

def consumeWith[R : Tag, R1 : Tag, K, V](settings: ConsumerSettings, subscription: Subscription, keyDeserializer: Deserializer[R, K], valueDeserializer: Deserializer[R, V], commitRetryPolicy: Schedule[Any, Any, Any])(f: (K, V) => URIO[R1, Unit]): RIO[R & R1, Unit]

Execute an effect for each record and commit the offset after processing

Execute an effect for each record and commit the offset after processing

This method is the easiest way of processing messages on a Kafka topic.

Messages on a single partition are processed sequentially, while the processing of multiple partitions happens in parallel.

Offsets are committed after execution of the effect. They are batched when a commit action is in progress to avoid backpressuring the stream. When commits fail due to a org.apache.kafka.clients.consumer.RetriableCommitFailedException they are retried according to commitRetryPolicy

The effect should absorb any failures. Failures should be handled by retries or ignoring the error, which will result in the Kafka message being skipped.

Messages are processed with 'at least once' consistency: it is not guaranteed that every message that is processed by the effect has a corresponding offset commit before stream termination.

Usage example:

val settings: ConsumerSettings = ???
val subscription = Subscription.Topics(Set("my-kafka-topic"))

val consumerIO = Consumer.consumeWith(settings, subscription, Serdes.string, Serdes.string) { case (key, value) =>
 // Process the received record here
 putStrLn(s"Received record: ${key}: ${value}")
}
Type parameters:
K

Type of keys (an implicit Deserializer should be in scope)

R

Environment for the consuming effect

R1

Environment for the deserializers

V

Type of values (an implicit Deserializer should be in scope)

Value parameters:
commitRetryPolicy

Retry commits that failed due to a RetriableCommitFailedException according to this schedule

f

Function that returns the effect to execute for each message. It is passed the key and value

keyDeserializer

Deserializer for the key of the messages

settings

Settings for creating a Consumer

subscription

Topic subscription parameters

valueDeserializer

Deserializer for the value of the messages

Returns:

Effect that completes with a unit value only when interrupted. May fail when the Consumer fails.

def endOffsets(partitions: Set[TopicPartition], timeout: Duration): RIO[Consumer, Map[TopicPartition, Long]]

Accessor method for Consumer.endOffsets

Accessor method for Consumer.endOffsets

def listTopics(timeout: Duration): RIO[Consumer, Map[String, List[PartitionInfo]]]

Accessor method for Consumer.listTopics

Accessor method for Consumer.listTopics

def make(settings: ConsumerSettings, diagnostics: Diagnostics): ZIO[Scope, Throwable, Consumer]
def metrics: RIO[Consumer, Map[MetricName, Metric]]

Accessor method for Consumer.metrics

Accessor method for Consumer.metrics

def offsetsForTimes(timestamps: Map[TopicPartition, Long], timeout: Duration): RIO[Consumer, Map[TopicPartition, OffsetAndTimestamp]]

Accessor method for Consumer.offsetsForTimes

Accessor method for Consumer.offsetsForTimes

def partitionedStream[R, K, V](keyDeserializer: Deserializer[R, K], valueDeserializer: Deserializer[R, V]): ZStream[Consumer, Throwable, (TopicPartition, ZStream[R, Throwable, CommittableRecord[K, V]])]

Accessor method for Consumer.partitionedStream

Accessor method for Consumer.partitionedStream

def partitionsFor(topic: String, timeout: Duration): RIO[Consumer, List[PartitionInfo]]

Accessor method for Consumer.partitionsFor

Accessor method for Consumer.partitionsFor

def plainStream[R, K, V](keyDeserializer: Deserializer[R, K], valueDeserializer: Deserializer[R, V], bufferSize: Int): ZStream[R & Consumer, Throwable, CommittableRecord[K, V]]

Accessor method for Consumer.plainStream

Accessor method for Consumer.plainStream

def position(partition: TopicPartition, timeout: Duration): RIO[Consumer, Long]

Accessor method for Consumer.position

Accessor method for Consumer.position

def stopConsumption: RIO[Consumer, Unit]

Accessor method for Consumer.stopConsumption

Accessor method for Consumer.stopConsumption

def subscribe(subscription: Subscription): RIO[Consumer, Unit]

Accessor method for Consumer.subscribe

Accessor method for Consumer.subscribe

def subscription: RIO[Consumer, Set[String]]

Accessor method for Consumer.subscription

Accessor method for Consumer.subscription

def unsubscribe: RIO[Consumer, Unit]

Accessor method for Consumer.unsubscribe

Accessor method for Consumer.unsubscribe

Concrete fields

val offsetBatches: ZSink[Any, Nothing, Offset, Nothing, OffsetBatch]