title: Spring Kafka Accumulator Use Case
body: <p>I am developing a SpringBoot application which consumes events from a Kafka (broker version is 2.6) input topic and produce an event into an output topic.</p>
  <p>In order to respect some business constraints the component should wait to have at least X messages (which is a batch size) or until a timeout expired. In conclusion, it should act like an accumulator.
  Further, another mandatory requirement is to respect exactly-once semantic.</p>
  <p>The first solution I approached was to maintain events in-memory until constraints are satisfied and then publish output messages. In order to implement an at least-once semantic I used manual_immediate ack mode and I stored latest ack for each partition in-memory and acknowledge after processing ended (it may cause duplicates in race conditions but it is acceptable).</p>
  <p>In order to increase reliability I enforced upstream transactionality and set read_committed mode on listener.</p>
  <p>I was wondering wheter it is a correct approach or if there is any suitable solution like batch_mode listener.
  On a first look it is wonderful, but it seems not to allow accumulating on number of records, but rather on data size in bytes.</p>
  <p>Thanks in advance,
  G.</p>