/** * Use the supplied function to asynchronously produce messages with String keys and values, and write them to the * cluster. * * @param messageCount the number of messages to produce; must be positive * @param completionCallback the function to be called when the producer is completed; may be null * @param messageSupplier the function to produce messages; may not be null */ public void produceStrings(int messageCount, Runnable completionCallback, Supplier<ProducerRecord<String, String>> messageSupplier) { Serializer<String> keySer = new StringSerializer(); Serializer<String> valSer = keySer; String randomId = UUID.randomUUID().toString(); produce(randomId, messageCount, keySer, valSer, completionCallback, messageSupplier); }
/** * Use the supplied function to asynchronously produce messages with String keys and Integer values, and write them to the * cluster. * * @param messageCount the number of messages to produce; must be positive * @param completionCallback the function to be called when the producer is completed; may be null * @param messageSupplier the function to produce messages; may not be null */ public void produceIntegers(int messageCount, Runnable completionCallback, Supplier<ProducerRecord<String, Integer>> messageSupplier) { Serializer<String> keySer = new StringSerializer(); Serializer<Integer> valSer = new IntegerSerializer(); String randomId = UUID.randomUUID().toString(); produce(randomId, messageCount, keySer, valSer, completionCallback, messageSupplier); }
/** * Use the supplied function to asynchronously produce messages with String keys and {@link Document} values, and write * them to the cluster. * * @param messageCount the number of messages to produce; must be positive * @param completionCallback the function to be called when the producer is completed; may be null * @param messageSupplier the function to produce messages; may not be null */ public void produceDocuments(int messageCount, Runnable completionCallback, Supplier<ProducerRecord<String, Document>> messageSupplier) { Serializer<String> keySer = new StringSerializer(); Serializer<Document> valSer = new DocumentSerdes(); String randomId = UUID.randomUUID().toString(); produce(randomId, messageCount, keySer, valSer, completionCallback, messageSupplier); }
kafkaCluster.useTo().produce("testCleanupInConsumer_producer", 100, new StringSerializer(), new StringSerializer(), async::countDown, () -> new ProducerRecord<>(topicName, "the_value"));
kafkaCluster.useTo().produce("testCleanupInConsumer_producer", 100, new StringSerializer(), new StringSerializer(), async::countDown, () -> new ProducerRecord<>(topicName, "the_value"));
cluster.useTo().produce("manual", new StringSerializer(), new IntegerSerializer(), produer -> { produer.write(topicName, "key1", 1); produer.write(topicName, "key2", 2);
/** * Use the supplied function to asynchronously produce {@link Document} messages and write them to the cluster. * * @param producerName the name of the producer; may not be null * @param producer the function that will asynchronously */ public <K, V> void produce(String producerName, Consumer<InteractiveProducer<String, Document>> producer) { produce(producerName, new StringSerializer(), new DocumentSerdes(), producer); }