Skip to content

Expose selector type as config option #764

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion kafka/client_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class KafkaClient(object):
'ssl_crlfile': None,
'api_version': None,
'api_version_auto_timeout_ms': 2000,
'selector': selectors.DefaultSelector,
}
API_VERSIONS = [
(0, 10),
Expand Down Expand Up @@ -134,6 +135,9 @@ def __init__(self, **configs):
api_version_auto_timeout_ms (int): number of milliseconds to throw a
timeout exception from the constructor when checking the broker
api version. Only applies if api_version is None
selector (selectors.BaseSelector): Provide a specific selector
implementation to use for I/O multiplexing.
Default: selectors.DefaultSelector
"""
self.config = copy.copy(self.DEFAULT_CONFIG)
for key in self.config:
Expand All @@ -149,7 +153,7 @@ def __init__(self, **configs):
self._topics = set() # empty set will fetch all topic metadata
self._metadata_refresh_in_progress = False
self._last_no_node_available_ms = 0
self._selector = selectors.DefaultSelector()
self._selector = self.config['selector']()
self._conns = {}
self._connecting = set()
self._refresh_on_disconnects = True
Expand Down
6 changes: 5 additions & 1 deletion kafka/consumer/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import six

from kafka.client_async import KafkaClient
from kafka.client_async import KafkaClient, selectors
from kafka.consumer.fetcher import Fetcher
from kafka.consumer.subscription_state import SubscriptionState
from kafka.coordinator.consumer import ConsumerCoordinator
Expand Down Expand Up @@ -173,6 +173,9 @@ class KafkaConsumer(six.Iterator):
metrics. Default: 2
metrics_sample_window_ms (int): The maximum age in milliseconds of
samples used to compute metrics. Default: 30000
selector (selectors.BaseSelector): Provide a specific selector
implementation to use for I/O multiplexing.
Default: selectors.DefaultSelector

Note:
Configuration parameters are described in more detail at
Expand Down Expand Up @@ -218,6 +221,7 @@ class KafkaConsumer(six.Iterator):
'metric_reporters': [],
'metrics_num_samples': 2,
'metrics_sample_window_ms': 30000,
'selector': selectors.DefaultSelector,
}

def __init__(self, *topics, **configs):
Expand Down
6 changes: 5 additions & 1 deletion kafka/producer/kafka.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import weakref

from .. import errors as Errors
from ..client_async import KafkaClient
from ..client_async import KafkaClient, selectors
from ..metrics import MetricConfig, Metrics
from ..partitioner.default import DefaultPartitioner
from ..protocol.message import Message, MessageSet
Expand Down Expand Up @@ -228,6 +228,9 @@ class KafkaProducer(object):
metrics. Default: 2
metrics_sample_window_ms (int): The maximum age in milliseconds of
samples used to compute metrics. Default: 30000
selector (selectors.BaseSelector): Provide a specific selector
implementation to use for I/O multiplexing.
Default: selectors.DefaultSelector

Note:
Configuration parameters are described in more detail at
Expand Down Expand Up @@ -267,6 +270,7 @@ class KafkaProducer(object):
'metric_reporters': [],
'metrics_num_samples': 2,
'metrics_sample_window_ms': 30000,
'selector': selectors.DefaultSelector,
}

def __init__(self, **configs):
Expand Down