summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.rst8
-rw-r--r--docs/index.rst8
-rw-r--r--docs/usage.rst7
3 files changed, 19 insertions, 4 deletions
diff --git a/README.rst b/README.rst
index 782aba0..8b40519 100644
--- a/README.rst
+++ b/README.rst
@@ -76,9 +76,13 @@ for more details.
>>> from kafka import KafkaProducer
>>> producer = KafkaProducer(bootstrap_servers='localhost:1234')
->>> producer.send('foobar', b'some_message_bytes')
+>>> for _ in range(100):
+... producer.send('foobar', b'some_message_bytes')
->>> # Blocking send
+>>> # Block until all pending messages are sent
+>>> producer.flush()
+
+>>> # Block until a single message is sent (or timeout)
>>> producer.send('foobar', b'another_message').get(timeout=60)
>>> # Use a key for hashed-partitioning
diff --git a/docs/index.rst b/docs/index.rst
index d8f826a..eb8f429 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -74,9 +74,13 @@ client. See `KafkaProducer <apidoc/KafkaProducer.html>`_ for more details.
>>> from kafka import KafkaProducer
>>> producer = KafkaProducer(bootstrap_servers='localhost:1234')
->>> producer.send('foobar', b'some_message_bytes')
+>>> for _ in range(100):
+... producer.send('foobar', b'some_message_bytes')
->>> # Blocking send
+>>> # Block until all pending messages are sent
+>>> producer.flush()
+
+>>> # Block until a single message is sent (or timeout)
>>> producer.send('foobar', b'another_message').get(timeout=60)
>>> # Use a key for hashed-partitioning
diff --git a/docs/usage.rst b/docs/usage.rst
index d48cc0a..85fc44f 100644
--- a/docs/usage.rst
+++ b/docs/usage.rst
@@ -87,5 +87,12 @@ KafkaProducer
producer = KafkaProducer(value_serializer=lambda m: json.dumps(m).encode('ascii'))
producer.send('json-topic', {'key': 'value'})
+ # produce asynchronously
+ for _ in range(100):
+ producer.send('my-topic', b'msg')
+
+ # block until all async messages are sent
+ producer.flush()
+
# configure multiple retries
producer = KafkaProducer(retries=5)