Class KafkaPublisher.Builder<K,​V>

    • Method Detail

      • config

        public KafkaPublisher.Builder<K,​V> config​(Config config)
        Load this builder from a configuration.
        Parameters:
        config - configuration to load from
        Returns:
        updated builder instance
      • consumerSupplier

        public KafkaPublisher.Builder<K,​V> consumerSupplier​(Supplier<org.apache.kafka.clients.consumer.Consumer<K,​V>> consumerSupplier)
        Defines how to instantiate the KafkaConsumer. It will be invoked in KafkaPublisher.subscribe(Subscriber) This is a mandatory parameter.
        Parameters:
        consumerSupplier - instantiated Kafka consumer
        Returns:
        updated builder instance
      • topics

        public KafkaPublisher.Builder<K,​V> topics​(List<String> topics)
        The list of topics to subscribe to. This is a mandatory parameter if topicPattern is empty.
        Parameters:
        topics - list of topics to subscribe to
        Returns:
        updated builder instance
      • topicPattern

        public KafkaPublisher.Builder<K,​V> topicPattern​(Pattern topicPattern)
        The pattern for selecting multiple topics. This is a mandatory parameter if topics is empty.
        Parameters:
        topicPattern - pattern for selecting multiple topics
        Returns:
        updated builder instance
      • scheduler

        public KafkaPublisher.Builder<K,​V> scheduler​(ScheduledExecutorService scheduler)
        Specify a scheduler that will read ad process messages coming from Kafka. Is it intended that this scheduler is reused for other tasks. This is a mandatory parameter.
        Parameters:
        scheduler - scheduler that will read ad process messages
        Returns:
        updated builder instance
      • periodExecutions

        public KafkaPublisher.Builder<K,​V> periodExecutions​(long periodExecutions)
        Specifies the period in milliseconds between successive scheduler executions. The default value is 100 milliseconds.
        Parameters:
        periodExecutions - period in milliseconds
        Returns:
        updated builder instance
      • pollTimeout

        public KafkaPublisher.Builder<K,​V> pollTimeout​(long pollTimeout)
        Specifies maximum time in milliseconds to block polling messages from Kafka. The default value is 50 milliseconds.
        Parameters:
        pollTimeout - maximum time in milliseconds to block polling
        Returns:
        updated builder instance
      • autoCommit

        public KafkaPublisher.Builder<K,​V> autoCommit​(boolean autoCommit)
        This flag defines the strategy of committing messages to Kafka. When true, the messages are committed at the moment they are polled from Kafka. When false, the messages are committed when Message.ack() is invoked. This value is mandatory to be specified, and it must be consistent with the value enable.auto.commit in Kafka properties. Failing to do this will result the next scenarios: - For autoCommit = true and enable.auto.commit = false, messages will never be committed in Kafka. - For autoCommit = false and enable.auto.commit = true, all messages will be committed and Message.ack() will have no effect.
        Parameters:
        autoCommit - strategy of committing
        Returns:
        updated builder instance
      • ackTimeout

        public KafkaPublisher.Builder<K,​V> ackTimeout​(long ackTimeout)
        This value applies only when autoCommit is set to false. It defines the maximum time in milliseconds that Message.ack() will be waiting for the commit in Kafka. The default value is Long.MAX_VALUE
        Parameters:
        ackTimeout - time in milliseconds
        Returns:
        updated builder instance
      • limitNoAck

        public KafkaPublisher.Builder<K,​V> limitNoAck​(int limitNoAck)
        This value applies only when autoCommit is set to false. It specifies the limit of messages waiting to be committed in Kafka. If this value is overflown, the KafkaPublisher will notify a failure. The intention of this value is to fail gracefully when there are many pending commits, instead of failing with OutOfMemoryError.
        Parameters:
        limitNoAck - limit of messages waiting to be committed
        Returns:
        updated builder instance
      • build

        public KafkaPublisher<K,​V> build()
        Description copied from interface: Builder
        Build the instance from this builder.
        Specified by:
        build in interface Builder<K>
        Returns:
        instance of the built type