busline 0.3.0__py3-none-any.whl → 0.5.0__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.
- busline/client/client.py +27 -0
- {eventbus_client → busline/client}/eventbus_connector.py +5 -10
- busline/client/multiclient.py +41 -0
- busline/client/publisher/publisher.py +60 -0
- busline/client/pubsub_client.py +128 -0
- busline/client/subscriber/event_handler/closure_event_handler.py +18 -0
- busline/client/subscriber/event_handler/event_handler.py +15 -0
- busline/client/subscriber/event_handler/multi_handler.py +30 -0
- busline/client/subscriber/subscriber.py +109 -0
- busline/client/subscriber/topic_subscriber.py +79 -0
- busline/event/event.py +47 -0
- busline/event/registry.py +67 -0
- busline/event/test.py +47 -0
- busline/exceptions.py +8 -0
- busline/local/__init__.py +3 -0
- busline/local/eventbus/__init__.py +0 -0
- busline/local/eventbus/async_local_eventbus.py +26 -0
- busline/local/eventbus/eventbus.py +86 -0
- busline/local/eventbus/local_eventbus.py +23 -0
- busline/local/local_pubsub_client.py +54 -0
- busline/local/publisher/__init__.py +0 -0
- busline/local/publisher/local_publisher.py +38 -0
- busline/local/subscriber/__init__.py +0 -0
- busline/local/subscriber/local_subscriber.py +43 -0
- busline/local/test.py +156 -0
- busline-0.5.0.dist-info/METADATA +215 -0
- busline-0.5.0.dist-info/RECORD +36 -0
- {busline-0.3.0.dist-info → busline-0.5.0.dist-info}/WHEEL +1 -1
- busline-0.5.0.dist-info/top_level.txt +1 -0
- busline-0.3.0.dist-info/METADATA +0 -104
- busline-0.3.0.dist-info/RECORD +0 -30
- busline-0.3.0.dist-info/top_level.txt +0 -4
- event/event.py +0 -25
- event/event_content.py +0 -18
- event/event_metadata.py +0 -26
- eventbus/async_local_eventbus.py +0 -32
- eventbus/eventbus.py +0 -112
- eventbus/exceptions.py +0 -2
- eventbus/queued_local_eventbus.py +0 -50
- eventbus/topic.py +0 -35
- eventbus_client/eventbus_client.py +0 -99
- eventbus_client/exceptions.py +0 -4
- eventbus_client/local_eventbus_client.py +0 -25
- eventbus_client/publisher/local_eventbus_publisher.py +0 -35
- eventbus_client/publisher/publisher.py +0 -59
- eventbus_client/subscriber/closure_event_listener.py +0 -19
- eventbus_client/subscriber/event_listener.py +0 -15
- eventbus_client/subscriber/local_eventbus_closure_subscriber.py +0 -17
- eventbus_client/subscriber/local_eventbus_subscriber.py +0 -40
- eventbus_client/subscriber/subscriber.py +0 -93
- /__init__.py → /busline/__init__.py +0 -0
- {event → busline/client}/__init__.py +0 -0
- {eventbus → busline/client/publisher}/__init__.py +0 -0
- {eventbus_client → busline/client/subscriber}/__init__.py +0 -0
- {eventbus_client/publisher → busline/client/subscriber/event_handler}/__init__.py +0 -0
- {eventbus_client/subscriber → busline/event}/__init__.py +0 -0
- {busline-0.3.0.dist-info → busline-0.5.0.dist-info/licenses}/LICENSE +0 -0
eventbus/topic.py
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
class Topic:
|
4
|
-
"""
|
5
|
-
Topic of generic eventbus.
|
6
|
-
|
7
|
-
:param name: unique name of the topic
|
8
|
-
:param content_type: MIME type which describes content of the topic (e.g. "application/json")
|
9
|
-
:param description: simple topic description
|
10
|
-
:param priority: priority of message in topic related to other topics
|
11
|
-
|
12
|
-
Author: Nicola Ricciardi
|
13
|
-
"""
|
14
|
-
|
15
|
-
def __init__(self, name: str, content_type: str | None = None, description: str | None = None, priority: int = 0):
|
16
|
-
self.__name = name
|
17
|
-
self.__description = description
|
18
|
-
self.__content_type = content_type
|
19
|
-
self.__priority = priority
|
20
|
-
|
21
|
-
@property
|
22
|
-
def name(self) -> str:
|
23
|
-
return self.__name
|
24
|
-
|
25
|
-
@property
|
26
|
-
def description(self) -> str | None:
|
27
|
-
return self.__description
|
28
|
-
|
29
|
-
@property
|
30
|
-
def content_type(self) -> str | None:
|
31
|
-
return self.__content_type
|
32
|
-
|
33
|
-
@property
|
34
|
-
def priority(self) -> int:
|
35
|
-
return self.__priority
|
@@ -1,99 +0,0 @@
|
|
1
|
-
from uuid import uuid4
|
2
|
-
from src.event.event import Event
|
3
|
-
from src.eventbus_client.eventbus_connector import EventBusConnector
|
4
|
-
from src.eventbus_client.publisher.publisher import Publisher
|
5
|
-
from src.eventbus_client.subscriber.event_listener import EventListener
|
6
|
-
from src.eventbus_client.subscriber.subscriber import Subscriber
|
7
|
-
|
8
|
-
|
9
|
-
class EventBusClient(EventBusConnector):
|
10
|
-
"""
|
11
|
-
Eventbus client which should used by components which wouldn't be a publisher/subscriber, but they need them
|
12
|
-
|
13
|
-
Author: Nicola Ricciardi
|
14
|
-
"""
|
15
|
-
|
16
|
-
def __init__(self, publisher: Publisher, subscriber: Subscriber, event_listener: EventListener | None = None, client_id: str = str(uuid4())):
|
17
|
-
EventBusConnector.__init__(self, client_id)
|
18
|
-
|
19
|
-
self._id = client_id
|
20
|
-
self.__publisher: Publisher = None
|
21
|
-
self.__subscriber: Subscriber = None
|
22
|
-
self.__event_listener: EventListener = None
|
23
|
-
|
24
|
-
self.publisher = publisher
|
25
|
-
self.subscriber = subscriber
|
26
|
-
self.event_listener = event_listener
|
27
|
-
|
28
|
-
@property
|
29
|
-
def publisher(self) -> Publisher:
|
30
|
-
return self.__publisher
|
31
|
-
|
32
|
-
@publisher.setter
|
33
|
-
def publisher(self, publisher: Publisher):
|
34
|
-
self.__publisher = publisher
|
35
|
-
|
36
|
-
@property
|
37
|
-
def subscriber(self) -> Subscriber:
|
38
|
-
return self.__subscriber
|
39
|
-
|
40
|
-
@subscriber.setter
|
41
|
-
def subscriber(self, subscriber: Subscriber):
|
42
|
-
|
43
|
-
original_on_event = subscriber.on_event
|
44
|
-
|
45
|
-
async def on_event_wrapper(*args, **kwargs): # wrap on_event method to call self.on_event
|
46
|
-
await original_on_event(*args, **kwargs)
|
47
|
-
await self.on_event(*args, **kwargs)
|
48
|
-
|
49
|
-
subscriber.on_event = on_event_wrapper
|
50
|
-
self.__subscriber = subscriber
|
51
|
-
|
52
|
-
@property
|
53
|
-
def event_listener(self) -> EventListener:
|
54
|
-
return self.__event_listener
|
55
|
-
|
56
|
-
@event_listener.setter
|
57
|
-
def event_listener(self, event_listener: EventListener):
|
58
|
-
self.__event_listener = event_listener
|
59
|
-
|
60
|
-
async def connect(self):
|
61
|
-
c1 = self.__publisher.connect()
|
62
|
-
c2 = self.__subscriber.connect()
|
63
|
-
|
64
|
-
await c1
|
65
|
-
await c2
|
66
|
-
|
67
|
-
async def disconnect(self):
|
68
|
-
d1 = self.__publisher.disconnect()
|
69
|
-
d2 = self.__subscriber.disconnect()
|
70
|
-
|
71
|
-
await d1
|
72
|
-
await d2
|
73
|
-
|
74
|
-
async def publish(self, topic_name: str, event: Event, **kwargs):
|
75
|
-
"""
|
76
|
-
Alias of `client.publisher.publish(...)`
|
77
|
-
"""
|
78
|
-
|
79
|
-
await self.__publisher.publish(topic_name, event, **kwargs)
|
80
|
-
|
81
|
-
async def subscribe(self, topic_name: str, **kwargs):
|
82
|
-
"""
|
83
|
-
Alias of `client.subscriber.subscribe(...)`
|
84
|
-
"""
|
85
|
-
|
86
|
-
await self.__subscriber.subscribe(topic_name, **kwargs)
|
87
|
-
|
88
|
-
async def unsubscribe(self, topic_name: str | None = None, **kwargs):
|
89
|
-
"""
|
90
|
-
Alias of `client.subscriber.unsubscribe(...)`
|
91
|
-
"""
|
92
|
-
|
93
|
-
await self.__subscriber.unsubscribe(topic_name, **kwargs)
|
94
|
-
|
95
|
-
async def on_event(self, topic_name: str, event: Event, **kwargs):
|
96
|
-
if self.__event_listener is not None:
|
97
|
-
await self.__event_listener.on_event(topic_name, event, **kwargs)
|
98
|
-
|
99
|
-
|
eventbus_client/exceptions.py
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
from typing import Callable
|
2
|
-
from uuid import uuid4
|
3
|
-
|
4
|
-
from src.event.event import Event
|
5
|
-
from src.eventbus.async_local_eventbus import AsyncLocalEventBus
|
6
|
-
from src.eventbus_client.eventbus_client import EventBusClient
|
7
|
-
from src.eventbus_client.publisher.local_eventbus_publisher import LocalEventBusPublisher
|
8
|
-
from src.eventbus_client.subscriber.local_eventbus_closure_subscriber import LocalEventBusClosureSubscriber
|
9
|
-
|
10
|
-
|
11
|
-
class LocalEventBusClient(EventBusClient):
|
12
|
-
|
13
|
-
def __init__(self, on_event_callback: Callable[[str, Event], None], client_id: str = str(uuid4())):
|
14
|
-
|
15
|
-
eventbus_instance = AsyncLocalEventBus()
|
16
|
-
|
17
|
-
EventBusClient.__init__(
|
18
|
-
self,
|
19
|
-
publisher=LocalEventBusPublisher(eventbus_instance),
|
20
|
-
subscriber=LocalEventBusClosureSubscriber(eventbus_instance, on_event_callback),
|
21
|
-
client_id=client_id
|
22
|
-
)
|
23
|
-
|
24
|
-
|
25
|
-
|
@@ -1,35 +0,0 @@
|
|
1
|
-
from src.event.event import Event
|
2
|
-
from src.eventbus.eventbus import EventBus
|
3
|
-
from src.eventbus_client.exceptions import EventBusClientNotConnected
|
4
|
-
from src.eventbus_client.publisher.publisher import Publisher
|
5
|
-
|
6
|
-
|
7
|
-
class LocalEventBusPublisher(Publisher):
|
8
|
-
"""
|
9
|
-
Publisher which works with local eventbus, this class can be initialized and used stand-alone
|
10
|
-
|
11
|
-
Author: Nicola Ricciardi
|
12
|
-
"""
|
13
|
-
|
14
|
-
def __init__(self, eventbus_instance: EventBus):
|
15
|
-
Publisher.__init__(self)
|
16
|
-
|
17
|
-
self._eventbus = eventbus_instance
|
18
|
-
self._connected = False
|
19
|
-
|
20
|
-
async def connect(self):
|
21
|
-
self._connected = True
|
22
|
-
|
23
|
-
async def disconnect(self):
|
24
|
-
self._connected = False
|
25
|
-
|
26
|
-
async def _internal_publish(self, topic_name: str, event: Event, raise_if_not_connected: bool = False, **kwargs):
|
27
|
-
|
28
|
-
if raise_if_not_connected and not self._connected:
|
29
|
-
raise EventBusClientNotConnected()
|
30
|
-
else:
|
31
|
-
await self.connect()
|
32
|
-
|
33
|
-
self.on_publishing(topic_name, event)
|
34
|
-
await self._eventbus.put_event(topic_name, event)
|
35
|
-
self.on_published(topic_name, event)
|
@@ -1,59 +0,0 @@
|
|
1
|
-
import logging
|
2
|
-
from abc import ABC, abstractmethod
|
3
|
-
from uuid import uuid4
|
4
|
-
|
5
|
-
from src.event.event import Event
|
6
|
-
from src.eventbus_client.eventbus_connector import EventBusConnector
|
7
|
-
|
8
|
-
|
9
|
-
class Publisher(EventBusConnector, ABC):
|
10
|
-
"""
|
11
|
-
Abstract class which can be implemented by your components which must be able to publish on eventbus
|
12
|
-
|
13
|
-
Author: Nicola Ricciardi
|
14
|
-
"""
|
15
|
-
|
16
|
-
def __init__(self, publisher_id: str = str(uuid4())):
|
17
|
-
EventBusConnector.__init__(self, publisher_id)
|
18
|
-
|
19
|
-
@abstractmethod
|
20
|
-
async def _internal_publish(self, topic_name: str, event: Event, **kwargs):
|
21
|
-
"""
|
22
|
-
Actual publish on topic the event
|
23
|
-
|
24
|
-
:param topic_name:
|
25
|
-
:param event:
|
26
|
-
:return:
|
27
|
-
"""
|
28
|
-
|
29
|
-
async def publish(self, topic_name: str, event: Event, **kwargs):
|
30
|
-
"""
|
31
|
-
Publish on topic the event
|
32
|
-
|
33
|
-
:param topic_name:
|
34
|
-
:param event:
|
35
|
-
:return:
|
36
|
-
"""
|
37
|
-
|
38
|
-
logging.debug(f"{self._id} publishing on {topic_name}: {event}")
|
39
|
-
self.on_publishing(topic_name, event)
|
40
|
-
await self._internal_publish(topic_name, event, **kwargs)
|
41
|
-
self.on_published(topic_name, event)
|
42
|
-
|
43
|
-
def on_publishing(self, topic_name: str, event: Event):
|
44
|
-
"""
|
45
|
-
Callback called on publishing start
|
46
|
-
|
47
|
-
:param topic_name:
|
48
|
-
:param event:
|
49
|
-
:return:
|
50
|
-
"""
|
51
|
-
|
52
|
-
def on_published(self, topic_name: str, event: Event):
|
53
|
-
"""
|
54
|
-
Callback called on publishing end
|
55
|
-
|
56
|
-
:param topic_name:
|
57
|
-
:param event:
|
58
|
-
:return:
|
59
|
-
"""
|
@@ -1,19 +0,0 @@
|
|
1
|
-
from typing import Callable
|
2
|
-
from src.event.event import Event
|
3
|
-
from src.eventbus_client.subscriber.event_listener import EventListener
|
4
|
-
|
5
|
-
|
6
|
-
class ClosureEventListener(EventListener):
|
7
|
-
"""
|
8
|
-
Abstract event listener which use a pre-defined callback as `on_event`
|
9
|
-
|
10
|
-
Author: Nicola Ricciardi
|
11
|
-
"""
|
12
|
-
|
13
|
-
def __init__(self, on_event_callback: Callable[[str, Event], None]):
|
14
|
-
EventListener.__init__(self)
|
15
|
-
|
16
|
-
self.__on_event_callback = on_event_callback
|
17
|
-
|
18
|
-
async def on_event(self, topic_name: str, event: Event, **kwargs):
|
19
|
-
self.__on_event_callback(topic_name, event, **kwargs)
|
@@ -1,15 +0,0 @@
|
|
1
|
-
from abc import ABC, abstractmethod
|
2
|
-
from src.event.event import Event
|
3
|
-
|
4
|
-
|
5
|
-
class EventListener(ABC):
|
6
|
-
|
7
|
-
@abstractmethod
|
8
|
-
async def on_event(self, topic_name: str, event: Event, **kwargs):
|
9
|
-
"""
|
10
|
-
Callback called when new event arrives
|
11
|
-
|
12
|
-
:param topic_name:
|
13
|
-
:param event:
|
14
|
-
:return:
|
15
|
-
"""
|
@@ -1,17 +0,0 @@
|
|
1
|
-
from typing import Callable
|
2
|
-
from src.event.event import Event
|
3
|
-
from src.eventbus.eventbus import EventBus
|
4
|
-
from src.eventbus_client.subscriber.closure_event_listener import ClosureEventListener
|
5
|
-
from src.eventbus_client.subscriber.local_eventbus_subscriber import LocalEventBusSubscriber
|
6
|
-
|
7
|
-
|
8
|
-
class LocalEventBusClosureSubscriber(LocalEventBusSubscriber, ClosureEventListener):
|
9
|
-
"""
|
10
|
-
Subscriber which works with local eventbus, this class can be initialized and used stand-alone
|
11
|
-
|
12
|
-
Author: Nicola Ricciardi
|
13
|
-
"""
|
14
|
-
|
15
|
-
def __init__(self, eventbus_instance: EventBus, on_event_callback: Callable[[str, Event], None]):
|
16
|
-
LocalEventBusSubscriber.__init__(self, eventbus_instance)
|
17
|
-
ClosureEventListener.__init__(self, on_event_callback)
|
@@ -1,40 +0,0 @@
|
|
1
|
-
from abc import ABC
|
2
|
-
from src.eventbus.eventbus import EventBus
|
3
|
-
from src.eventbus_client.exceptions import EventBusClientNotConnected
|
4
|
-
from src.eventbus_client.subscriber.subscriber import Subscriber
|
5
|
-
|
6
|
-
|
7
|
-
class LocalEventBusSubscriber(Subscriber, ABC):
|
8
|
-
"""
|
9
|
-
Abstract subscriber which works with local eventbus without implementing `on_event` method
|
10
|
-
|
11
|
-
Author: Nicola Ricciardi
|
12
|
-
"""
|
13
|
-
|
14
|
-
def __init__(self, eventbus_instance: EventBus):
|
15
|
-
Subscriber.__init__(self)
|
16
|
-
|
17
|
-
self._eventbus = eventbus_instance
|
18
|
-
self._connected = False
|
19
|
-
|
20
|
-
async def connect(self):
|
21
|
-
self._connected = True
|
22
|
-
|
23
|
-
async def disconnect(self):
|
24
|
-
self._connected = False
|
25
|
-
|
26
|
-
async def _internal_subscribe(self, topic_name: str, raise_if_not_connected: bool = False, **kwargs):
|
27
|
-
if raise_if_not_connected and not self._connected:
|
28
|
-
raise EventBusClientNotConnected()
|
29
|
-
else:
|
30
|
-
await self.connect()
|
31
|
-
|
32
|
-
self._eventbus.add_subscriber(topic_name, self)
|
33
|
-
|
34
|
-
async def _internal_unsubscribe(self, topic_name: str | None = None, raise_if_not_connected: bool = False, **kwargs):
|
35
|
-
if raise_if_not_connected and not self._connected:
|
36
|
-
raise EventBusClientNotConnected()
|
37
|
-
else:
|
38
|
-
await self.connect()
|
39
|
-
|
40
|
-
self._eventbus.remove_subscriber(self, topic_name)
|
@@ -1,93 +0,0 @@
|
|
1
|
-
from abc import ABC, abstractmethod
|
2
|
-
from uuid import uuid4
|
3
|
-
|
4
|
-
from src.event.event import Event
|
5
|
-
from src.eventbus_client.eventbus_connector import EventBusConnector
|
6
|
-
from src.eventbus_client.subscriber.event_listener import EventListener
|
7
|
-
|
8
|
-
|
9
|
-
class Subscriber(EventBusConnector, EventListener, ABC):
|
10
|
-
"""
|
11
|
-
Abstract class which can be implemented by your components which must be able to subscribe on eventbus
|
12
|
-
|
13
|
-
Author: Nicola Ricciardi
|
14
|
-
"""
|
15
|
-
|
16
|
-
def __init__(self, subscriber_id: str = str(uuid4())):
|
17
|
-
EventBusConnector.__init__(self, subscriber_id)
|
18
|
-
EventListener.__init__(self)
|
19
|
-
|
20
|
-
|
21
|
-
@abstractmethod
|
22
|
-
async def _internal_subscribe(self, topic_name: str, **kwargs):
|
23
|
-
"""
|
24
|
-
Actual subscribe to topic
|
25
|
-
|
26
|
-
:param topic_name:
|
27
|
-
:return:
|
28
|
-
"""
|
29
|
-
|
30
|
-
@abstractmethod
|
31
|
-
async def _internal_unsubscribe(self, topic_name: str | None = None, **kwargs):
|
32
|
-
"""
|
33
|
-
Actual unsubscribe to topic
|
34
|
-
|
35
|
-
:param topic_name:
|
36
|
-
:return:
|
37
|
-
"""
|
38
|
-
|
39
|
-
async def subscribe(self, topic_name: str, **kwargs):
|
40
|
-
"""
|
41
|
-
Subscribe to topic
|
42
|
-
|
43
|
-
:param topic_name:
|
44
|
-
:return:
|
45
|
-
"""
|
46
|
-
|
47
|
-
self.on_subscribing(topic_name)
|
48
|
-
await self._internal_subscribe(topic_name, **kwargs)
|
49
|
-
self.on_subscribed(topic_name)
|
50
|
-
|
51
|
-
async def unsubscribe(self, topic_name: str | None = None, **kwargs):
|
52
|
-
"""
|
53
|
-
Unsubscribe to topic
|
54
|
-
|
55
|
-
:param topic_name:
|
56
|
-
:return:
|
57
|
-
"""
|
58
|
-
|
59
|
-
self.on_unsubscribing(topic_name)
|
60
|
-
await self._internal_unsubscribe(topic_name, **kwargs)
|
61
|
-
self.on_unsubscribed(topic_name)
|
62
|
-
|
63
|
-
def on_subscribing(self, topic_name: str):
|
64
|
-
"""
|
65
|
-
Callback called on subscribing
|
66
|
-
|
67
|
-
:param topic_name:
|
68
|
-
:return:
|
69
|
-
"""
|
70
|
-
|
71
|
-
def on_subscribed(self, topic_name: str):
|
72
|
-
"""
|
73
|
-
Callback called on subscribed
|
74
|
-
|
75
|
-
:param topic_name:
|
76
|
-
:return:
|
77
|
-
"""
|
78
|
-
|
79
|
-
def on_unsubscribing(self, topic_name: str):
|
80
|
-
"""
|
81
|
-
Callback called on unsubscribing
|
82
|
-
|
83
|
-
:param topic_name:
|
84
|
-
:return:
|
85
|
-
"""
|
86
|
-
|
87
|
-
def on_unsubscribed(self, topic_name: str):
|
88
|
-
"""
|
89
|
-
Callback called on unsubscribed
|
90
|
-
|
91
|
-
:param topic_name:
|
92
|
-
:return:
|
93
|
-
"""
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|