-
Notifications
You must be signed in to change notification settings - Fork 0
/
interface.py
37 lines (27 loc) · 989 Bytes
/
interface.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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."""
raise 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