Skip to content
This repository was archived by the owner on Jan 28, 2022. It is now read-only.

Commit b01b1a7

Browse files
author
Sergio García Prado
authored
Merge pull request #445 from Clariteia/0.2.0
0.2.0
2 parents e3ede6e + 5d28488 commit b01b1a7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+666
-995
lines changed

HISTORY.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,12 @@ History
126126

127127
* Add `REPLY_TOPIC_CONTEXT_VAR` and integrate with `DynamicHandlerPool`.
128128
* Add support for `post_fn` callbacks following the same strategy as in `pre_fn` callbacks.
129+
130+
0.2.0 (2021-11-15)
131+
------------------
132+
133+
* Remove dependency to `minos-microservice-aggregate` (now `minos.aggregate` package will require `minos.networks`).
134+
* Add support for middleware functions.
135+
* Add support variable number of services (previously only `CommandService` and `QueryService` were allowed).
136+
* Migrate `Command`, `CommandReply`, `CommandStatus` and `Event` from `minos.common` to `minos.networks`.
137+
* Add support for `minos-microservice-common=^0.3.0`

minos/networks/__init__.py

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,32 @@
11
__author__ = """Clariteia Devs"""
22
__email__ = "devs@clariteia.com"
3-
__version__ = "0.1.1"
3+
__version__ = "0.2.0"
44

55
from .brokers import (
66
REPLY_TOPIC_CONTEXT_VAR,
77
Broker,
88
BrokerSetup,
9+
Command,
910
CommandBroker,
11+
CommandHandler,
12+
CommandHandlerService,
13+
CommandReply,
1014
CommandReplyBroker,
15+
CommandStatus,
16+
Consumer,
17+
ConsumerService,
18+
DynamicHandler,
19+
DynamicHandlerPool,
20+
Event,
1121
EventBroker,
22+
EventHandler,
23+
EventHandlerService,
24+
Handler,
25+
HandlerEntry,
26+
HandlerRequest,
27+
HandlerResponse,
28+
HandlerResponseException,
29+
HandlerSetup,
1230
Producer,
1331
ProducerService,
1432
)
@@ -44,24 +62,6 @@
4462
MinosNetworkException,
4563
MinosRedefinedEnrouteDecoratorException,
4664
)
47-
from .handlers import (
48-
CommandHandler,
49-
CommandHandlerService,
50-
CommandReplyHandler,
51-
CommandReplyHandlerService,
52-
Consumer,
53-
ConsumerService,
54-
DynamicHandler,
55-
DynamicHandlerPool,
56-
EventHandler,
57-
EventHandlerService,
58-
Handler,
59-
HandlerEntry,
60-
HandlerRequest,
61-
HandlerResponse,
62-
HandlerResponseException,
63-
HandlerSetup,
64-
)
6565
from .messages import (
6666
USER_CONTEXT_VAR,
6767
Request,
@@ -84,9 +84,6 @@
8484
ScheduledRequestContent,
8585
ScheduledResponseException,
8686
)
87-
from .snapshots import (
88-
SnapshotService,
89-
)
9087
from .utils import (
9188
consume_queue,
9289
get_host_ip,

minos/networks/brokers/__init__.py

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,32 @@
1-
from .abc import (
1+
from .messages import (
2+
REPLY_TOPIC_CONTEXT_VAR,
3+
Command,
4+
CommandReply,
5+
CommandStatus,
6+
Event,
7+
)
8+
from .publishers import (
29
Broker,
310
BrokerSetup,
4-
)
5-
from .command_replies import (
6-
CommandReplyBroker,
7-
)
8-
from .commands import (
9-
REPLY_TOPIC_CONTEXT_VAR,
1011
CommandBroker,
11-
)
12-
from .events import (
12+
CommandReplyBroker,
1313
EventBroker,
14-
)
15-
from .producers import (
1614
Producer,
17-
)
18-
from .services import (
1915
ProducerService,
2016
)
17+
from .subscribers import (
18+
CommandHandler,
19+
CommandHandlerService,
20+
Consumer,
21+
ConsumerService,
22+
DynamicHandler,
23+
DynamicHandlerPool,
24+
EventHandler,
25+
EventHandlerService,
26+
Handler,
27+
HandlerEntry,
28+
HandlerRequest,
29+
HandlerResponse,
30+
HandlerResponseException,
31+
HandlerSetup,
32+
)

minos/networks/brokers/messages.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
from __future__ import (
2+
annotations,
3+
)
4+
5+
from contextvars import (
6+
ContextVar,
7+
)
8+
from enum import (
9+
IntEnum,
10+
)
11+
from typing import (
12+
Any,
13+
Final,
14+
Optional,
15+
)
16+
from uuid import (
17+
UUID,
18+
)
19+
20+
from minos.common import (
21+
DeclarativeModel,
22+
)
23+
24+
REPLY_TOPIC_CONTEXT_VAR: Final[ContextVar[Optional[str]]] = ContextVar("reply_topic", default=None)
25+
26+
27+
class Command(DeclarativeModel):
28+
"""Base Command class."""
29+
30+
topic: str
31+
data: Any
32+
saga: Optional[UUID]
33+
reply_topic: str
34+
user: Optional[UUID]
35+
36+
37+
class CommandReply(DeclarativeModel):
38+
"""Base Command class."""
39+
40+
topic: str
41+
data: Any
42+
saga: Optional[UUID]
43+
status: CommandStatus
44+
service_name: Optional[str]
45+
46+
@property
47+
def ok(self) -> bool:
48+
"""Check if the reply is okay or not.
49+
50+
:return: ``True`` if the reply is okay or ``False`` otherwise.
51+
"""
52+
return self.status == CommandStatus.SUCCESS
53+
54+
55+
class CommandStatus(IntEnum):
56+
"""Command Status class."""
57+
58+
SUCCESS = 200
59+
ERROR = 400
60+
SYSTEM_ERROR = 500
61+
62+
63+
class Event(DeclarativeModel):
64+
"""Base Event class."""
65+
66+
topic: str
67+
data: Any
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from .abc import (
2+
Broker,
3+
BrokerSetup,
4+
)
5+
from .command_replies import (
6+
CommandReplyBroker,
7+
)
8+
from .commands import (
9+
CommandBroker,
10+
)
11+
from .events import (
12+
EventBroker,
13+
)
14+
from .producers import (
15+
Producer,
16+
)
17+
from .services import (
18+
ProducerService,
19+
)
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
)
88

99
from minos.common import (
10-
MinosBroker,
1110
PostgreSqlMinosDatabase,
1211
)
1312

@@ -22,7 +21,7 @@ async def _create_broker_table(self) -> None:
2221
await self.submit_query(_CREATE_TABLE_QUERY, lock=hash("producer_queue"))
2322

2423

25-
class Broker(MinosBroker, BrokerSetup, ABC):
24+
class Broker(BrokerSetup, ABC):
2625
"""Minos Broker Class."""
2726

2827
ACTION: str

minos/networks/brokers/command_replies.py renamed to minos/networks/brokers/publishers/command_replies.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
)
1212

