Init notifications-consumer repo
Similarly to notifications-routing will consume messages from activemq, so it can follow a similar structure.
Make it configurable to allow multiple types of consumers: push, email, ...
Make on_message call a configurable method. Suggestion use registry pattern with python decorators:
# app/processors/registry.py
class ProcessorRegistry:
registry = {}
@classmethod
def register(cls, processorCls):
cls.registry[processorCls.id()] = processorCls()
return processorCls
# app/processors/processor.py
from abc import ABC, abstractmethod
class Processor(ABC):
def __init__(self):
super().__init__()
@abstractmethod
def process(self):
pass
# app/processors/email/processor.py
@ProcessorRegistry.register
class EmailProcessor(Processor):
__id = "email"
def __init__(self):
super().__init__()
@classmethod
def id(cls):
return cls.__id
def __str__(self):
return self.id()
def process(self):
print(f"I'm the {self} consumer and i'm consuming")
# app/config.py
class Config:
PROCESSOR = "email"
# app/consumer.py
class Consumer:
def on_message():
ProcessorRegistry.registry[Config.PROCESSOR].process()
Consumer.on_message()
> I'm the email consumer and i'm consuming
Don't implement process methods yet, just pass
them.
Make CI build one docker image per consumer, with different names, to allow deploying just one at each time. Suggestion: You can detect if a changed file is in the common code build both, if just changed in the folder /consumers/push just build the push image. Use ENV's to set the correct consumer in the dockerfile.
Repo: https://gitlab.cern.ch/push-notifications/notifications-consumer