Show / Hide Table of Contents

    Kafka Events

    The underlying library (Confluent.Kafka) uses some events to let you catch important information, interact with the partitions assignment process, etc.

    Silverback proxies those events to give you full access to those features.

    Consumer events

    These callbacks are available:

    • IKafkaPartitionsAssignedCallback
    • IKafkaPartitionsRevokedCallback
    • IKafkaOffsetCommittedCallback
    • IKafkaConsumerErrorCallback
    • IKafkaConsumerStatisticsCallback
    • IKafkaConsumerLogCallback
    • IKafkaPartitionEofCallback

    Offset reset example

    In the following example the partitions assigned event is subscribed in order to reset the start offsets and replay the past messages.

    • Startup
    • ResetOffsetPartitionsAssignedCallbackHandler
    public class Startup
    {
        public void ConfigureServices(IServiceCollection services)
        {
            services
                .AddSilverback()
                .WithConnectionToMessageBroker(options => options
                    .AddKafka())
                .AddSingletonBrokerCallbackHandler<ResetOffsetPartitionsAssignedCallbackHandler>();
        }
    }
    
    public class ResetOffsetPartitionsAssignedCallbackHandler
        : IKafkaPartitionsAssignedCallback
    {
        public IEnumerable<TopicPartitionOffset> OnPartitionsAssigned(
            IReadOnlyCollection<TopicPartition> topicPartitions,
            KafkaConsumer consumer) =>
            topicPartitions.Select(
                topicPartition => new TopicPartitionOffset(topicPartition, Offset.Beginning));
    }
    

    Producer events

    These callbacks are available:

    • IKafkaProducerStatisticsCallback
    • IKafkaProducerLogCallback

    See also

    Broker Callbacks

    • Improve this doc
    GitHub E-Mail
    ↑ Back to top © 2020 Sergio Aquilini