本文整理汇总了Python中aiokafka.client.AIOKafkaClient.check_version方法的典型用法代码示例。如果您正苦于以下问题:Python AIOKafkaClient.check_version方法的具体用法?Python AIOKafkaClient.check_version怎么用?Python AIOKafkaClient.check_version使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aiokafka.client.AIOKafkaClient
的用法示例。
在下文中一共展示了AIOKafkaClient.check_version方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_check_version
# 需要导入模块: from aiokafka.client import AIOKafkaClient [as 别名]
# 或者: from aiokafka.client.AIOKafkaClient import check_version [as 别名]
def test_check_version(self):
client = AIOKafkaClient(loop=self.loop, bootstrap_servers=self.hosts)
yield from client.bootstrap()
ver = yield from client.check_version()
self.assertTrue('0.' in ver)
yield from self.wait_topic(client, 'some_test_topic')
ver2 = yield from client.check_version()
self.assertEqual(ver, ver2)
ver2 = yield from client.check_version(client.get_random_node())
self.assertEqual(ver, ver2)
with mock.patch.object(
AIOKafkaConnection, 'send') as mocked:
mocked.side_effect = KafkaError('mocked exception')
with self.assertRaises(UnrecognizedBrokerVersion):
yield from client.check_version(client.get_random_node())
client._get_conn = asyncio.coroutine(lambda _: None)
with self.assertRaises(ConnectionError):
yield from client.check_version()
示例2: test_check_version
# 需要导入模块: from aiokafka.client import AIOKafkaClient [as 别名]
# 或者: from aiokafka.client.AIOKafkaClient import check_version [as 别名]
def test_check_version(self):
kafka_version = tuple(int(x) for x in self.kafka_version.split("."))
client = AIOKafkaClient(loop=self.loop, bootstrap_servers=self.hosts)
yield from client.bootstrap()
ver = yield from client.check_version()
self.assertEqual(kafka_version[:2], ver[:2])
yield from self.wait_topic(client, 'some_test_topic')
ver2 = yield from client.check_version()
self.assertEqual(ver, ver2)
ver2 = yield from client.check_version(client.get_random_node())
self.assertEqual(ver, ver2)
with mock.patch.object(
AIOKafkaConnection, 'send') as mocked:
mocked.side_effect = KafkaError('mocked exception')
with self.assertRaises(UnrecognizedBrokerVersion):
yield from client.check_version(client.get_random_node())
client._get_conn = asyncio.coroutine(lambda _, **kw: None)
with self.assertRaises(ConnectionError):
yield from client.check_version()
yield from client.close()
示例3: AIOKafkaConsumer
# 需要导入模块: from aiokafka.client import AIOKafkaClient [as 别名]
# 或者: from aiokafka.client.AIOKafkaClient import check_version [as 别名]
#.........这里部分代码省略.........
request_timeout_ms=request_timeout_ms)
self._api_version = api_version
self._group_id = group_id
self._heartbeat_interval_ms = heartbeat_interval_ms
self._retry_backoff_ms = retry_backoff_ms
self._enable_auto_commit = enable_auto_commit
self._auto_commit_interval_ms = auto_commit_interval_ms
self._partition_assignment_strategy = partition_assignment_strategy
self._key_deserializer = key_deserializer
self._value_deserializer = value_deserializer
self._fetch_min_bytes = fetch_min_bytes
self._fetch_max_wait_ms = fetch_max_wait_ms
self._max_partition_fetch_bytes = max_partition_fetch_bytes
self._consumer_timeout = consumer_timeout_ms / 1000
self._check_crcs = check_crcs
self._subscription = SubscriptionState(auto_offset_reset)
self._fetcher = None
self._coordinator = None
self._closed = False
self._loop = loop
self._topics = topics
if topics:
self._client.set_topics(topics)
self._subscription.subscribe(topics=topics)
@asyncio.coroutine
def start(self):
yield from self._client.bootstrap()
# Check Broker Version if not set explicitly
if self._api_version == 'auto':
self._api_version = yield from self._client.check_version()
# Convert api_version config to tuple for easy comparisons
self._api_version = tuple(
map(int, self._api_version.split('.')))
if self._api_version < (0, 9):
raise ValueError(
"Unsupported Kafka version: {}".format(self._api_version))
self._fetcher = Fetcher(
self._client, self._subscription, loop=self._loop,
key_deserializer=self._key_deserializer,
value_deserializer=self._value_deserializer,
fetch_min_bytes=self._fetch_min_bytes,
fetch_max_wait_ms=self._fetch_max_wait_ms,
max_partition_fetch_bytes=self._max_partition_fetch_bytes,
check_crcs=self._check_crcs,
fetcher_timeout=self._consumer_timeout)
if self._group_id is not None:
# using group coordinator for automatic partitions assignment
self._coordinator = GroupCoordinator(
self._client, self._subscription, loop=self._loop,
group_id=self._group_id,
heartbeat_interval_ms=self._heartbeat_interval_ms,
retry_backoff_ms=self._retry_backoff_ms,
enable_auto_commit=self._enable_auto_commit,
auto_commit_interval_ms=self._auto_commit_interval_ms,
assignors=self._partition_assignment_strategy)
self._coordinator.on_group_rebalanced(
self._on_change_subscription)
yield from self._coordinator.ensure_active_group()
示例4: AIOKafkaProducer
# 需要导入模块: from aiokafka.client import AIOKafkaClient [as 别名]
# 或者: from aiokafka.client.AIOKafkaClient import check_version [as 别名]
#.........这里部分代码省略.........
acks = -1
self._acks = acks
self._api_version = api_version
self._key_serializer = key_serializer
self._value_serializer = value_serializer
self._compression_type = compression_type
self._partitioner = partitioner
self._max_request_size = max_request_size
self._request_timeout_ms = request_timeout_ms
self.client = AIOKafkaClient(
loop=loop, bootstrap_servers=bootstrap_servers,
client_id=client_id, metadata_max_age_ms=metadata_max_age_ms,
request_timeout_ms=request_timeout_ms)
self._metadata = self.client.cluster
self._message_accumulator = MessageAccumulator(
self._metadata, max_batch_size, self._compression_type,
self._request_timeout_ms/1000, loop)
self._sender_task = None
self._in_flight = set()
self._closed = False
self._loop = loop
self._retry_backoff = retry_backoff_ms / 1000
self._linger_time = linger_ms / 1000
@asyncio.coroutine
def start(self):
"""Connect to Kafka cluster and check server version"""
log.debug("Starting the Kafka producer") # trace
yield from self.client.bootstrap()
# Check Broker Version if not set explicitly
if self._api_version == 'auto':
self._api_version = yield from self.client.check_version()
# Convert api_version config to tuple for easy comparisons
self._api_version = tuple(
map(int, self._api_version.split('.')))
if self._compression_type == 'lz4':
assert self._api_version >= (0, 8, 2), \
'LZ4 Requires >= Kafka 0.8.2 Brokers'
self._sender_task = ensure_future(
self._sender_routine(), loop=self._loop)
log.debug("Kafka producer started")
@asyncio.coroutine
def stop(self):
"""Flush all pending data and close all connections to kafka cluser"""
if self._closed:
return
# Wait untill all batches are Delivered and futures resolved
yield from self._message_accumulator.close()
if self._sender_task:
self._sender_task.cancel()
yield from self._sender_task
yield from self.client.close()
self._closed = True
log.debug("The Kafka producer has closed.")
@asyncio.coroutine
def partitions_for(self, topic):