@Override
    public synchronized <K, V> void increment(KafkaProducer<K, V> producer) {
        // Increment the message tracker.
        messageTracker += 1;

        // Flush when we reach the desired number of messages.
        if (messageTracker >= messagesPerFlush) {
            messageTracker = 0;
            try {
                producer.flush();
            } catch (InterruptException e) {
                // Ignore flush interruption exceptions.
            }
        }
    }
This generator will flush the producer after a specific number of messages.  This is useful to simulate a specific
number of messages in a batch regardless of the message size, since batch flushing is not exposed in the
KafkaProducer client code.

WARNING: This does not directly control when KafkaProducer will batch, this only makes best effort.  This also
cannot tell when a KafkaProducer batch is closed.  If the KafkaProducer sends a batch before this executes, this
will continue to execute on its own cadence.  To alleviate this, make sure to set `linger.ms` to allow for at least
`messagesPerFlush` messages to be generated, and make sure to set `batch.size` to allow for all these messages.

Here is an example spec:

{
   "type": "constant",
   "messagesPerFlush": 16
}

This example will flush the producer every 16 messages.
trogdor/src/main/java/org/apache/kafka/trogdor/workload/ConstantFlushGenerator.java