object Consumer
- Alphabetic
- By Inheritance
- Consumer
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Type Members
- sealed trait AutoOffsetStrategy extends AnyRef
- final case class Live(consumer: ConsumerAccess, settings: ConsumerSettings, runloop: Runloop) extends Service with Product with Serializable
- sealed trait OffsetRetrieval extends AnyRef
- trait Service extends AnyRef
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def assignment: RIO[Blocking with Consumer, Set[TopicPartition]]
Accessor method for Service.assignment
- def beginningOffsets(partitions: Set[TopicPartition], timeout: Duration = Duration.Infinity): RIO[Blocking with Consumer, Map[TopicPartition, Long]]
Accessor method for Service.beginningOffsets
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- def committed(partitions: Set[TopicPartition], timeout: Duration = Duration.Infinity): RIO[Blocking with Consumer, Map[TopicPartition, Option[OffsetAndMetadata]]]
Accessor method for Service.committed
- def consumeWith[R, R1, K, V](settings: ConsumerSettings, subscription: Subscription, keyDeserializer: Deserializer[R1, K], valueDeserializer: Deserializer[R1, V], commitRetryPolicy: Schedule[Clock, Any, Any] = Schedule.exponential(1.second) && Schedule.recurs(3))(f: (K, V) => ZIO[R, Nothing, Unit])(implicit arg0: zio.Tag[R1], arg1: zio.Tag[K], arg2: zio.Tag[V]): ZIO[R with R1 with Blocking with Clock, Throwable, 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}") }
- R
Environment for the consuming effect
- R1
Environment for the deserializers
- K
Type of keys (an implicit
Deserializershould be in scope)- V
Type of values (an implicit
Deserializershould be in scope)- settings
Settings for creating a Consumer
- subscription
Topic subscription parameters
- keyDeserializer
Deserializer for the key of the messages
- valueDeserializer
Deserializer for the value of the messages
- 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
- returns
Effect that completes with a unit value only when interrupted. May fail when the Consumer fails.
- def endOffsets(partitions: Set[TopicPartition], timeout: Duration = Duration.Infinity): RIO[Blocking with Consumer, Map[TopicPartition, Long]]
Accessor method for Service.endOffsets
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def listTopics(timeout: Duration = Duration.Infinity): RIO[Blocking with Consumer, Map[String, List[PartitionInfo]]]
Accessor method for Service.listTopics
- def live: ZLayer[Clock with Blocking with Has[ConsumerSettings] with Has[Diagnostics], Throwable, Consumer]
- def make(settings: ConsumerSettings, diagnostics: Diagnostics = Diagnostics.NoOp): ZManaged[Clock with Blocking, Throwable, Service]
- def metrics: RIO[Blocking with Consumer, Map[MetricName, Metric]]
Accessor method for Service.metrics
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- val offsetBatches: ZTransducer[Any, Nothing, Offset, OffsetBatch]
- def offsetsForTimes(timestamps: Map[TopicPartition, Long], timeout: Duration = Duration.Infinity): RIO[Blocking with Consumer, Map[TopicPartition, OffsetAndTimestamp]]
Accessor method for Service.offsetsForTimes
- def partitionedStream[R, K, V](keyDeserializer: Deserializer[R, K], valueDeserializer: Deserializer[R, V])(implicit arg0: zio.Tag[R], arg1: zio.Tag[K], arg2: zio.Tag[V]): ZStream[Consumer with Clock with Blocking, Throwable, (TopicPartition, ZStream[R, Throwable, CommittableRecord[K, V]])]
Accessor method for Service.partitionedStream
- def partitionsFor(topic: String, timeout: Duration = Duration.Infinity): RIO[Blocking with Consumer, List[PartitionInfo]]
Accessor method for Service.partitionsFor
- def plainStream[R, K, V](keyDeserializer: Deserializer[R, K], valueDeserializer: Deserializer[R, V])(implicit arg0: zio.Tag[R], arg1: zio.Tag[K], arg2: zio.Tag[V]): ZStream[R with Consumer with Clock with Blocking, Throwable, CommittableRecord[K, V]]
Accessor method for Service.plainStream
- def position(partition: TopicPartition, timeout: Duration = Duration.Infinity): RIO[Blocking with Consumer, Long]
Accessor method for Service.position
- def stopConsumption: RIO[Consumer, Unit]
Accessor method for Service.stopConsumption
- def subscribe(subscription: Subscription): RIO[Blocking with Consumer, Unit]
Accessor method for Service.subscribe
- def subscribeAnd(subscription: Subscription): SubscribedConsumerFromEnvironment
Accessor method for Service.subscribeAnd
- def subscription: RIO[Blocking with Consumer, Set[String]]
Accessor method for Service.subscription
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- def unsubscribe: RIO[Blocking with Consumer, Unit]
Accessor method for Service.unsubscribe
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- def withConsumerService[R, A](r: (Service) => RIO[R with Blocking, A]): RIO[R with Blocking with Consumer, A]
- object AutoOffsetStrategy
- object OffsetRetrieval