karafka / karafka-web

Web UI for monitoring and managing Karafka consumers
Other
50 stars 7 forks source link

If not transactional use lower ack level for web-ui reporting in producer #342

Open mensfeld opened 1 month ago

mensfeld commented 1 month ago

Users usually may want to have stronger delivery warranties in their producers for their setup. We do not need this level of warranties in web UI because it's not mission critical and more analytics. That's why ack 1 should be ok to work with.

mensfeld commented 5 days ago
# frozen_string_literal: true

module Karafka
  module Web
    class Producer < SimpleDelegator
      def initialize
        @initialized = false
      end

      def __getobj__
        unless @initialized
          @delegate_sd_obj = build_producer
          @initialized = true
        end

        super
      end

      private

      def build_producer
        default = ::Karafka.producer

        return default if default.idempotent?
        return default if default.transactional?

        default.variant(topic_config: { acks: 0 })
      end
    end
  end
end