Skip to content

Pass through keyword arguments to send_produce_request #303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions kafka/producer/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class Producer(object):
batch_send - If True, messages are send in batches
batch_send_every_n - If set, messages are send in batches of this size
batch_send_every_t - If set, messages are send after this timeout
kwargs - keyword arguments that get passed throught to `client.send_produce_request`
"""

ACK_NOT_REQUIRED = 0 # No ack is required
Expand All @@ -113,7 +114,8 @@ def __init__(self, client, async=False,
codec=None,
batch_send=False,
batch_send_every_n=BATCH_SEND_MSG_COUNT,
batch_send_every_t=BATCH_SEND_DEFAULT_INTERVAL):
batch_send_every_t=BATCH_SEND_DEFAULT_INTERVAL,
**kwargs):

if batch_send:
async = True
Expand All @@ -127,6 +129,8 @@ def __init__(self, client, async=False,
self.async = async
self.req_acks = req_acks
self.ack_timeout = ack_timeout
self._request_kwargs = {'acks': self.req_acks, 'timeout': self.ack_timeout}
self._request_kwargs.update(kwargs)

if codec is None:
codec = CODEC_NONE
Expand Down Expand Up @@ -194,8 +198,7 @@ def _send_messages(self, topic, partition, *msg, **kwargs):
messages = create_message_set(msg, self.codec, key)
req = ProduceRequest(topic, partition, messages)
try:
resp = self.client.send_produce_request([req], acks=self.req_acks,
timeout=self.ack_timeout)
resp = self.client.send_produce_request([req], **self._request_kwargs)
except Exception:
log.exception("Unable to send messages")
raise
Expand Down