本文整理汇总了Java中org.apache.kafka.clients.producer.internals.TransactionalRequestResult.await方法的典型用法代码示例。如果您正苦于以下问题:Java TransactionalRequestResult.await方法的具体用法?Java TransactionalRequestResult.await怎么用?Java TransactionalRequestResult.await使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.kafka.clients.producer.internals.TransactionalRequestResult
的用法示例。
在下文中一共展示了TransactionalRequestResult.await方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: flushNewPartitions
import org.apache.kafka.clients.producer.internals.TransactionalRequestResult; //导入方法依赖的package包/类
/**
* Besides committing {@link org.apache.kafka.clients.producer.KafkaProducer#commitTransaction} is also adding new
* partitions to the transaction. flushNewPartitions method is moving this logic to pre-commit/flush, to make
* resumeTransaction simpler. Otherwise resumeTransaction would require to restore state of the not yet added/"in-flight"
* partitions.
*/
private void flushNewPartitions() {
LOG.info("Flushing new partitions");
TransactionalRequestResult result = enqueueNewPartitions();
Object sender = getValue(kafkaProducer, "sender");
invoke(sender, "wakeup");
result.await();
}
示例2: initTransactions
import org.apache.kafka.clients.producer.internals.TransactionalRequestResult; //导入方法依赖的package包/类
/**
* Needs to be called before any other methods when the transactional.id is set in the configuration.
* <p>
* This method does the following:
* 1. Ensures any transactions initiated by previous instances of the producer
* are completed. If the previous instance had failed with a transaction in
* progress, it will be aborted. If the last transaction had begun completion,
* but not yet finished, this method awaits its completion.
* 2. Gets the internal producer id and epoch, used in all future transactional
* messages issued by the producer.
*
* @throws IllegalStateException if the TransactionalId for the producer is not set
* in the configuration.
*/
public void initTransactions() {
if (transactionManager == null)
throw new IllegalStateException("Cannot call initTransactions without setting a transactional id.");
TransactionalRequestResult result = transactionManager.initializeTransactions();
sender.wakeup();
result.await();
}
示例3: sendOffsetsToTransaction
import org.apache.kafka.clients.producer.internals.TransactionalRequestResult; //导入方法依赖的package包/类
/**
* Sends a list of consumed offsets to the consumer group coordinator, and also marks
* those offsets as part of the current transaction. These offsets will be considered
* consumed only if the transaction is committed successfully.
* <p>
* This method should be used when you need to batch consumed and produced messages
* together, typically in a consume-transform-produce pattern.
*
* @throws ProducerFencedException if another producer with the same
* transactional.id is active.
*/
public void sendOffsetsToTransaction(Map<TopicPartition, OffsetAndMetadata> offsets,
String consumerGroupId) throws ProducerFencedException {
if (transactionManager == null)
throw new IllegalStateException("Cannot send offsets to transaction since transactions are not enabled.");
TransactionalRequestResult result = transactionManager.sendOffsetsToTransaction(offsets, consumerGroupId);
sender.wakeup();
result.await();
}
示例4: commitTransaction
import org.apache.kafka.clients.producer.internals.TransactionalRequestResult; //导入方法依赖的package包/类
/**
* Commits the ongoing transaction. This method will flush any unsent records before actually committing the transaction.
* <p>
* Further, if any of the {@link #send(ProducerRecord)} calls which were part of the transaction hit irrecoverable
* errors, this method will throw the last received exception immediately and the transaction will not be committed.
* So all {@link #send(ProducerRecord)} calls in a transaction must succeed in order for this method to succeed.
*
* @throws ProducerFencedException if another producer with the same
* transactional.id is active.
*/
public void commitTransaction() throws ProducerFencedException {
if (transactionManager == null)
throw new IllegalStateException("Cannot commit transaction since transactions are not enabled");
TransactionalRequestResult result = transactionManager.beginCommit();
sender.wakeup();
result.await();
}
示例5: abortTransaction
import org.apache.kafka.clients.producer.internals.TransactionalRequestResult; //导入方法依赖的package包/类
/**
* Aborts the ongoing transaction. Any unflushed produce messages will be aborted when this call is made.
* This call will throw an exception immediately if any prior {@link #send(ProducerRecord)} calls failed with a
* {@link ProducerFencedException} or an instance of {@link org.apache.kafka.common.errors.AuthorizationException}.
*
* @throws ProducerFencedException if another producer with the same
* transactional.id is active.
*/
public void abortTransaction() throws ProducerFencedException {
if (transactionManager == null)
throw new IllegalStateException("Cannot abort transaction since transactions are not enabled.");
TransactionalRequestResult result = transactionManager.beginAbort();
sender.wakeup();
result.await();
}