Java Code Examples for org.apache.flink.streaming.connectors.kafka.internal.FlinkKafkaInternalProducer#close()
The following examples show how to use
org.apache.flink.streaming.connectors.kafka.internal.FlinkKafkaInternalProducer#close() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FlinkKafkaProducer.java From flink with Apache License 2.0 | 6 votes |
@Override protected void recoverAndCommit(FlinkKafkaProducer.KafkaTransactionState transaction) { if (transaction.isTransactional()) { FlinkKafkaInternalProducer<byte[], byte[]> producer = null; try { producer = initTransactionalProducer(transaction.transactionalId, false); producer.resumeTransaction(transaction.producerId, transaction.epoch); producer.commitTransaction(); } catch (InvalidTxnStateException | ProducerFencedException ex) { // That means we have committed this transaction before. LOG.warn("Encountered error {} while recovering transaction {}. " + "Presumably this transaction has been already committed before", ex, transaction); } finally { if (producer != null) { producer.close(0, TimeUnit.SECONDS); } } } }
Example 2
Source File: FlinkKafkaInternalProducerITCase.java From flink with Apache License 2.0 | 5 votes |
@Test(timeout = 30000L, expected = IllegalStateException.class) public void testBeginTransactionAfterClosed() { FlinkKafkaInternalProducer<String, String> kafkaProducer = new FlinkKafkaInternalProducer<>(extraProperties); kafkaProducer.initTransactions(); kafkaProducer.close(); kafkaProducer.beginTransaction(); }
Example 3
Source File: FlinkKafkaInternalProducerITCase.java From flink with Apache License 2.0 | 5 votes |
private FlinkKafkaInternalProducer<String, String> getClosedProducer(String topicName) { FlinkKafkaInternalProducer<String, String> kafkaProducer = new FlinkKafkaInternalProducer<>(extraProperties); kafkaProducer.initTransactions(); kafkaProducer.beginTransaction(); kafkaProducer.send(new ProducerRecord<>(topicName, "42", "42")); kafkaProducer.close(); return kafkaProducer; }
Example 4
Source File: FlinkKafkaProducer.java From flink with Apache License 2.0 | 5 votes |
@Override protected void recoverAndAbort(FlinkKafkaProducer.KafkaTransactionState transaction) { if (transaction.isTransactional()) { FlinkKafkaInternalProducer<byte[], byte[]> producer = null; try { producer = initTransactionalProducer(transaction.transactionalId, false); producer.initTransactions(); } finally { if (producer != null) { producer.close(0, TimeUnit.SECONDS); } } } }
Example 5
Source File: FlinkKafkaInternalProducerITCase.java From flink with Apache License 2.0 | 5 votes |
@Test(timeout = 30000L) public void testResumeTransaction() throws IOException { String topicName = "flink-kafka-producer-resume-transaction"; FlinkKafkaInternalProducer<String, String> kafkaProducer = new FlinkKafkaInternalProducer<>(extraProperties); try { kafkaProducer.initTransactions(); kafkaProducer.beginTransaction(); kafkaProducer.send(new ProducerRecord<>(topicName, "42", "42")); kafkaProducer.flush(); long producerId = kafkaProducer.getProducerId(); short epoch = kafkaProducer.getEpoch(); FlinkKafkaInternalProducer<String, String> resumeProducer = new FlinkKafkaInternalProducer<>(extraProperties); try { resumeProducer.resumeTransaction(producerId, epoch); resumeProducer.commitTransaction(); } finally { resumeProducer.close(Duration.ofSeconds(5)); } assertRecord(topicName, "42", "42"); // this shouldn't throw - in case of network split, old producer might attempt to commit it's transaction kafkaProducer.commitTransaction(); // this shouldn't fail also, for same reason as above resumeProducer = new FlinkKafkaInternalProducer<>(extraProperties); try { resumeProducer.resumeTransaction(producerId, epoch); resumeProducer.commitTransaction(); } finally { resumeProducer.close(Duration.ofSeconds(5)); } } finally { kafkaProducer.close(Duration.ofSeconds(5)); } deleteTestTopic(topicName); }
Example 6
Source File: FlinkKafkaInternalProducerITCase.java From flink with Apache License 2.0 | 5 votes |
@Test(timeout = 30000L, expected = IllegalStateException.class) public void testBeginTransactionAfterClosed() { FlinkKafkaInternalProducer<String, String> kafkaProducer = new FlinkKafkaInternalProducer<>(extraProperties); kafkaProducer.initTransactions(); kafkaProducer.close(Duration.ofSeconds(5)); kafkaProducer.beginTransaction(); }
Example 7
Source File: FlinkKafkaInternalProducerITCase.java From flink with Apache License 2.0 | 5 votes |
private FlinkKafkaInternalProducer<String, String> getClosedProducer(String topicName) { FlinkKafkaInternalProducer<String, String> kafkaProducer = new FlinkKafkaInternalProducer<>(extraProperties); kafkaProducer.initTransactions(); kafkaProducer.beginTransaction(); kafkaProducer.send(new ProducerRecord<>(topicName, "42", "42")); kafkaProducer.close(Duration.ofSeconds(5)); return kafkaProducer; }
Example 8
Source File: FlinkKafkaProducer.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
private void recycleTransactionalProducer(FlinkKafkaInternalProducer<byte[], byte[]> producer) { availableTransactionalIds.add(producer.getTransactionalId()); producer.close(); }
Example 9
Source File: FlinkKafkaProducer.java From flink with Apache License 2.0 | 4 votes |
private void recycleTransactionalProducer(FlinkKafkaInternalProducer<byte[], byte[]> producer) { availableTransactionalIds.add(producer.getTransactionalId()); producer.close(); }
Example 10
Source File: FlinkKafkaInternalProducerITCase.java From flink with Apache License 2.0 | 4 votes |
@Test(timeout = 30000L, expected = IllegalStateException.class) public void testPartitionsForAfterClosed() { FlinkKafkaInternalProducer<String, String> kafkaProducer = new FlinkKafkaInternalProducer<>(extraProperties); kafkaProducer.close(); kafkaProducer.partitionsFor("Topic"); }
Example 11
Source File: FlinkKafkaInternalProducerITCase.java From flink with Apache License 2.0 | 4 votes |
@Test(timeout = 30000L, expected = IllegalStateException.class) public void testInitTransactionsAfterClosed() { FlinkKafkaInternalProducer<String, String> kafkaProducer = new FlinkKafkaInternalProducer<>(extraProperties); kafkaProducer.close(); kafkaProducer.initTransactions(); }
Example 12
Source File: FlinkKafkaProducer.java From flink with Apache License 2.0 | 4 votes |
private void recycleTransactionalProducer(FlinkKafkaInternalProducer<byte[], byte[]> producer) { availableTransactionalIds.add(producer.getTransactionalId()); producer.flush(); producer.close(Duration.ofSeconds(0)); }
Example 13
Source File: FlinkKafkaInternalProducerITCase.java From flink with Apache License 2.0 | 4 votes |
@Test(timeout = 30000L, expected = IllegalStateException.class) public void testPartitionsForAfterClosed() { FlinkKafkaInternalProducer<String, String> kafkaProducer = new FlinkKafkaInternalProducer<>(extraProperties); kafkaProducer.close(Duration.ofSeconds(5)); kafkaProducer.partitionsFor("Topic"); }
Example 14
Source File: FlinkKafkaInternalProducerITCase.java From flink with Apache License 2.0 | 4 votes |
@Test(timeout = 30000L, expected = IllegalStateException.class) public void testInitTransactionsAfterClosed() { FlinkKafkaInternalProducer<String, String> kafkaProducer = new FlinkKafkaInternalProducer<>(extraProperties); kafkaProducer.close(Duration.ofSeconds(5)); kafkaProducer.initTransactions(); }