Skip to content

Commit

Permalink
Added approximate interface boundary for consumer producer pattern.
Browse files Browse the repository at this point in the history
Concrete implementations can leverage any tool, in this case being queue and pubsub/streams.
  • Loading branch information
codecakes committed Nov 28, 2022
1 parent 71aa2a2 commit 3541dae
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
Empty file added consumer.py
Empty file.
39 changes: 39 additions & 0 deletions interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import abc
from typing import Protocol, Optional, TypeVar


t_consumer_id = TypeVar('consumer_id', bound=str)


class Consumer(Protocol):
"""This class consumes input.
Each consumer entry creates a dedicated channel to consume into.
"""

@abc.abstractmethod
def setup(self, channel: Optional[str] = None, **kwargs) -> t_consumer_id:
"""Setup the consumer."""
raise NotImplementedError

@abc.abstractmethod
def consume(self, data: dict, **optional_attrs) -> None:
"""Consume input."""
raises NotImplementedError


class Producer(Protocol):
"""This class produces output.
Each producer entry publishes from a dedicated channel.
"""

@abc.abstractmethod
def setup(self, consumer_id: t_consumer_id, **kwargs) -> None:
"""Setup the producer."""
raise NotImplementedError

@abc.abstractmethod
def get(self, **optional_attrs) -> None:
"""Returns output."""
raise NotImplementedError

Empty file added producer.py
Empty file.
Empty file added test/__init__.py
Empty file.

0 comments on commit 3541dae

Please sign in to comment.