Reusable TOMToolkit app for listening to kafka streams.
Project description
tom-alertstreams
tom-alertstreams
is a reusable TOM Toolkit app for listening to kafka streams.
tom-alertstreams
provides a management command, readstreams
. There are no urlpatterns
,
no Views, and no templates. The readstreams
management command reads the settings.py
ALERT_STREAMS
configuration and starts listening to each configured Kafka stream. It is not expected
to return, and is intended to run along side your TOM's server component. The ALERT_STREAMS
configuration (see below) tells readstreams
what streams to access, what topics to listen to,
and what to do with messages that arrive on a given topic.
Installation
-
Install the package into your TOM environment:
pip install tom-alertstreams
-
In your project
settings.py
, addtom_alertstreams
to yourINSTALLED_APPS
setting:INSTALLED_APPS = [ ... 'tom_alertstreams', ]
At this point you can verify the installation by running ./manage.py
to list the available
management commands and see
[tom_alertstreams]
readstreams
in the output.
Configuration
Each Kafka stream that your TOM listens to (via readstreams
) will have a configuration dictionary
in your settings.py
ALERT_STREAMS
. ALERT_STREAMS
is a list of configuration dictionaries, one
dictionary for each Kafka stream. Here's an example ALERT_STREAMS
configuration for two Kafka streams:
SCiMMA Hopskotch and
GCN Classic over Kafka.
ALERT_STREAMS = [
{
'ACTIVE': True,
'NAME': 'tom_alertstreams.alertstreams.hopskotch.HopskotchAlertStream',
'OPTIONS': {
'URL': 'kafka://kafka.scimma.org/',
'USERNAME': os.getenv('SCIMMA_AUTH_USERNAME', None),
'PASSWORD': os.getenv('SCIMMA_AUTH_PASSWORD', None),
'TOPIC_HANDLER': {
'sys.heartbeat': (lambda x: print(x)),
'tomtoolkit.test': (lambda x: print(x)),
'hermes.test': (lambda x: print(x)),
},
},
},
{
'ACTIVE': True,
'NAME': 'tom_alertstreams.alertstreams.gcn.GCNClassicAlertStream',
# The keys of the OPTIONS dictionary become (lower-case) properties of the AlertStream instance.
'OPTIONS': {
# see https://github.com/nasa-gcn/gcn-kafka-python#to-use for configuration details.
'GCN_CLASSIC_CLIENT_ID': os.getenv('GCN_CLASSIC_CLIENT_ID', None),
'GCN_CLASSIC_CLIENT_SECRET': os.getenv('GCN_CLASSIC_CLIENT_SECRET', None),
'DOMAIN': 'gcn.nasa.gov', # optional, defaults to 'gcn.nasa.gov'
'CONFIG': { # optional
# 'group.id': 'tom_alertstreams - llindstrom@lco.global',
# 'auto.offset.reset': 'earliest',
# 'enable.auto.commit': False
},
'TOPIC_HANDLER': {
'gcn.classic.text.LVC_INITIAL': (lambda x: print(x)),
'gcn.classic.text.LVC_PRELIMINARY': (lambda x: print(x)),
'gcn.classic.text.LVC_RETRACTION': (lambda x: print(x)),
},
},
}
]
The configuration dictionary for each AlertStream
subclass will contain these key-value pairs:
ACTIVE
: Boolean which tellsreadstreams
to access this stream. Should beTrue
, unless you want to keep a configuration dictionary, but ignore the stream.NAME
: The name of theAlertStream
subclass that implements the interface to this Kafka stream.tom_alertstreams
will provideAlertStream
subclasses for major astromical Kafka streams. See below for instructions on Subclassing theAlertStream
base class.OPTIONS
: A dictionary of key-value pairs specific to theAlertStream
subclass given byNAME
. The doc string forAlertStream
subclass should document what is expected. Typically, a URL, authentication information, and a dictionary,TOPIC_HANDLER
, will be required. See "SubclassingAlertStream
" below.
Alert Handling
documentation coming.
Subclassing AlertStream
documentation coming.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file tom_alertstreams-0.3.0.tar.gz
.
File metadata
- Download URL: tom_alertstreams-0.3.0.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.9.9 Linux/3.10.0-1160.49.1.el7.x86_64
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a371a42fdbec0d7fe87f897b33a47319b1f5f9adaf113faa14e92166150e217c |
|
MD5 | 95ccb848c73cfc629dd36564b6394ee1 |
|
BLAKE2b-256 | f379cdbd2a67e93597e1da4c3c3ec2179716237ba2a506f9b9c84b6d56c41a49 |
Provenance
File details
Details for the file tom_alertstreams-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: tom_alertstreams-0.3.0-py3-none-any.whl
- Upload date:
- Size: 10.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.9.9 Linux/3.10.0-1160.49.1.el7.x86_64
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01cd87b6ef3c6444ca52f3f8ce5f42af5aad80c35122ce6aa9a966d05fbb1440 |
|
MD5 | 1e319a7d993e64560f3e53e5fb32a4dd |
|
BLAKE2b-256 | 020bde8740d00769e7f0fe1578f9099d0401f7e974fabc9c1a6dfd40e9632c8a |