|
2 | 2 | import collections
|
3 | 3 | import copy
|
4 | 4 | import functools
|
5 |
| -import itertools |
6 | 5 | import logging
|
7 | 6 | import time
|
8 | 7 | import kafka.common
|
|
23 | 22 | class KafkaClient(object):
|
24 | 23 |
|
25 | 24 | CLIENT_ID = b"kafka-python"
|
26 |
| - ID_GEN = itertools.count() |
27 | 25 |
|
28 | 26 | # NOTE: The timeout given to the client should always be greater than the
|
29 | 27 | # one passed to SimpleConsumer.get_message(), otherwise you can get a
|
30 | 28 | # socket timeout.
|
31 | 29 | def __init__(self, hosts, client_id=CLIENT_ID,
|
32 |
| - timeout=DEFAULT_SOCKET_TIMEOUT_SECONDS): |
| 30 | + timeout=DEFAULT_SOCKET_TIMEOUT_SECONDS, |
| 31 | + correlation_id=0): |
33 | 32 | # We need one connection to bootstrap
|
34 | 33 | self.client_id = kafka_bytestring(client_id)
|
35 | 34 | self.timeout = timeout
|
36 | 35 | self.hosts = collect_hosts(hosts)
|
| 36 | + self.correlation_id = correlation_id |
37 | 37 |
|
38 | 38 | # create connections only when we need them
|
39 | 39 | self.conns = {}
|
@@ -98,10 +98,10 @@ def _get_leader_for_partition(self, topic, partition):
|
98 | 98 | return self.brokers[meta.leader]
|
99 | 99 |
|
100 | 100 | def _next_id(self):
|
101 |
| - """ |
102 |
| - Generate a new correlation id |
103 |
| - """ |
104 |
| - return next(KafkaClient.ID_GEN) |
| 101 | + """Generate a new correlation id""" |
| 102 | + # modulo to keep w/i int32 |
| 103 | + self.correlation_id = (self.correlation_id + 1) % 2**31 |
| 104 | + return self.correlation_id |
105 | 105 |
|
106 | 106 | def _send_broker_unaware_request(self, payloads, encoder_fn, decoder_fn):
|
107 | 107 | """
|
|
0 commit comments