本文整理汇总了Python中kafka.SimpleClient.send_produce_request方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleClient.send_produce_request方法的具体用法?Python SimpleClient.send_produce_request怎么用?Python SimpleClient.send_produce_request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kafka.SimpleClient
的用法示例。
在下文中一共展示了SimpleClient.send_produce_request方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_send_produce_request_raises_when_noleader
# 需要导入模块: from kafka import SimpleClient [as 别名]
# 或者: from kafka.SimpleClient import send_produce_request [as 别名]
def test_send_produce_request_raises_when_noleader(self, protocol, conn):
mock_conn(conn)
brokers = [
BrokerMetadata(0, 'broker_1', 4567, None),
BrokerMetadata(1, 'broker_2', 5678, None)
]
resp0_brokers = list(map(itemgetter(0, 1, 2), brokers))
topics = [
(NO_ERROR, 'topic_noleader', [
(NO_LEADER, 0, -1, [], []),
(NO_LEADER, 1, -1, [], []),
]),
]
protocol.decode_metadata_response.return_value = MetadataResponse[0](resp0_brokers, topics)
client = SimpleClient(hosts=['broker_1:4567'])
requests = [ProduceRequestPayload(
"topic_noleader", 0,
[create_message("a"), create_message("b")])]
with self.assertRaises(FailedPayloadsError):
client.send_produce_request(requests)
示例2: test_send_produce_request_raises_when_topic_unknown
# 需要导入模块: from kafka import SimpleClient [as 别名]
# 或者: from kafka.SimpleClient import send_produce_request [as 别名]
def test_send_produce_request_raises_when_topic_unknown(self, protocol, conn):
mock_conn(conn)
brokers = [BrokerMetadata(0, "broker_1", 4567, None), BrokerMetadata(1, "broker_2", 5678, None)]
resp0_brokers = list(map(itemgetter(0, 1, 2), brokers))
topics = [(UNKNOWN_TOPIC_OR_PARTITION, "topic_doesnt_exist", [])]
protocol.decode_metadata_response.return_value = MetadataResponse[0](resp0_brokers, topics)
client = SimpleClient(hosts=["broker_1:4567"])
requests = [ProduceRequestPayload("topic_doesnt_exist", 0, [create_message("a"), create_message("b")])]
with self.assertRaises(FailedPayloadsError):
client.send_produce_request(requests)
示例3: test_send_produce_request_raises_when_topic_unknown
# 需要导入模块: from kafka import SimpleClient [as 别名]
# 或者: from kafka.SimpleClient import send_produce_request [as 别名]
def test_send_produce_request_raises_when_topic_unknown(self, protocol, conn):
mock_conn(conn)
brokers = [
BrokerMetadata(0, 'broker_1', 4567),
BrokerMetadata(1, 'broker_2', 5678)
]
topics = [
(UNKNOWN_TOPIC_OR_PARTITION, 'topic_doesnt_exist', []),
]
protocol.decode_metadata_response.return_value = MetadataResponse(brokers, topics)
client = SimpleClient(hosts=['broker_1:4567'])
requests = [ProduceRequestPayload(
"topic_doesnt_exist", 0,
[create_message("a"), create_message("b")])]
with self.assertRaises(UnknownTopicOrPartitionError):
client.send_produce_request(requests)
示例4: test_send_produce_request_raises_when_noleader
# 需要导入模块: from kafka import SimpleClient [as 别名]
# 或者: from kafka.SimpleClient import send_produce_request [as 别名]
def test_send_produce_request_raises_when_noleader(self, protocol, conn):
mock_conn(conn)
brokers = [
BrokerMetadata(0, 'broker_1', 4567),
BrokerMetadata(1, 'broker_2', 5678)
]
topics = [
(NO_ERROR, 'topic_noleader', [
(NO_LEADER, 0, -1, [], []),
(NO_LEADER, 1, -1, [], []),
]),
]
protocol.decode_metadata_response.return_value = MetadataResponse(brokers, topics)
client = SimpleClient(hosts=['broker_1:4567'])
requests = [ProduceRequestPayload(
"topic_noleader", 0,
[create_message("a"), create_message("b")])]
with self.assertRaises(LeaderNotAvailableError):
client.send_produce_request(requests)