-
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.
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.
- Loading branch information
1 parent
52f0eb6
commit a8ee8de
Showing
5 changed files
with
74 additions
and
31 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 |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
Kafka implementation for Open edX event bus. | ||
""" | ||
|
||
__version__ = '0.2.0' | ||
__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