@Override public void initTransactions() { kafkaProducer.initTransactions(); }
@Override public void initTransactions() { kafkaProducer.initTransactions(); }
@Override public void initTransactions() { kafkaProducer.initTransactions(); }
@Test public void testTransactionalProducerWithInvalidCredentials() { Map<String, Object> props = new HashMap<>(saslClientConfigs); props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:" + server.port()); props.put(ProducerConfig.TRANSACTIONAL_ID_CONFIG, "txclient-1"); props.put(ProducerConfig.ENABLE_IDEMPOTENCE_CONFIG, "true"); StringSerializer serializer = new StringSerializer(); try (KafkaProducer<String, String> producer = new KafkaProducer<>(props, serializer, serializer)) { producer.initTransactions(); fail("Expected an authentication error!"); } catch (SaslAuthenticationException e) { // expected exception } }
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(); }
consumer.subscribe(singletonList(Topics.ORDERS.name())); if (eosEnabled) { producer.initTransactions();
@Override public void initTransactions() { kafkaProducer.initTransactions(); }
@Override public void initTransactions() { kafkaProducer.initTransactions(); }
@Override public void initTransactions() { kafkaProducer.initTransactions(); }
@Override public void initTransactions() { kafkaProducer.initTransactions(); }
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; } }