Package org.apache.kafka.clients.producer

Examples of org.apache.kafka.clients.producer.KafkaProducer$FutureFailure


                            return new Thread(kafkaProducerThreads, r);
                        }
                    };
                    Callable<KafkaProducer> task = new Callable<KafkaProducer>() {
                        public KafkaProducer call() throws InterruptedException {
                            return new KafkaProducer(props);
                        }
                    };
                    ExecutorService executorService = Executors.newFixedThreadPool(1, threadFactory);
                    Future<KafkaProducer> future = executorService.submit(task);
                    try {
View Full Code Here


            String[] pieces = args[i].split("=");
            if (pieces.length != 2)
                throw new IllegalArgumentException("Invalid property: " + args[i]);
            props.put(pieces[0], pieces[1]);
        }
        KafkaProducer producer = new KafkaProducer(props);

        /* setup perf test */
        byte[] payload = new byte[recordSize];
        Arrays.fill(payload, (byte) 1);
        ProducerRecord record = new ProducerRecord(topicName, payload);
        long sleepTime = NS_PER_SEC / throughput;
        long sleepDeficitNs = 0;
        Stats stats = new Stats(numRecords, 5000);
        for (int i = 0; i < numRecords; i++) {
            long sendStart = System.currentTimeMillis();
            Callback cb = stats.nextCompletion(sendStart, payload.length, stats);
            producer.send(record, cb);

            /*
             * Maybe sleep a little to control throughput. Sleep time can be a bit inaccurate for times < 1 ms so
             * instead of sleeping each time instead wait until a minimum sleep time accumulates (the "sleep deficit")
             * and then make up the whole deficit in one longer sleep.
             */
            if (throughput > 0) {
                sleepDeficitNs += sleepTime;
                if (sleepDeficitNs >= MIN_SLEEP_NS) {
                    long sleepMs = sleepDeficitNs / 1000000;
                    long sleepNs = sleepDeficitNs - sleepMs * 1000000;
                    Thread.sleep(sleepMs, (int) sleepNs);
                    sleepDeficitNs = 0;
                }
            }
        }

        /* print final results */
        producer.close();
        stats.printTotal();
    }
View Full Code Here

            props.putAll(etcProps);
        }

        this.keyTopicMap = keyTopicMap != null ? keyTopicMap : Maps.<String, String>newHashMap();

        producer = new KafkaProducer( props );

        Monitors.registerObject(clientId, this);
    }
View Full Code Here

TOP

Related Classes of org.apache.kafka.clients.producer.KafkaProducer$FutureFailure

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.