1313
from minos.common import (
14-
CommandReply,
15-
CommandStatus,
1614
MinosConfig,
1715
)
1816

17+
from ..messages import (
18+
CommandReply,
19+
CommandStatus,
20+
)
1921
from .abc import (
2022
Broker,
2123
)
@@ -28,9 +30,13 @@ class CommandReplyBroker(Broker):
2830

2931
ACTION = "commandReply"
3032

33+
def __init__(self, *args, service_name: str, **kwargs):
34+
super().__init__(*args, **kwargs)
35+
self.service_name = service_name
36+
3137
@classmethod
3238
def _from_config(cls, *args, config: MinosConfig, **kwargs) -> CommandReplyBroker:
33-
return cls(*args, **config.broker.queue._asdict(), **kwargs)
39+
return cls(*args, service_name=config.service.name, **config.broker.queue._asdict(), **kwargs)
3440

3541
# noinspection PyMethodOverriding
3642
async def send(self, data: Any, topic: str, saga: UUID, status: CommandStatus, **kwargs) -> int:
@@ -39,10 +45,10 @@ async def send(self, data: Any, topic: str, saga: UUID, status: CommandStatus, *
3945
:param data: The data to be send.
4046
:param topic: Topic in which the message will be published.
4147
:param saga: Saga identifier.
42-
:param status: Command status.
48+
:param status: command status.
4349
:return: This method does not return anything.
4450
"""
4551

46-
command_reply = CommandReply(topic, data, saga, status)
52+
command_reply = CommandReply(topic, data, saga=saga, status=status, service_name=self.service_name)
4753
logger.info(f"Sending '{command_reply!s}'...")
4854
return await self.enqueue(command_reply.topic, command_reply.avro_bytes)

minos/networks/brokers/commands.py renamed to minos/networks/brokers/publishers/commands.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,28 @@
33
)
44

55
import logging
6-
from contextvars import (
7-
ContextVar,
8-
)
96
from typing import (
107
Any,
11-
Final,
128
Optional,
139
)
1410
from uuid import (
1511
UUID,
1612
)
1713

1814
from minos.common import (
19-
Command,
2015
MinosConfig,
2116
)
2217

18+
from ..messages import (
19+
REPLY_TOPIC_CONTEXT_VAR,
20+
Command,
21+
)
2322
from .abc import (
2423
Broker,
2524
)
2625

2726
logger = logging.getLogger(__name__)
2827

29-
REPLY_TOPIC_CONTEXT_VAR: Final[ContextVar[Optional[str]]] = ContextVar("reply_topic", default=None)
30-
3128

3229
class CommandBroker(Broker):
3330
"""Minos Command Broker Class."""
@@ -48,7 +45,7 @@ async def send(
4845
self,
4946
data: Any,
5047
topic: str,
51-
saga: UUID,
48+
saga: Optional[UUID] = None,
5249
reply_topic: Optional[str] = None,
5350
user: Optional[UUID] = None,
5451
**kwargs,

minos/networks/brokers/events.py renamed to minos/networks/brokers/publishers/events.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33
)
44

55
import logging
6-
7-
from minos.aggregate import (
8-
AggregateDiff,
6+
from typing import (
7+
Any,
98
)
9+
1010
from minos.common import (
11-
Event,
1211
MinosConfig,
1312
)
1413

14+
from ..messages import (
15+
Event,
16+
)
1517
from .abc import (
1618
Broker,
1719
)
@@ -29,7 +31,7 @@ def _from_config(cls, *args, config: MinosConfig, **kwargs) -> EventBroker:
2931
return cls(*args, **config.broker.queue._asdict(), **kwargs)
3032

3133
# noinspection PyMethodOverriding
32-
async def send(self, data: AggregateDiff, topic: str, **kwargs) -> int:
34+
async def send(self, data: Any, topic: str, **kwargs) -> int:
3335
"""Send an ``Event``.
3436
3537
:param data: The data to be send.

minos/networks/brokers/producers.py renamed to minos/networks/brokers/publishers/producers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@
3434
MinosConfig,
3535
)
3636

37-
from ..handlers import (
38-
Consumer,
39-
)
40-
from ..utils import (
37+
from ...utils import (
4138
consume_queue,
4239
)
40+
from ..subscribers import (
41+
Consumer,
42+
)
4343
from .abc import (
4444
BrokerSetup,
4545
)

0 commit comments

Comments
 (0)