/** * Closes the sender without sending out any pending messages. */ public void forceClose() { this.forceClose = true; initiateClose(); }
this.sender.initiateClose(); if (this.ioThread != null) { try {
@Test public void testSenderShutdownWithPendingAddPartitions() throws Exception { long pid = 13131L; short epoch = 1; doInitTransactions(pid, epoch); transactionManager.beginTransaction(); transactionManager.maybeAddPartitionToTransaction(tp0); FutureRecordMetadata sendFuture = accumulator.append(tp0, time.milliseconds(), "key".getBytes(), "value".getBytes(), Record.EMPTY_HEADERS, null, MAX_BLOCK_TIMEOUT).future; prepareAddPartitionsToTxn(tp0, Errors.NONE); prepareProduceResponse(Errors.NONE, pid, epoch); sender.initiateClose(); sender.run(); assertTrue(sendFuture.isDone()); }
/** * Close this producer. This method blocks until all in-flight requests complete. */ @Override public void close() { log.trace("Closing the Kafka producer."); this.sender.initiateClose(); try { this.ioThread.join(); } catch (InterruptedException e) { throw new KafkaException(e); } this.metrics.close(); this.keySerializer.close(); this.valueSerializer.close(); log.debug("The Kafka producer has closed."); }