use of org.apache.pulsar.client.api.transaction.Transaction in project flink by apache.
the class TopicProducerRegister method abortTransactions.
/**
* Abort the existed transactions. This method would be used when closing PulsarWriter.
*/
private void abortTransactions() {
if (transactionRegister.isEmpty()) {
return;
}
TransactionCoordinatorClient coordinatorClient = ((PulsarClientImpl) pulsarClient).getTcClient();
// This null check is used for making sure transaction is enabled in client.
checkNotNull(coordinatorClient);
try (Closer closer = Closer.create()) {
for (Transaction transaction : transactionRegister.values()) {
TxnID txnID = transaction.getTxnID();
closer.register(() -> coordinatorClient.abort(txnID));
}
clearTransactions();
} catch (IOException e) {
throw new FlinkRuntimeException(e);
}
}
use of org.apache.pulsar.client.api.transaction.Transaction in project flink by apache.
the class TopicProducerRegister method createMessageBuilder.
/**
* Create a TypedMessageBuilder which could be sent to Pulsar directly. First, we would create a
* topic-related producer or use a cached instead. Then we would try to find a topic-related
* transaction. We would generate a transaction instance if there is no transaction. Finally, we
* create the message builder and put the element into it.
*/
public <T> TypedMessageBuilder<T> createMessageBuilder(String topic, Schema<T> schema) {
Producer<T> producer = getOrCreateProducer(topic, schema);
DeliveryGuarantee deliveryGuarantee = sinkConfiguration.getDeliveryGuarantee();
if (deliveryGuarantee == DeliveryGuarantee.EXACTLY_ONCE) {
Transaction transaction = getOrCreateTransaction(topic);
return producer.newMessage(transaction);
} else {
return producer.newMessage();
}
}
Aggregations