Skip to content

Commit 8a2c91e

Browse files
committed
Use api_version() to select MetadataRequest from client
1 parent 1487df2 commit 8a2c91e

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

kafka/client_async.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -868,9 +868,9 @@ def _maybe_refresh_metadata(self, wakeup=False):
868868
if not topics and self.cluster.is_bootstrap(node_id):
869869
topics = list(self.config['bootstrap_topics_filter'])
870870

871+
api_version = self.api_version(MetadataRequest, max_version=1)
871872
if self.cluster.need_all_topic_metadata or not topics:
872-
topics = [] if self.config['api_version'] < (0, 10, 0) else None
873-
api_version = 0 if self.config['api_version'] < (0, 10, 0) else 1
873+
topics = MetadataRequest[api_version].ALL_TOPICS
874874
request = MetadataRequest[api_version](topics)
875875
log.debug("Sending metadata request %s to node %s", request, node_id)
876876
future = self.send(node_id, request, wakeup=wakeup)

kafka/protocol/metadata.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -135,34 +135,34 @@ class MetadataRequest_v0(Request):
135135
SCHEMA = Schema(
136136
('topics', Array(String('utf-8')))
137137
)
138-
ALL_TOPICS = None # Empty Array (len 0) for topics returns all topics
138+
ALL_TOPICS = [] # Empty Array (len 0) for topics returns all topics
139139

140140

141141
class MetadataRequest_v1(Request):
142142
API_KEY = 3
143143
API_VERSION = 1
144144
RESPONSE_TYPE = MetadataResponse_v1
145145
SCHEMA = MetadataRequest_v0.SCHEMA
146-
ALL_TOPICS = -1 # Null Array (len -1) for topics returns all topics
147-
NO_TOPICS = None # Empty array (len 0) for topics returns no topics
146+
ALL_TOPICS = None # Null Array (len -1) for topics returns all topics
147+
NO_TOPICS = [] # Empty array (len 0) for topics returns no topics
148148

149149

150150
class MetadataRequest_v2(Request):
151151
API_KEY = 3
152152
API_VERSION = 2
153153
RESPONSE_TYPE = MetadataResponse_v2
154154
SCHEMA = MetadataRequest_v1.SCHEMA
155-
ALL_TOPICS = -1 # Null Array (len -1) for topics returns all topics
156-
NO_TOPICS = None # Empty array (len 0) for topics returns no topics
155+
ALL_TOPICS = None
156+
NO_TOPICS = []
157157

158158

159159
class MetadataRequest_v3(Request):
160160
API_KEY = 3
161161
API_VERSION = 3
162162
RESPONSE_TYPE = MetadataResponse_v3
163163
SCHEMA = MetadataRequest_v1.SCHEMA
164-
ALL_TOPICS = -1 # Null Array (len -1) for topics returns all topics
165-
NO_TOPICS = None # Empty array (len 0) for topics returns no topics
164+
ALL_TOPICS = None
165+
NO_TOPICS = []
166166

167167

168168
class MetadataRequest_v4(Request):
@@ -173,8 +173,8 @@ class MetadataRequest_v4(Request):
173173
('topics', Array(String('utf-8'))),
174174
('allow_auto_topic_creation', Boolean)
175175
)
176-
ALL_TOPICS = -1 # Null Array (len -1) for topics returns all topics
177-
NO_TOPICS = None # Empty array (len 0) for topics returns no topics
176+
ALL_TOPICS = None
177+
NO_TOPICS = []
178178

179179

180180
class MetadataRequest_v5(Request):
@@ -186,8 +186,8 @@ class MetadataRequest_v5(Request):
186186
API_VERSION = 5
187187
RESPONSE_TYPE = MetadataResponse_v5
188188
SCHEMA = MetadataRequest_v4.SCHEMA
189-
ALL_TOPICS = -1 # Null Array (len -1) for topics returns all topics
190-
NO_TOPICS = None # Empty array (len 0) for topics returns no topics
189+
ALL_TOPICS = None
190+
NO_TOPICS = []
191191

192192

193193
MetadataRequest = [

0 commit comments

Comments
 (0)