summaryrefslogtreecommitdiff
path: root/kafka/common.py
diff options
context:
space:
mode:
authorDavid Arthur <mumrah@gmail.com>2013-03-30 00:28:00 -0400
committerDavid Arthur <mumrah@gmail.com>2013-04-02 20:19:30 -0400
commitb6d98c07b418b16061ae92392947d5dd6958a708 (patch)
treee777fcf3019ef0ddc6c278ef733c487f5b0532c3 /kafka/common.py
parent3499e2f6ead76e1c2db6ac754358bd57f9a15268 (diff)
downloadkafka-python-b6d98c07b418b16061ae92392947d5dd6958a708.tar.gz
Big code re-org
Diffstat (limited to 'kafka/common.py')
-rw-r--r--kafka/common.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/kafka/common.py b/kafka/common.py
new file mode 100644
index 0000000..447684f
--- /dev/null
+++ b/kafka/common.py
@@ -0,0 +1,43 @@
+from collections import namedtuple
+
+###############
+# Structs #
+###############
+
+# Request payloads
+ProduceRequest = namedtuple("ProduceRequest", ["topic", "partition", "messages"])
+FetchRequest = namedtuple("FetchRequest", ["topic", "partition", "offset", "max_bytes"])
+OffsetRequest = namedtuple("OffsetRequest", ["topic", "partition", "time", "max_offsets"])
+OffsetCommitRequest = namedtuple("OffsetCommitRequest", ["topic", "partition", "offset", "metadata"])
+OffsetFetchRequest = namedtuple("OffsetFetchRequest", ["topic", "partition"])
+
+# Response payloads
+ProduceResponse = namedtuple("ProduceResponse", ["topic", "partition", "error", "offset"])
+FetchResponse = namedtuple("FetchResponse", ["topic", "partition", "error", "highwaterMark", "messages"])
+OffsetResponse = namedtuple("OffsetResponse", ["topic", "partition", "error", "offsets"])
+OffsetCommitResponse = namedtuple("OffsetCommitResponse", ["topic", "partition", "error"])
+OffsetFetchResponse = namedtuple("OffsetFetchResponse", ["topic", "partition", "offset", "metadata", "error"])
+BrokerMetadata = namedtuple("BrokerMetadata", ["nodeId", "host", "port"])
+PartitionMetadata = namedtuple("PartitionMetadata", ["topic", "partition", "leader", "replicas", "isr"])
+
+# Other useful structs
+OffsetAndMessage = namedtuple("OffsetAndMessage", ["offset", "message"])
+Message = namedtuple("Message", ["magic", "attributes", "key", "value"])
+TopicAndPartition = namedtuple("TopicAndPartition", ["topic", "partition"])
+
+class ErrorMapping(object):
+ # Many of these are not actually used by the client
+ UNKNOWN = -1
+ NO_ERROR = 0
+ OFFSET_OUT_OF_RANGE = 1
+ INVALID_MESSAGE = 2
+ UNKNOWN_TOPIC_OR_PARTITON = 3
+ INVALID_FETCH_SIZE = 4
+ LEADER_NOT_AVAILABLE = 5
+ NOT_LEADER_FOR_PARTITION = 6
+ REQUEST_TIMED_OUT = 7
+ BROKER_NOT_AVAILABLE = 8
+ REPLICA_NOT_AVAILABLE = 9
+ MESSAGE_SIZE_TO_LARGE = 10
+ STALE_CONTROLLER_EPOCH = 11
+ OFFSET_METADATA_TOO_LARGE = 12