Skip to content

Commit 63a9907

Browse files
committed
Enable batching by default
Keep the same behavior with other clients.
1 parent c3c12c4 commit 63a9907

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

pulsar/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ def create_producer(self, topic,
617617
max_pending_messages=1000,
618618
max_pending_messages_across_partitions=50000,
619619
block_if_queue_full=False,
620-
batching_enabled=False,
620+
batching_enabled=True,
621621
batching_max_messages=1000,
622622
batching_max_allowed_size_in_bytes=128*1024,
623623
batching_max_publish_delay_ms=10,
@@ -670,7 +670,7 @@ def create_producer(self, topic,
670670
671671
SNAPPY is supported since Pulsar 2.4. Consumers will need to be at least at that release in order to
672672
be able to receive messages compressed with SNAPPY.
673-
batching_enabled: bool, default=False
673+
batching_enabled: bool, default=True
674674
When automatic batching is enabled, multiple calls to `send` can result in a single batch to be sent to the
675675
broker, leading to better throughput, especially when publishing small messages.
676676
All messages in a batch will be published as a single batched message. The consumer will be delivered

tests/pulsar_test.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,18 +146,21 @@ def test_producer_send_async(self):
146146

147147
sent_messages = []
148148

149+
event = threading.Event()
149150
def send_callback(producer, msg):
150151
sent_messages.append(msg)
152+
if len(sent_messages) >= 3:
153+
event.set()
151154

152155
producer.send_async(b"hello", send_callback)
153156
producer.send_async(b"hello", send_callback)
154157
producer.send_async(b"hello", send_callback)
155158

156-
i = 0
157-
while len(sent_messages) < 3 and i < 100:
158-
time.sleep(0.1)
159-
i += 1
159+
event.wait(3000)
160160
self.assertEqual(len(sent_messages), 3)
161+
for i in range(0, len(sent_messages)):
162+
msg_id = sent_messages[i]
163+
self.assertEqual(msg_id.batch_index(), i)
161164
client.close()
162165

163166
def test_producer_send(self):

0 commit comments

Comments
 (0)