Skip to content

Commit 75ae411

Browse files
committed
Default retries -> infinite
1 parent 95856f0 commit 75ae411

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

kafka/producer/kafka.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ class KafkaProducer(object):
143143
Compression is of full batches of data, so the efficacy of batching
144144
will also impact the compression ratio (more batching means better
145145
compression). Default: None.
146-
retries (int): Setting a value greater than zero will cause the client
146+
retries (numeric): Setting a value greater than zero will cause the client
147147
to resend any record whose send fails with a potentially transient
148148
error. Note that this retry is no different than if the client
149149
resent the record upon receiving the error. Allowing retries
@@ -156,7 +156,7 @@ class KafkaProducer(object):
156156
configured by delivery_timeout_ms expires first before successful
157157
acknowledgement. Users should generally prefer to leave this config
158158
unset and instead use delivery_timeout_ms to control retry behavior.
159-
Default: 2147483647 (java max int).
159+
Default: float('inf') (infinite)
160160
batch_size (int): Requests sent to brokers will contain multiple
161161
batches, one for each partition with data available to be sent.
162162
A small batch size will make batching less common and may reduce
@@ -337,7 +337,7 @@ class KafkaProducer(object):
337337
'acks': 1,
338338
'bootstrap_topics_filter': set(),
339339
'compression_type': None,
340-
'retries': 2147483647,
340+
'retries': float('inf'),
341341
'batch_size': 16384,
342342
'linger_ms': 0,
343343
'partitioner': DefaultPartitioner(),
@@ -485,10 +485,7 @@ def __init__(self, **configs):
485485
else:
486486
log.info("%s: Instantiated an idempotent producer.", str(self))
487487

488-
if 'retries' not in user_provided_configs:
489-
log.info("%s: Overriding the default 'retries' config to 3 since the idempotent producer is enabled.", str(self))
490-
self.config['retries'] = 3
491-
elif self.config['retries'] == 0:
488+
if self.config['retries'] == 0:
492489
raise Errors.KafkaConfigurationError("Must set 'retries' to non-zero when using the idempotent producer.")
493490

494491
if 'max_in_flight_requests_per_connection' not in user_provided_configs:

kafka/producer/sender.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Sender(threading.Thread):
3030
DEFAULT_CONFIG = {
3131
'max_request_size': 1048576,
3232
'acks': 1,
33-
'retries': 0,
33+
'retries': float('inf'),
3434
'request_timeout_ms': 30000,
3535
'retry_backoff_ms': 100,
3636
'metrics': None,
@@ -468,7 +468,7 @@ def _complete_batch(self, batch, error, base_offset, timestamp_ms=None):
468468
if self._can_retry(batch, error):
469469
# retry
470470
log.warning("%s: Got error produce response on topic-partition %s,"
471-
" retrying (%d attempts left). Error: %s",
471+
" retrying (%s attempts left). Error: %s",
472472
str(self), batch.topic_partition,
473473
self.config['retries'] - batch.attempts - 1,
474474
error)

0 commit comments

Comments
 (0)