Java Code Examples for org.apache.flink.streaming.connectors.kafka.internal.FlinkKafkaProducer#beginTransaction()
The following examples show how to use
org.apache.flink.streaming.connectors.kafka.internal.FlinkKafkaProducer#beginTransaction() .
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: FlinkKafkaProducer011.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Override protected KafkaTransactionState beginTransaction() throws FlinkKafka011Exception { switch (semantic) { case EXACTLY_ONCE: FlinkKafkaProducer<byte[], byte[]> producer = createTransactionalProducer(); producer.beginTransaction(); return new KafkaTransactionState(producer.getTransactionalId(), producer); case AT_LEAST_ONCE: case NONE: // Do not create new producer on each beginTransaction() if it is not necessary final KafkaTransactionState currentTransaction = currentTransaction(); if (currentTransaction != null && currentTransaction.producer != null) { return new KafkaTransactionState(currentTransaction.producer); } return new KafkaTransactionState(initNonTransactionalProducer(true)); default: throw new UnsupportedOperationException("Not implemented semantic"); } }
Example 2
Source File: FlinkKafkaProducer011.java From flink with Apache License 2.0 | 6 votes |
@Override protected KafkaTransactionState beginTransaction() throws FlinkKafka011Exception { switch (semantic) { case EXACTLY_ONCE: FlinkKafkaProducer<byte[], byte[]> producer = createTransactionalProducer(); producer.beginTransaction(); return new KafkaTransactionState(producer.getTransactionalId(), producer); case AT_LEAST_ONCE: case NONE: // Do not create new producer on each beginTransaction() if it is not necessary final KafkaTransactionState currentTransaction = currentTransaction(); if (currentTransaction != null && currentTransaction.producer != null) { return new KafkaTransactionState(currentTransaction.producer); } return new KafkaTransactionState(initNonTransactionalProducer(true)); default: throw new UnsupportedOperationException("Not implemented semantic"); } }
Example 3
Source File: FlinkKafkaProducer011.java From flink with Apache License 2.0 | 6 votes |
@Override protected KafkaTransactionState beginTransaction() throws FlinkKafka011Exception { switch (semantic) { case EXACTLY_ONCE: FlinkKafkaProducer<byte[], byte[]> producer = createTransactionalProducer(); producer.beginTransaction(); return new KafkaTransactionState(producer.getTransactionalId(), producer); case AT_LEAST_ONCE: case NONE: // Do not create new producer on each beginTransaction() if it is not necessary final KafkaTransactionState currentTransaction = currentTransaction(); if (currentTransaction != null && currentTransaction.producer != null) { return new KafkaTransactionState(currentTransaction.producer); } return new KafkaTransactionState(initNonTransactionalProducer(true)); default: throw new UnsupportedOperationException("Not implemented semantic"); } }
Example 4
Source File: FlinkKafkaProducerITCase.java From flink with Apache License 2.0 | 5 votes |
@Test(timeout = 30000L, expected = IllegalStateException.class) public void testBeginTransactionAfterClosed() { FlinkKafkaProducer<String, String> kafkaProducer = new FlinkKafkaProducer<>(extraProperties); kafkaProducer.initTransactions(); kafkaProducer.close(); kafkaProducer.beginTransaction(); }
Example 5
Source File: FlinkKafkaProducerITCase.java From flink with Apache License 2.0 | 5 votes |
private FlinkKafkaProducer<String, String> getClosedProducer(String topicName) { FlinkKafkaProducer<String, String> kafkaProducer = new FlinkKafkaProducer<>(extraProperties); kafkaProducer.initTransactions(); kafkaProducer.beginTransaction(); kafkaProducer.send(new ProducerRecord<>(topicName, "42", "42")); kafkaProducer.close(); return kafkaProducer; }
Example 6
Source File: FlinkKafkaProducerITCase.java From flink with Apache License 2.0 | 5 votes |
@Test(timeout = 30000L, expected = IllegalStateException.class) public void testBeginTransactionAfterClosed() { FlinkKafkaProducer<String, String> kafkaProducer = new FlinkKafkaProducer<>(extraProperties); kafkaProducer.initTransactions(); kafkaProducer.close(); kafkaProducer.beginTransaction(); }
Example 7
Source File: FlinkKafkaProducerITCase.java From flink with Apache License 2.0 | 5 votes |
private FlinkKafkaProducer<String, String> getClosedProducer(String topicName) { FlinkKafkaProducer<String, String> kafkaProducer = new FlinkKafkaProducer<>(extraProperties); kafkaProducer.initTransactions(); kafkaProducer.beginTransaction(); kafkaProducer.send(new ProducerRecord<>(topicName, "42", "42")); kafkaProducer.close(); return kafkaProducer; }