Class

net.liftmodules.kafkaactors

KafkaActor

Related Doc: package kafkaactors

Permalink

abstract class KafkaActor extends LiftActor

A kind of LiftActor capable of consuming messages from a Kafka topic.

This actor imposes a few restrictions that normal LiftActors do not. Specifically:

Other than the above, this Actor behaves very similarly to a normal LiftActor. You can send messages directly to it, thus bypassing Kafka, by using its ! or send methods.

Configuration

For this actor to work correctly with Kafka, you'll ahve to provide it with some basic configuration. The required overrides are:

The Kafka consumer works by polling for a certain number of milliseconds, and then returning if no messages are retrieved. We abstract away that event loop behavior, but sometimes applications need to tweak how long the consumer will sleep in order to optimize performance. To change that you can also override the following:

If you need to tune more specific settings, you can provide a consumerPropsCustomizer that will get to alter the Properties object before we pass it into the KafkaConsumer constructor. This is what you'll need to implement if you want to provide custom settings for things like authentication, encryption, etc. By default, we provide the bootstrap servers, the group ID, we disable auto committing, and provide a key and value serializer implementation.

Please be careful when overriding settings that were set by the KafkaActor itself.

Starting consumption

Once the actor is created, it'll behave like a normal LiftActor until its told to connect up to Kafka and start consuming messages. To do that your code will need to transmit the StartConsumer message to it like so:

actor ! StartConsumer

You can also stop consuming anytime you like by transmitting StopConsumer or you can force committing offsets by transmitting CommitOffsets to the actor if you need to do so for some reason, though as mentioned below those cases should be rare.

Processing messages

When messages come from the topic, they will be parsed and extracted to case class objects using lift-json. The messages will then be put in the actor's normal mailbox using ! and be subjet to normal actor processing rules. Every time the actor consumes messages it'll also add a CommitOffsets message onto the end of the message batch.

Because of the way the actor mailbox works, CommitOffsets won't be processed until all of the messages in that batch have been processed. Thus, if you have a class of errors that may cause you to want to avoid checkpointing offsets to Kafka, you sould throw an exception of some sort in your userMessageHandler so things blow up.

Sending messages

KafkaActor works like a normal actor if you use the regular sending methods. However, you may find it useful to send messages to this actor _through_ Kafka even when the actor is running in the local process. To facilitate this, you can send messages through the included ref like so:

myKafkaActor.ref ! MyMessage()

This will cause the message to be routed through a Kafka producer and then consumed by the actor using the normal consumption means.

Linear Supertypes
LiftActor, ForwardableActor[Any, Any], GenericActor[Any], TypedActor[Any, Any], SpecializedLiftActor[Any], SimpleActor[Any], AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. KafkaActor
  2. LiftActor
  3. ForwardableActor
  4. GenericActor
  5. TypedActor
  6. SpecializedLiftActor
  7. SimpleActor
  8. AnyRef
  9. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new KafkaActor()

    Permalink

Abstract Value Members

  1. abstract def bootstrapServers: String

    Permalink
  2. abstract def groupId: String

    Permalink
  3. abstract def kafkaTopic: String

    Permalink
  4. abstract def userMessageHandler: PartialFunction[Any, Any]

    Permalink

Concrete Value Members

  1. def !(msg: Any): Unit

    Permalink
    Definition Classes
    SpecializedLiftActor → SimpleActor
  2. def !!(msg: Any): Box[Any]

    Permalink
    Definition Classes
    LiftActor → TypedActor
  3. def !!(msg: Any, timeout: Long): Box[Any]

    Permalink
    Definition Classes
    LiftActor → TypedActor
  4. def !<(msg: Any): LAFuture[Any]

    Permalink
    Definition Classes
    LiftActor
  5. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  6. def !?(timeout: Long, message: Any): Box[Any]

    Permalink
    Definition Classes
    LiftActor → TypedActor
  7. def !?(msg: Any): Any

    Permalink
    Definition Classes
    LiftActor → TypedActor
  8. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  9. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  10. def around[R](f: ⇒ R): R

    Permalink
    Attributes
    protected
    Definition Classes
    SpecializedLiftActor
  11. def aroundLoans: List[CommonLoanWrapper]

    Permalink
    Attributes
    protected
    Definition Classes
    SpecializedLiftActor
  12. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  13. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  14. def consumerPropsCustomizer(props: Properties): Properties

    Permalink

    Override this method in the implementing class to customize the consumer settings to your liking.

  15. lazy val consumingThread: KafkaActorConsumingThread

    Permalink
    Attributes
    protected
  16. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  17. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  18. def exceptionHandler: PartialFunction[Throwable, Unit]

    Permalink
    Attributes
    protected
    Definition Classes
    SpecializedLiftActor
  19. def execTranslate(f: (Any) ⇒ Unit)(v: Any): Unit

    Permalink
    Attributes
    protected
    Definition Classes
    LiftActor → SpecializedLiftActor
  20. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  21. final def forwardMessageTo(msg: Any, forwardTo: TypedActor[Any, Any]): Unit

    Permalink
    Attributes
    protected
    Definition Classes
    LiftActor → ForwardableActor
  22. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  23. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  24. def highPriorityReceive: Box[PartialFunction[Any, Unit]]

    Permalink
    Attributes
    protected
    Definition Classes
    SpecializedLiftActor
  25. def insertMsgAtHeadOfQueue_!(msg: Any): Unit

    Permalink
    Attributes
    protected
    Definition Classes
    SpecializedLiftActor
  26. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  27. final def messageHandler: PartialFunction[Any, Unit]

    Permalink
    Definition Classes
    KafkaActor → SpecializedLiftActor
  28. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  29. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  30. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  31. def pollTime: Long

    Permalink
  32. lazy val ref: KafkaActorRef

    Permalink

    The ref for this actor that permits sending messages through the Kafka broker instead of directly to the actor itself.

    The ref for this actor that permits sending messages through the Kafka broker instead of directly to the actor itself. Override this implementation if you need to include custom producing behavior in the KafkaActorRef.

  33. def reply(v: Any): Unit

    Permalink
    Attributes
    protected
    Definition Classes
    LiftActor → ForwardableActor
  34. def send(msg: Any): Unit

    Permalink
    Definition Classes
    SpecializedLiftActor
  35. def sendAndGetFuture(msg: Any): LAFuture[Any]

    Permalink
    Definition Classes
    LiftActor
  36. def sendAndGetReply(timeout: Long, msg: Any): Any

    Permalink
    Definition Classes
    LiftActor
  37. def sendAndGetReply(msg: Any): Any

    Permalink
    Definition Classes
    LiftActor
  38. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  39. def testTranslate(f: (Any) ⇒ Boolean)(v: Any): Boolean

    Permalink
    Attributes
    protected
    Definition Classes
    LiftActor → SpecializedLiftActor
  40. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  41. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  42. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  43. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from LiftActor

Inherited from ForwardableActor[Any, Any]

Inherited from GenericActor[Any]

Inherited from TypedActor[Any, Any]

Inherited from SpecializedLiftActor[Any]

Inherited from SimpleActor[Any]

Inherited from AnyRef

Inherited from Any

Ungrouped