Class KafkaEvent

java.lang.Object
java.util.EventObject
org.springframework.context.ApplicationEvent
org.springframework.kafka.event.KafkaEvent
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
ConsumerFailedToStartEvent, ConsumerPartitionPausedEvent, ConsumerPartitionResumedEvent, ConsumerPausedEvent, ConsumerResumedEvent, ConsumerRetryAuthEvent, ConsumerRetryAuthSuccessfulEvent, ConsumerStartedEvent, ConsumerStartingEvent, ConsumerStoppedEvent, ConsumerStoppingEvent, ContainerStoppedEvent, ListenerContainerIdleEvent, ListenerContainerNoLongerIdleEvent, ListenerContainerPartitionIdleEvent, ListenerContainerPartitionNoLongerIdleEvent, NonResponsiveConsumerEvent

public abstract class KafkaEvent extends org.springframework.context.ApplicationEvent
Base class for events.
See Also:
  • Field Summary

    Fields inherited from class java.util.EventObject

    source
  • Constructor Summary

    Constructors
    Constructor
    Description
    KafkaEvent(Object source, Object container)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> T
    Get the container for which the event was published, which will be the parent container if the source that emitted the event is a child container, or the source itself otherwise.
    <T> T
    getSource(Class<T> type)
    Get the container (source) that published the event.

    Methods inherited from class org.springframework.context.ApplicationEvent

    getTimestamp

    Methods inherited from class java.util.EventObject

    getSource, toString

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • KafkaEvent

      public KafkaEvent(Object source, Object container)
  • Method Details

    • getContainer

      public <T> T getContainer(Class<T> type)
      Get the container for which the event was published, which will be the parent container if the source that emitted the event is a child container, or the source itself otherwise. The type is required here to avoid a dependency tangle between the event and listener packages.
      Type Parameters:
      T - the type.
      Parameters:
      type - the container type (e.g. MessageListenerContainer.class).
      Returns:
      the container.
      Since:
      2.2.1
      See Also:
    • getSource

      public <T> T getSource(Class<T> type)
      Get the container (source) that published the event. This is provided as an alternative to EventObject.getSource() to avoid the need to cast in user code. The type is required here to avoid a dependency tangle between the event and listener packages.
      Type Parameters:
      T - the type.
      Parameters:
      type - the container type (e.g. MessageListenerContainer.class).
      Returns:
      the container.
      Since:
      2.2.1
      See Also: