-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Use non-blocking poll after production; allow flush for testing…
…; deduplicating config; cache producers (#12) I believe a nullary call to poll uses a default timeout of -1 (wait indefinitely), but we really just want to make sure that pending callbacks are triggered for the acks that have been buffered in the background, from previous events. poll(0) will not block if the buffer is empty. For testing we need to call flush(-1), so add sync=True as an option. Documentation for `rd_kafka_poll`: https://github.com/edenhill/librdkafka/blob/4faeb8132521da70b6bcde14423a14eb7ed5c55e/src/rdkafka.h#L3079 This addresses part of #10 Configuration is put in config.py rather than inside the send to event bus function so it can be more widely used, do note that setting names are changed to have the EVENT_BUS_KAFKA prefix for use. Caching implemented on producers so data is not lost (one test breaks as a result).
- Loading branch information
1 parent
a528edd
commit 6deaa64
Showing
6 changed files
with
111 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,7 @@ One Time Setup | |
.. code-block:: | ||
# Clone the repository | ||
git clone [email protected]:edx/event-bus-kafka.git | ||
git clone [email protected]:openedx/event-bus-kafka.git | ||
cd event-bus-kafka | ||
# Set up a virtualenv using virtualenvwrapper with the same name as the repo and activate it | ||
|
@@ -131,26 +131,26 @@ For more information about these options, see the `Getting Help`_ page. | |
.. _community Slack workspace: https://openedx.slack.com/ | ||
.. _Getting Help: https://openedx.org/getting-help | ||
|
||
.. |pypi-badge| image:: https://img.shields.io/pypi/v/event-bus-kafka.svg | ||
:target: https://pypi.python.org/pypi/event-bus-kafka/ | ||
.. |pypi-badge| image:: https://img.shields.io/pypi/v/edx-event-bus-kafka.svg | ||
:target: https://pypi.python.org/pypi/edx-event-bus-kafka/ | ||
:alt: PyPI | ||
|
||
.. |ci-badge| image:: https://github.com/edx/event-bus-kafka/workflows/Python%20CI/badge.svg?branch=main | ||
:target: https://github.com/edx/event-bus-kafka/actions | ||
.. |ci-badge| image:: https://github.com/openedx/event-bus-kafka/workflows/Python%20CI/badge.svg?branch=main | ||
:target: https://github.com/openedx/event-bus-kafka/actions | ||
:alt: CI | ||
|
||
.. |codecov-badge| image:: https://codecov.io/github/edx/event-bus-kafka/coverage.svg?branch=main | ||
:target: https://codecov.io/github/edx/event-bus-kafka?branch=main | ||
.. |codecov-badge| image:: https://codecov.io/github/openedx/event-bus-kafka/coverage.svg?branch=main | ||
:target: https://codecov.io/github/openedx/event-bus-kafka?branch=main | ||
:alt: Codecov | ||
|
||
.. |doc-badge| image:: https://readthedocs.org/projects/event-bus-kafka/badge/?version=latest | ||
:target: https://event-bus-kafka.readthedocs.io/en/latest/ | ||
.. |doc-badge| image:: https://readthedocs.org/projects/edx-event-bus-kafka/badge/?version=latest | ||
:target: https://edx-event-bus-kafka.readthedocs.io/en/latest/ | ||
:alt: Documentation | ||
|
||
.. |pyversions-badge| image:: https://img.shields.io/pypi/pyversions/event-bus-kafka.svg | ||
:target: https://pypi.python.org/pypi/event-bus-kafka/ | ||
.. |pyversions-badge| image:: https://img.shields.io/pypi/pyversions/edx-event-bus-kafka.svg | ||
:target: https://pypi.python.org/pypi/edx-event-bus-kafka/ | ||
:alt: Supported Python versions | ||
|
||
.. |license-badge| image:: https://img.shields.io/github/license/edx/event-bus-kafka.svg | ||
:target: https://github.com/edx/event-bus-kafka/blob/main/LICENSE.txt | ||
.. |license-badge| image:: https://img.shields.io/github/license/openedx/event-bus-kafka.svg | ||
:target: https://github.com/openedx/event-bus-kafka/blob/main/LICENSE.txt | ||
:alt: License |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
Kafka implementation for Open edX event bus. | ||
""" | ||
|
||
__version__ = '0.1.1' | ||
__version__ = '0.3.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
""" | ||
Configuration loading and validation. | ||
""" | ||
|
||
import warnings | ||
from typing import Optional | ||
|
||
from confluent_kafka.schema_registry import SchemaRegistryClient | ||
from django.conf import settings | ||
|
||
|
||
def create_schema_registry_client() -> Optional[SchemaRegistryClient]: | ||
""" | ||
Create a schema registry client from common settings. | ||
""" | ||
url = getattr(settings, 'EVENT_BUS_KAFKA_SCHEMA_REGISTRY_URL', None) | ||
if url is None: | ||
warnings.warn("Cannot configure event-bus-kafka: Missing setting EVENT_BUS_KAFKA_SCHEMA_REGISTRY_URL") | ||
return None | ||
|
||
key = getattr(settings, 'EVENT_BUS_KAFKA_SCHEMA_REGISTRY_API_KEY', '') | ||
secret = getattr(settings, 'EVENT_BUS_KAFKA_SCHEMA_REGISTRY_API_SECRET', '') | ||
|
||
return SchemaRegistryClient({ | ||
'url': url, | ||
'basic.auth.user.info': f"{key}:{secret}", | ||
}) | ||
|
||
|
||
def load_common_settings() -> Optional[dict]: | ||
""" | ||
Load common settings, a base for either producer or consumer configuration. | ||
""" | ||
bootstrap_servers = getattr(settings, 'EVENT_BUS_KAFKA_BOOTSTRAP_SERVERS', None) | ||
if bootstrap_servers is None: | ||
warnings.warn("Cannot configure event-bus-kafka: Missing setting EVENT_BUS_KAFKA_BOOTSTRAP_SERVERS") | ||
return None | ||
|
||
base_settings = { | ||
'bootstrap.servers': bootstrap_servers, | ||
} | ||
|
||
key = getattr(base_settings, 'EVENT_BUS_KAFKA_API_KEY', None) | ||
secret = getattr(base_settings, 'EVENT_BUS_KAFKA_API_SECRET', None) | ||
|
||
if key and secret: | ||
base_settings.update({ | ||
'sasl.mechanism': 'PLAIN', | ||
'security.protocol': 'SASL_SSL', | ||
'sasl.username': key, | ||
'sasl.password': secret, | ||
}) | ||
|
||
return base_settings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters