本文整理匯總了Python中afkak.kafkacodec.KafkaCodec.encode_offset_commit_request方法的典型用法代碼示例。如果您正苦於以下問題:Python KafkaCodec.encode_offset_commit_request方法的具體用法?Python KafkaCodec.encode_offset_commit_request怎麽用?Python KafkaCodec.encode_offset_commit_request使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類afkak.kafkacodec.KafkaCodec
的用法示例。
在下文中一共展示了KafkaCodec.encode_offset_commit_request方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_encode_offset_commit_request
# 需要導入模塊: from afkak.kafkacodec import KafkaCodec [as 別名]
# 或者: from afkak.kafkacodec.KafkaCodec import encode_offset_commit_request [as 別名]
def test_encode_offset_commit_request(self):
header = b"".join([
struct.pack('>h', 8), # Message type = offset commit
struct.pack('>h', 1), # API version
struct.pack('>i', 42), # Correlation ID
struct.pack('>h9s', 9, b"client_id"), # The client ID
struct.pack('>h8s', 8, b"group_id"), # The group to commit for
struct.pack('>i', 996), # Group generation ID
struct.pack('>h11s', 11, b'consumer_id'), # Consumer ID
struct.pack('>i', 2), # Num topics
])
topic1 = b"".join([
struct.pack(">h6s", 6, b"topic1"), # Topic for the request
struct.pack(">i", 2), # Two partitions
struct.pack(">i", 0), # Partition 0
struct.pack(">q", 123), # Offset 123
struct.pack(">q", 1437585816816), # Timestamp in ms > epoch
struct.pack(">h", -1), # Null metadata
struct.pack(">i", 1), # Partition 1
struct.pack(">q", 234), # Offset 234
struct.pack(">q", 1436981054199), # Timestamp in ms > epoch
struct.pack(">h11s", 11, b'My_Metadata'), # Null metadata
])
topic2 = b"".join([
struct.pack(">h6s", 6, b"topic2"), # Topic for the request
struct.pack(">i", 1), # One partition
struct.pack(">i", 2), # Partition 2
struct.pack(">q", 345), # Offset 345
struct.pack(">q", -1), # Timestamp 'invalid-time'
struct.pack(">h", -1), # Null metadata
])
# A dict is used, so we can't predict the order of the topics...
expected1 = b"".join([header, topic1, topic2])
expected2 = b"".join([header, topic2, topic1])
encoded = KafkaCodec.encode_offset_commit_request(
b"client_id", 42, u"group_id", 996, u'consumer_id', [
OffsetCommitRequest("topic1", 0, 123, 1437585816816, None),
OffsetCommitRequest(u"topic1", 1, 234, 1436981054199,
b'My_Metadata'),
OffsetCommitRequest(u"topic2", 2, 345, -1, None),
])
self.assertIn(encoded, [expected1, expected2])