-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added approximate interface boundary for consumer producer pattern.
Concrete implementations can leverage any tool, in this case being queue and pubsub/streams.
- Loading branch information
Showing
4 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
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,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.
Empty file.