@Override public void beginTransaction() throws ProducerFencedException { kafkaProducer.beginTransaction(); }
@Override public void beginTransaction() throws ProducerFencedException { kafkaProducer.beginTransaction(); }
@Override public void beginTransaction() throws ProducerFencedException { kafkaProducer.beginTransaction(); }
private static void sendData(List<ConsumerRecord<byte[], byte[]>> recordList, @Nullable String txId) { LOG.info("Setting up kafka producer"); Properties producerProps = new Properties(); producerProps.setProperty("bootstrap.servers", KafkaBrokerResource.BROKER_IP_PORT); producerProps.setProperty("key.serializer", "org.apache.kafka.common.serialization.ByteArraySerializer"); producerProps.setProperty("value.serializer", "org.apache.kafka.common.serialization.ByteArraySerializer"); producerProps.setProperty("max.block.ms", "10000"); if (txId != null) { producerProps.setProperty(ProducerConfig.TRANSACTIONAL_ID_CONFIG, txId); } producer = new KafkaProducer<>(producerProps); LOG.info("kafka producer started"); LOG.info("Sending [{}] records", RECORDS.size()); if (txId != null) { producer.initTransactions(); producer.beginTransaction(); } recordList.stream() .map(consumerRecord -> new ProducerRecord<>(consumerRecord.topic(), consumerRecord.partition(), consumerRecord.timestamp(), consumerRecord.key(), consumerRecord.value())) .forEach(producerRecord -> producer.send(producerRecord)); if (txId != null) { producer.commitTransaction(); } producer.close(); }
if (records.count() > 0) { if (eosEnabled) { producer.beginTransaction();
@Override public void beginTransaction() throws ProducerFencedException { kafkaProducer.beginTransaction(); }
@Override public void beginTransaction() throws ProducerFencedException { kafkaProducer.beginTransaction(); }
@Override public void beginTransaction() throws ProducerFencedException { kafkaProducer.beginTransaction(); }
@Override public void beginTransaction() throws ProducerFencedException { kafkaProducer.beginTransaction(); }
private void doSend(ProducerRecord<Object, Object> producerRecord, KafkaProducer<Object, Object> transactionalProducer) { if(transactionalProducer == null) { // no transaction so hand over to the current thread (and send in it's own transaction) runCommand((kafkaConsumer, kafkaProducer) -> { try { kafkaProducer.beginTransaction(); kafkaProducer.send(producerRecord, loggingCallback); kafkaProducer.commitTransaction(); } catch(RetriableException e) { logger.warn("Recoverable exception while sending ProducerRecord", e); } catch(ProducerFencedException e) { logger.error("FATAL: ProducerFenced while committing transaction, another Node seems to be handling the same shards", e); // @todo: this is an unrecoverable error } catch(KafkaException e) { logger.error("FATAL: Unrecoverable exception while committing producer transaction", e); // @todo: this is an unrecoverable error } catch(Throwable t) { logger.error("Unexpected exception while sending ProducerRecord", t); } }); } else { transactionalProducer.send(producerRecord, loggingCallback); } }
public Stats runTest() { System.out.println("Running producer performance test using non-reactive API, class=" + this.getClass().getSimpleName() + " messageSize=" + recordSize); KafkaProducer<byte[], byte[]> producer = new KafkaProducer<byte[], byte[]>(producerProps); if (transactionsEnabled) producer.initTransactions(); int currentTransactionSize = 0; long transactionStartMs = 0; for (int i = 0; i < numRecords; i++) { long sendStartMs = System.currentTimeMillis(); if (transactionsEnabled && currentTransactionSize == 0) { producer.beginTransaction(); transactionStartMs = sendStartMs; } Callback cb = stats.nextCompletion(sendStartMs, recordSize, stats); producer.send(record, cb); currentTransactionSize++; if (transactionsEnabled && transactionDurationMs <= (sendStartMs - transactionStartMs)) { producer.commitTransaction(); currentTransactionSize = 0; } if (throttler.shouldThrottle(i, sendStartMs)) throttler.throttle(); } if (transactionsEnabled && currentTransactionSize != 0) producer.commitTransaction(); stats.complete(); producer.close(); return stats; } }
eventListener.getMessageClass().getName(), false); producer.beginTransaction(); try {
producer.beginTransaction(); messagesToFire.forEach(scheduledMessage -> {