Skip to content

Commit b1a7799

Browse files
committed
Support setting the max bytes to fetch per request
1 parent 95e3a21 commit b1a7799

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

lib/kafka/client.rb

+1
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ def fetch_messages(topic:, partition:, offset: :latest, max_wait_time: 5, min_by
369369
cluster: @cluster,
370370
logger: @logger,
371371
min_bytes: min_bytes,
372+
max_bytes: max_bytes,
372373
max_wait_time: max_wait_time,
373374
)
374375

lib/kafka/fetch_operation.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@ module Kafka
1818
# operation.execute
1919
#
2020
class FetchOperation
21-
def initialize(cluster:, logger:, min_bytes: 1, max_wait_time: 5)
21+
def initialize(cluster:, logger:, min_bytes: 1, max_bytes: 10485760, max_wait_time: 5)
2222
@cluster = cluster
2323
@logger = logger
2424
@min_bytes = min_bytes
25+
@max_bytes = max_bytes
2526
@max_wait_time = max_wait_time
2627
@topics = {}
2728
end
2829

29-
def fetch_from_partition(topic, partition, offset: :latest, max_bytes: 1048576)
30+
def fetch_from_partition(topic, partition, offset: :latest, max_bytes: 10485760)
3031
if offset == :earliest
3132
offset = -2
3233
elsif offset == :latest
@@ -66,6 +67,7 @@ def execute
6667
options = {
6768
max_wait_time: @max_wait_time * 1000, # Kafka expects ms, not secs
6869
min_bytes: @min_bytes,
70+
max_bytes: @max_bytes,
6971
topics: topics,
7072
}
7173

lib/kafka/protocol/fetch_request.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ class FetchRequest
1919
# @param max_wait_time [Integer]
2020
# @param min_bytes [Integer]
2121
# @param topics [Hash]
22-
def initialize(max_wait_time:, min_bytes:, topics:)
22+
def initialize(max_wait_time:, min_bytes:, max_bytes:, topics:)
2323
@replica_id = REPLICA_ID
2424
@max_wait_time = max_wait_time
2525
@min_bytes = min_bytes
26+
@max_bytes = max_bytes
2627
@topics = topics
2728
end
2829

@@ -31,7 +32,7 @@ def api_key
3132
end
3233

3334
def api_version
34-
2
35+
3
3536
end
3637

3738
def response_class
@@ -42,6 +43,7 @@ def encode(encoder)
4243
encoder.write_int32(@replica_id)
4344
encoder.write_int32(@max_wait_time)
4445
encoder.write_int32(@min_bytes)
46+
encoder.write_int32(@max_bytes)
4547

4648
encoder.write_array(@topics) do |topic, partitions|
4749
encoder.write_string(topic)

spec/broker_spec.rb

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ def send_request(request)
8787
actual_response = broker.fetch_messages(
8888
max_wait_time: 0,
8989
min_bytes: 0,
90+
max_bytes: 10 * 1024,
9091
topics: {}
9192
)
9293

0 commit comments

Comments
 (0)