DefStream 0.1.19__79-py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- DefStream/Broker/Configuration.py +17 -0
- DefStream/Broker/Connection.py +141 -0
- DefStream/Broker/Consumer.py +59 -0
- DefStream/Broker/Errors.py +14 -0
- DefStream/Broker/Event.py +35 -0
- DefStream/Broker/Implements/RabbitMQ/Configuration.py +49 -0
- DefStream/Broker/Implements/RabbitMQ/Connection.py +547 -0
- DefStream/Broker/Implements/RabbitMQ/Consumer.py +360 -0
- DefStream/Broker/Implements/RabbitMQ/Event.py +146 -0
- DefStream/Broker/Implements/RabbitMQ/Exchange.py +277 -0
- DefStream/Broker/Implements/RabbitMQ/Queue.py +321 -0
- DefStream/Broker/Implements/RabbitMQ/Serializer.py +75 -0
- DefStream/Broker/Implements/RabbitMQ/Stream.py +181 -0
- DefStream/Broker/Implements/RabbitMQ/Subscription.py +74 -0
- DefStream/Broker/Implements/RabbitMQ/__init__.py +45 -0
- DefStream/Broker/Implements/Redis/Configuration.py +59 -0
- DefStream/Broker/Implements/Redis/Connection.py +265 -0
- DefStream/Broker/Implements/Redis/Consumer.py +368 -0
- DefStream/Broker/Implements/Redis/Event.py +212 -0
- DefStream/Broker/Implements/Redis/Queue.py +284 -0
- DefStream/Broker/Implements/Redis/Serializer.py +48 -0
- DefStream/Broker/Implements/Redis/Subscription.py +46 -0
- DefStream/Broker/Implements/Redis/__init__.py +29 -0
- DefStream/Broker/Implements/__init__.py +1 -0
- DefStream/Broker/Priority.py +26 -0
- DefStream/Broker/Protocol.py +45 -0
- DefStream/Broker/__init__.py +53 -0
- DefStream/Descriptor/DataObject.py +409 -0
- DefStream/Descriptor/Types.py +248 -0
- DefStream/Descriptor/Value.py +188 -0
- DefStream/Descriptor/__init__.py +172 -0
- DefStream/Inspector/Extension.py +69 -0
- DefStream/Inspector/Extensions/Metrics.py +316 -0
- DefStream/Inspector/Extensions/Ping.py +107 -0
- DefStream/Inspector/Extensions/Play.html +373 -0
- DefStream/Inspector/Extensions/Play.py +415 -0
- DefStream/Inspector/Extensions/Specifications.py +176 -0
- DefStream/Inspector/Extensions/Status.html +206 -0
- DefStream/Inspector/Extensions/Status.py +124 -0
- DefStream/Inspector/Extensions/__init__.py +13 -0
- DefStream/Inspector/Inspector.py +354 -0
- DefStream/Inspector/Response.py +14 -0
- DefStream/Inspector/__init__.py +9 -0
- DefStream/Validator/Pattern.py +36 -0
- DefStream/Validator/Patterns/Array.py +30 -0
- DefStream/Validator/Patterns/Common.py +92 -0
- DefStream/Validator/Patterns/Compare.py +180 -0
- DefStream/Validator/Patterns/Condition.py +60 -0
- DefStream/Validator/Patterns/DataObject.py +93 -0
- DefStream/Validator/Patterns/DateTime.py +111 -0
- DefStream/Validator/Patterns/Number.py +43 -0
- DefStream/Validator/Patterns/Object.py +158 -0
- DefStream/Validator/Patterns/Size.py +110 -0
- DefStream/Validator/Patterns/String.py +92 -0
- DefStream/Validator/Patterns/Type.py +355 -0
- DefStream/Validator/Patterns/__init__.py +137 -0
- DefStream/Validator/Validate.py +29 -0
- DefStream/Validator/Validator.py +30 -0
- DefStream/Validator/__init__.py +11 -0
- DefStream/Worker/Executor.py +371 -0
- DefStream/Worker/Message.py +180 -0
- DefStream/Worker/Pool.py +245 -0
- DefStream/Worker/Run.py +357 -0
- DefStream/Worker/Specification.py +87 -0
- DefStream/Worker/Startup.py +174 -0
- DefStream/Worker/Worker.py +421 -0
- DefStream/Worker/__init__.py +47 -0
- DefStream/__init__.py +0 -0
- defstream-0.1.19.dist-info/METADATA +92 -0
- defstream-0.1.19.dist-info/RECORD +73 -0
- defstream-0.1.19.dist-info/WHEEL +6 -0
- defstream-0.1.19.dist-info/licenses/LICENSE +674 -0
- defstream-0.1.19.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
from abc import (
|
|
4
|
+
ABCMeta,
|
|
5
|
+
abstractmethod,
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
__all__ = (
|
|
9
|
+
'Configuration',
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Configuration(metaclass=ABCMeta):
|
|
14
|
+
"""Configuration Interface for Event Broker"""
|
|
15
|
+
@abstractmethod
|
|
16
|
+
def __init__(self, *args, **kwargs):
|
|
17
|
+
raise NotImplementedError('{} must be implemented __init__'.format(self.__class__.__name__))
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
from abc import abstractmethod
|
|
4
|
+
from typing import (
|
|
5
|
+
Any,
|
|
6
|
+
Optional,
|
|
7
|
+
Protocol,
|
|
8
|
+
runtime_checkable,
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
from .Consumer import Consumer
|
|
12
|
+
from .Event import EventHandler
|
|
13
|
+
from .Protocol import Sendable
|
|
14
|
+
|
|
15
|
+
__all__ = (
|
|
16
|
+
'Connection',
|
|
17
|
+
'BrokerFactory',
|
|
18
|
+
'GetExchange',
|
|
19
|
+
'GetQueue',
|
|
20
|
+
'GetStream',
|
|
21
|
+
'GetConsumer',
|
|
22
|
+
'Declarable',
|
|
23
|
+
'Emittable',
|
|
24
|
+
'Requestable',
|
|
25
|
+
'PrioritySupport',
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class Connection(Protocol):
|
|
30
|
+
@abstractmethod
|
|
31
|
+
def connect(self) -> None: ...
|
|
32
|
+
|
|
33
|
+
@abstractmethod
|
|
34
|
+
def close(self) -> None: ...
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class BrokerFactory(Protocol):
|
|
38
|
+
"""호출마다 독립적인 새 브로커 연결을 반환하는 팩터리 계약."""
|
|
39
|
+
|
|
40
|
+
@abstractmethod
|
|
41
|
+
def __call__(self) -> Connection: ...
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@runtime_checkable
|
|
45
|
+
class GetExchange(Protocol):
|
|
46
|
+
@abstractmethod
|
|
47
|
+
def exchange(
|
|
48
|
+
self,
|
|
49
|
+
name: str,
|
|
50
|
+
/,
|
|
51
|
+
) -> Sendable: ...
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@runtime_checkable
|
|
55
|
+
class GetQueue(Protocol):
|
|
56
|
+
@abstractmethod
|
|
57
|
+
def queue(
|
|
58
|
+
self,
|
|
59
|
+
name: str,
|
|
60
|
+
/,
|
|
61
|
+
) -> Sendable: ...
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
@runtime_checkable
|
|
65
|
+
class GetStream(Protocol):
|
|
66
|
+
@abstractmethod
|
|
67
|
+
def stream(
|
|
68
|
+
self,
|
|
69
|
+
name: str,
|
|
70
|
+
/,
|
|
71
|
+
) -> Sendable: ...
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
@runtime_checkable
|
|
75
|
+
class GetConsumer(Protocol):
|
|
76
|
+
@abstractmethod
|
|
77
|
+
def consumer(
|
|
78
|
+
self,
|
|
79
|
+
handler: Optional[EventHandler] = None,
|
|
80
|
+
) -> Consumer: ...
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
@runtime_checkable
|
|
84
|
+
class Declarable(Protocol):
|
|
85
|
+
@abstractmethod
|
|
86
|
+
def declare(
|
|
87
|
+
self,
|
|
88
|
+
parameters: Any,
|
|
89
|
+
) -> None: ...
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
@runtime_checkable
|
|
93
|
+
class Emittable(Protocol):
|
|
94
|
+
@abstractmethod
|
|
95
|
+
def emit(
|
|
96
|
+
self,
|
|
97
|
+
body: Any,
|
|
98
|
+
parameters: Any,
|
|
99
|
+
) -> Any: ...
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
@runtime_checkable
|
|
103
|
+
class Requestable(Protocol):
|
|
104
|
+
@abstractmethod
|
|
105
|
+
def request(
|
|
106
|
+
self,
|
|
107
|
+
body: Any,
|
|
108
|
+
parameters: Any,
|
|
109
|
+
timeout: float = 5,
|
|
110
|
+
) -> Any: ...
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
@runtime_checkable
|
|
114
|
+
class PrioritySupport(
|
|
115
|
+
Emittable,
|
|
116
|
+
Requestable,
|
|
117
|
+
Protocol,
|
|
118
|
+
):
|
|
119
|
+
"""작업 구독 설정의 우선순위 처리와 우선순위 발행을 지원하는 계약."""
|
|
120
|
+
|
|
121
|
+
def priority_parameters(
|
|
122
|
+
self,
|
|
123
|
+
parameters: Any,
|
|
124
|
+
) -> Any: ...
|
|
125
|
+
|
|
126
|
+
def emit(
|
|
127
|
+
self,
|
|
128
|
+
body: Any,
|
|
129
|
+
parameters: Any,
|
|
130
|
+
*,
|
|
131
|
+
priority: Optional[int] = None,
|
|
132
|
+
) -> Any: ...
|
|
133
|
+
|
|
134
|
+
def request(
|
|
135
|
+
self,
|
|
136
|
+
body: Any,
|
|
137
|
+
parameters: Any,
|
|
138
|
+
timeout: float = 5,
|
|
139
|
+
*,
|
|
140
|
+
priority: Optional[int] = None,
|
|
141
|
+
) -> Any: ...
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
from abc import (
|
|
4
|
+
ABCMeta,
|
|
5
|
+
abstractmethod,
|
|
6
|
+
)
|
|
7
|
+
from typing import (
|
|
8
|
+
Any,
|
|
9
|
+
Callable,
|
|
10
|
+
Optional,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
from .Event import (
|
|
14
|
+
Event,
|
|
15
|
+
EventHandler,
|
|
16
|
+
EventErrorPolicy,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
__all__ = (
|
|
20
|
+
'Consumer',
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class Consumer(metaclass=ABCMeta):
|
|
25
|
+
"""Consumer Interface of Event Broker"""
|
|
26
|
+
def complete(
|
|
27
|
+
self,
|
|
28
|
+
event: Event,
|
|
29
|
+
result: Any,
|
|
30
|
+
) -> None:
|
|
31
|
+
event.ack()
|
|
32
|
+
|
|
33
|
+
def call(self, callback: Callable[[], None]) -> None:
|
|
34
|
+
"""Schedule a callback on the connection owner thread."""
|
|
35
|
+
raise NotImplementedError('Consumer must implement thread-safe callback scheduling')
|
|
36
|
+
|
|
37
|
+
def fail(
|
|
38
|
+
self,
|
|
39
|
+
event: Event,
|
|
40
|
+
policy: Optional[EventErrorPolicy] = None,
|
|
41
|
+
) -> None:
|
|
42
|
+
raise NotImplementedError('Consumer must implement failure policies')
|
|
43
|
+
|
|
44
|
+
def close(self) -> None:
|
|
45
|
+
raise NotImplementedError('Consumer must implement close')
|
|
46
|
+
|
|
47
|
+
@abstractmethod
|
|
48
|
+
def subs(
|
|
49
|
+
self,
|
|
50
|
+
queue: Any,
|
|
51
|
+
handler: Optional[EventHandler] = None,
|
|
52
|
+
) -> None:
|
|
53
|
+
raise NotImplementedError('{} must implement subs'.format(self.__class__.__name__))
|
|
54
|
+
@abstractmethod
|
|
55
|
+
def run(self):
|
|
56
|
+
raise NotImplementedError('{} must be implemented run'.format(self.__class__.__name__))
|
|
57
|
+
@abstractmethod
|
|
58
|
+
def stop(self):
|
|
59
|
+
raise NotImplementedError('{} must be implemented stop'.format(self.__class__.__name__))
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from abc import abstractmethod
|
|
2
|
+
from typing import (
|
|
3
|
+
Any,
|
|
4
|
+
Protocol,
|
|
5
|
+
)
|
|
6
|
+
|
|
7
|
+
__all__ = (
|
|
8
|
+
'Event',
|
|
9
|
+
'EventHandler',
|
|
10
|
+
'EventErrorPolicy',
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class Event(Protocol):
|
|
15
|
+
@property
|
|
16
|
+
def body(self) -> Any: ...
|
|
17
|
+
|
|
18
|
+
def ack(self) -> None: ...
|
|
19
|
+
def nack(self) -> None: ...
|
|
20
|
+
def reject(self) -> None: ...
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class EventHandler(Protocol):
|
|
24
|
+
@abstractmethod
|
|
25
|
+
def __call__(
|
|
26
|
+
self,
|
|
27
|
+
event: Event,
|
|
28
|
+
) -> None: ...
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class EventErrorPolicy(Protocol):
|
|
32
|
+
def __call__(
|
|
33
|
+
self,
|
|
34
|
+
event: Event,
|
|
35
|
+
) -> None: ...
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
from DefStream.Broker import Configuration as BaseConfiguration
|
|
4
|
+
|
|
5
|
+
from .Serializer import (
|
|
6
|
+
Encoder,
|
|
7
|
+
Decoder,
|
|
8
|
+
JavaScriptObjectNotationEncoder,
|
|
9
|
+
JavaScriptObjectNotationDecoder,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
from pika import SSLOptions
|
|
14
|
+
from ssl import create_default_context
|
|
15
|
+
from typing import Optional
|
|
16
|
+
|
|
17
|
+
__all__ = (
|
|
18
|
+
'Configuration',
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class Configuration(BaseConfiguration):
|
|
23
|
+
"""
|
|
24
|
+
Configuration of Event Broker for RabbitMQ
|
|
25
|
+
"""
|
|
26
|
+
def __init__(
|
|
27
|
+
self,
|
|
28
|
+
host: str,
|
|
29
|
+
port: int,
|
|
30
|
+
username: str,
|
|
31
|
+
password: str,
|
|
32
|
+
ssl: bool = False,
|
|
33
|
+
vhost: str = '/',
|
|
34
|
+
timeout: Optional[int] = None,
|
|
35
|
+
heartbeat: Optional[int] = None,
|
|
36
|
+
encode: Encoder = JavaScriptObjectNotationEncoder(),
|
|
37
|
+
decode: Decoder = JavaScriptObjectNotationDecoder(),
|
|
38
|
+
):
|
|
39
|
+
self.host = host
|
|
40
|
+
self.port = port
|
|
41
|
+
self.username = username
|
|
42
|
+
self.password = password
|
|
43
|
+
self.ssl = SSLOptions(create_default_context(), host) if ssl else None
|
|
44
|
+
self.vhost = vhost
|
|
45
|
+
self.timeout = timeout/1000 if timeout else None
|
|
46
|
+
self.heartbeat = int(heartbeat*2/1000) if heartbeat else None
|
|
47
|
+
self.encode = encode
|
|
48
|
+
self.decode = decode
|
|
49
|
+
return
|