Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Hackathonxxiii messaging #260

Closed
wants to merge 6 commits into from
Closed
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
40 changes: 40 additions & 0 deletions registrar/apps/core/consumers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""
Defines the Kombu consumer for the registrar project.
"""
from __future__ import absolute_import

from kombu import Exchange, Queue
from kombu.mixins import ConsumerMixin

from registrar.apps.core.models import Program


class ProgramConsumer(ConsumerMixin):

exchange = Exchange('catalog', type='direct')
queues = [
Queue('program_create_queue', exchange, routing_key='catalog.program.create'),
Queue('program_update_queue', exchange, routing_key='catalog.program.update'),
Queue('program_delete_queue', exchange, routing_key='catalog.program.delete'),
]

def __init__(self, connection):
self.connection = connection

def get_consumers(self, Consumer, channel):
return [
Consumer(self.queues, callbacks=[self.on_message], accept=['json']),
]

def on_message(self, body, message):
payload = message.payload
if message.delivery_info['routing_key'] == 'catalog.program.create':
print('CREATED!')
print(payload)
elif message.delivery_info['routing_key'] == 'catalog.program.update':
print('UPDATED!')
print(payload)
elif message.delivery_info['routing_key'] == 'catalog.program.delete':
print('DELETED!')
print(payload)
message.ack()
26 changes: 26 additions & 0 deletions registrar/apps/core/management/commands/run_consumer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
""" Management command to run worker that will act on messages """
import logging

from django.conf import settings
from django.core.management.base import BaseCommand
from kombu import Connection
from kombu.utils.debug import setup_logging

from registrar.apps.core.consumers import ProgramConsumer


logger = logging.getLogger(__name__)


class Command(BaseCommand):
"""
Runs a worker to act on messages received from queue.
"""
def handle(self, *args, **options):
setup_logging(loglevel='DEBUG')

with Connection(settings.BROKER_URL) as conn:
try:
ProgramConsumer(conn).run()
except KeyboardInterrupt:
print('bye bye')
1 change: 1 addition & 0 deletions requirements/base.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ edx-auth-backends
edx-django-release-util
edx-drf-extensions
edx-rest-api-client==1.9.2
kombu<3.1
pytz
redis==2.8
6 changes: 5 additions & 1 deletion requirements/constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@

# These packages are pinned because their next version would require django 2.0.0
django-guardian==2.0.0
django-model-utils<4.0.0
django-model-utils<4.0.0

# Requires Python 3.6+
mock<4
zipp<2
70 changes: 34 additions & 36 deletions requirements/devstack.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ aws-sam-translator==1.20.1 # via cfn-lint
aws-xray-sdk==2.4.3 # via moto
babel==2.8.0 # via sphinx
billiard==3.3.0.23 # via celery
boto3==1.11.6 # via aws-sam-translator, moto
boto3==1.11.15 # via aws-sam-translator, moto
boto==2.49.0 # via moto
botocore==1.14.6 # via aws-xray-sdk, boto3, moto, s3transfer
botocore==1.14.15 # via aws-xray-sdk, boto3, moto, s3transfer
celery==3.1.26.post2
certifi==2019.11.28 # via requests
cffi==1.13.2 # via cryptography
cfn-lint==0.27.1 # via moto
cffi==1.14.0 # via cryptography
cfn-lint==0.27.5 # via moto
chardet==3.0.4 # via requests
click-log==0.3.2 # via edx-lint
click==7.0 # via click-log, code-annotations, edx-lint
Expand All @@ -31,62 +31,61 @@ cryptography==2.8 # via moto
ddt==1.2.2
defusedxml==0.6.0 # via python3-openid, social-auth-core
django-cors-headers==3.2.1
django-debug-toolbar==2.1
django-debug-toolbar==2.2
django-dynamic-fixture==3.0.2
django-extensions==2.2.6
django-extensions==2.2.8
django-guardian==2.0.0
django-model-utils==3.2.0
django-mysql==3.3.0
django-simple-history==2.8.0
django-storages==1.8
django-storages==1.9.1
django-user-tasks==0.3.0
django-waffle==0.19.0
django==1.11.27
django==1.11.28
djangorestframework-jwt==1.11.0 # via edx-drf-extensions
djangorestframework==3.11.0
docker==4.1.0 # via moto
docker==4.2.0 # via moto
docopt==0.6.2 # via pipreqs
docutils==0.15.2 # via botocore, sphinx
ecdsa==0.15 # via python-jose
edx-auth-backends==2.0.2
edx-django-release-util==0.3.3
edx-django-utils==2.0.3 # via edx-drf-extensions
edx-drf-extensions==2.4.5
edx-auth-backends==3.0.2
edx-django-release-util==0.3.6
edx-django-utils==2.0.4 # via edx-drf-extensions
edx-drf-extensions==2.4.6
edx-i18n-tools==0.5.0
edx-lint==1.3.0
edx-opaque-keys==2.0.1 # via edx-drf-extensions
edx-rest-api-client==1.9.2
edx-sphinx-theme==1.5.0
factory-boy==2.12.0
faker==4.0.0
freezegun==0.3.13
freezegun==0.3.14
future==0.18.2 # via aws-xray-sdk, pyjwkest
idna==2.8 # via moto, requests
imagesize==1.2.0 # via sphinx
importlib-metadata==1.4.0 # via jsonschema, path, pluggy, pytest
importlib-metadata==1.5.0 # via jsonschema, path, pluggy, pytest
importlib-resources==1.0.2 # via cfn-lint
isort[requirements]==4.3.21
jinja2==2.10.3 # via code-annotations, moto, sphinx
jinja2==2.11.1 # via code-annotations, moto, sphinx
jmespath==0.9.4 # via boto3, botocore
jsondiff==1.1.2 # via moto
jsonpatch==1.24 # via cfn-lint
jsonpatch==1.25 # via cfn-lint
jsonpickle==1.2 # via aws-xray-sdk
jsonpointer==2.0 # via jsonpatch
jsonschema==3.2.0 # via aws-sam-translator, cfn-lint
kombu==3.0.37 # via celery
kombu==3.0.37
lazy-object-proxy==1.4.3 # via astroid
markupsafe==1.1.1 # via jinja2
mccabe==0.6.1 # via pylint
mock==3.0.5
more-itertools==8.1.0 # via pytest, zipp
more-itertools==8.2.0 # via pytest
moto==1.3.8
mysqlclient==1.3.14
newrelic==5.4.1.134 # via edx-django-utils
newrelic==5.6.0.135 # via edx-django-utils
oauthlib==3.1.0 # via requests-oauthlib, social-auth-core
packaging==20.0 # via pytest
packaging==20.1 # via pytest
path.py==12.4.0 # via edx-i18n-tools
path==13.1.0 # via path.py
pathlib2==2.3.5 # via pytest
pathspec==0.7.0 # via yamllint
pbr==5.4.4 # via stevedore
pip-api==0.0.13 # via isort
Expand All @@ -98,10 +97,9 @@ py==1.8.1 # via pytest
pyasn1==0.4.8 # via python-jose, rsa
pycodestyle==2.5.0
pycparser==2.19 # via cffi
pycryptodomex==3.9.4 # via pyjwkest
pycryptodomex==3.9.6 # via pyjwkest
pygments==2.5.2 # via sphinx
pyinotify==0.9.6
pyjwkest==1.3.2 # via edx-drf-extensions, social-auth-core
pyjwkest==1.3.2 # via edx-drf-extensions
pyjwt==1.7.1 # via djangorestframework-jwt, edx-auth-backends, edx-rest-api-client, social-auth-core
pylint-celery==0.3 # via edx-lint
pylint-django==0.7.2 # via edx-lint
Expand All @@ -112,7 +110,7 @@ pyparsing==2.4.6 # via packaging
pyrsistent==0.15.7 # via jsonschema
pytest-cov==2.8.1
pytest-django==3.8.0
pytest==5.3.4
pytest==5.3.5
python-dateutil==2.8.1 # via analytics-python, botocore, edx-drf-extensions, faker, freezegun, moto, ruamel.yaml.convert
python-jose==3.1.0 # via moto
python-memcached==1.59
Expand All @@ -130,30 +128,30 @@ ruamel.std.argparse==0.8.1 # via ruamel.yaml.cmd
ruamel.yaml.clib==0.2.0 # via ruamel.yaml
ruamel.yaml.cmd==0.5.5
ruamel.yaml.convert==0.3.2 # via ruamel.yaml.cmd
ruamel.yaml==0.16.6 # via ruamel.yaml.cmd, ruamel.yaml.convert
s3transfer==0.3.1 # via boto3
ruamel.yaml==0.16.10 # via ruamel.yaml.cmd, ruamel.yaml.convert
s3transfer==0.3.3 # via boto3
semantic-version==2.8.4 # via edx-drf-extensions
six==1.14.0 # via analytics-python, astroid, aws-sam-translator, cfn-lint, configobj, cryptography, django-dynamic-fixture, django-extensions, django-simple-history, django-waffle, docker, ecdsa, edx-auth-backends, edx-django-release-util, edx-drf-extensions, edx-i18n-tools, edx-lint, edx-opaque-keys, edx-sphinx-theme, freezegun, jsonschema, mock, moto, packaging, pathlib2, pyjwkest, pylint, pyrsistent, python-dateutil, python-jose, python-memcached, responses, social-auth-app-django, social-auth-core, sphinx, stevedore, transifex-client, websocket-client
six==1.14.0 # via analytics-python, astroid, aws-sam-translator, cfn-lint, configobj, cryptography, django-dynamic-fixture, django-extensions, django-simple-history, django-waffle, docker, ecdsa, edx-auth-backends, edx-django-release-util, edx-drf-extensions, edx-i18n-tools, edx-lint, edx-opaque-keys, edx-sphinx-theme, freezegun, jsonschema, mock, moto, packaging, pyjwkest, pylint, pyrsistent, python-dateutil, python-jose, python-memcached, responses, social-auth-app-django, social-auth-core, sphinx, stevedore, transifex-client, websocket-client
slumber==0.7.1 # via edx-rest-api-client
snowballstemmer==2.0.0 # via sphinx
social-auth-app-django==1.2.0 # via edx-auth-backends
social-auth-core[openidconnect]==1.7.0 # via edx-auth-backends, social-auth-app-django
social-auth-app-django==3.1.0 # via edx-auth-backends
social-auth-core==3.2.0 # via edx-auth-backends, social-auth-app-django
sphinx==1.6.7
sphinxcontrib-websupport==1.1.2 # via sphinx
sphinxcontrib-websupport==1.2.0 # via sphinx
sqlparse==0.3.0 # via django-debug-toolbar
stevedore==1.31.0 # via code-annotations, edx-opaque-keys
stevedore==1.32.0 # via code-annotations, edx-opaque-keys
text-unidecode==1.3 # via faker
transifex-client==0.13.7
unidecode==1.1.1 # via python-slugify
urllib3==1.25.7 # via botocore, requests, transifex-client
urllib3==1.25.8 # via botocore, requests, transifex-client
wcwidth==0.1.8 # via pytest
websocket-client==0.57.0 # via docker
werkzeug==0.16.0 # via moto
werkzeug==1.0.0 # via moto
wrapt==1.11.2 # via astroid, aws-xray-sdk
xmltodict==0.12.0 # via moto
yamllint==1.20.0
yarg==0.1.9 # via pipreqs
zipp==1.0.0 # via importlib-metadata
zipp==1.1.0 # via importlib-metadata

# The following packages are considered to be unsafe in a requirements file:
# pip
Expand Down
2 changes: 1 addition & 1 deletion requirements/local.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

django-debug-toolbar
edx-i18n-tools
pyinotify
#pyinotify
ruamel.yaml.cmd
transifex-client
Loading