You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Minos is a framework which helps you create [reactive](https://www.reactivemanifesto.org/) microservices in Python.
25
-
Internally, it leverages Event Sourcing, CQRS and a message driven architecture to fulfil the commitments of an
26
-
asynchronous environment.
17
+
Minos is a framework which helps you create [reactive](https://www.reactivemanifesto.org/) microservices in Python. Internally, it leverages Event Sourcing, CQRS and a message driven architecture to fulfil the commitments of an asynchronous environment.
18
+
19
+
## Installation
20
+
21
+
### Guided installation
22
+
23
+
The easiest way to use `minos` is with the help of the [`minos-cli`](https://github.com/minos-framework/minos-cli), which provides commands to setup both the project skeleton (configures containerization, databases, brokers, etc.) and the microservice skeleton (the base microservice structure, environment configuration, etc.)
24
+
25
+
### Manual installation
26
+
27
+
If you want to directly use `minos` without the command-line utility, the following command will install the needed packages:
28
+
29
+
```shell
30
+
pip install \
31
+
minos-microservice-aggregate \
32
+
minos-microservice-common \
33
+
minos-microservice-cqrs \
34
+
minos-microservice-networks \
35
+
minos-microservice-saga
36
+
```
37
+
38
+
## Usage
39
+
40
+
This section includes a set of minimal examples of how-to-work with `minos`, so that anyone can get the gist of the framework.
41
+
42
+
### Create an Aggregate
43
+
44
+
Here is an example of the creation the `Foo` aggregate. In this case, it has two attributes, a `bar` being a `str`, and a `foobar` being an optional reference to the external `FooBar` aggregate, which it is assumed that it has a `something` attribute.
45
+
46
+
```python
47
+
from__future__import annotations
48
+
from typing import Optional
49
+
from minos.aggregate import Aggregate, AggregateRef, ModelRef
50
+
51
+
52
+
classFoo(Aggregate):
53
+
"""Foo Aggregate class."""
54
+
55
+
bar: str
56
+
foobar: Optional[ModelRef[FooBar]]
57
+
58
+
59
+
classFooBar(AggregateRef):
60
+
"""FooBar AggregateRef clas."""
61
+
62
+
something: str
63
+
```
64
+
65
+
### Expose a Command
66
+
67
+
Here is an example of the definition of a command to create `Foo` instances. To do that, it is necessary to define a `CommandService` that contains the handling function. It will handle both the broker messages sent to the `"CreateFoo"` topic and the rest calls to the `"/foos"` path with the `"POST"` method. In this case, the handling function unpacks the `Request`'s content and then calls the `create` method from the `Aggregate`, which stores the `Foo` instance following an event-driven strategy (it also publishes the `"FooCreated"` event). Finally, a `Response` is returned to be handled by the external caller (another microservice or the API-gateway).
68
+
69
+
```python
70
+
from minos.cqrs import CommandService
71
+
from minos.networks import enroute, Request, Response
:param request: The ``Request`` that contains the ``bar`` attribute.
83
+
:return: A ``Response`` containing identifier of the already created instance.
84
+
"""
85
+
content =await request.content()
86
+
bar = content["bar"]
87
+
88
+
foo =await Foo.create(bar)
89
+
90
+
return Response({"uuid": foo.uuid})
91
+
```
92
+
93
+
### Subscribe to an Event and Expose a Query
94
+
95
+
Here is an example of the event and query handling. In this case, it must be defined on a `QueryService` class. In this case a `"FooCreated"` event is handled (and only a `print` of the content is performed). The event contents typically contains instances of `AggregateDiff` type, which is referred to the difference respect to the previously stored instance. The exposed query is connected to the calls that come from the `"/foos/example"` path and `"GET"` method and a naive string is returned.
96
+
97
+
*Disclaimer*: A real `QueryService` implementation must populate a query-oriented database based on the events to which is subscribed to, and expose queries performed over that query-oriented database.
98
+
99
+
```python
100
+
from minos.cqrs import QueryService
101
+
from minos.networks import enroute, Request, Response
:param request: The ``Request`` that contains the necessary information.
122
+
:return: A ``Response`` instance.
123
+
"""
124
+
return Response("This is an example response!")
125
+
```
126
+
127
+
### Interact with another Microservice
128
+
129
+
Here is an example of the interaction between two microservices through a SAGA pattern. In this case, the interaction starts with a call to the `"/foo/add-foobar"` path and the `"POST"` method, which performs a `SagaManager` run over the `ADD_FOOBAR_SAGA` saga. This saga has two steps, one remote that executes the `"CreateFooBar"` command (possibly defined on the supposed `"foobar"` microservice), and a local step that is executed on this microservice. The `CreateFooBarDTO` defines the structure of the request to be sent when the `"CreateFooBar"` command is executed.
130
+
131
+
```python
132
+
from minos.common import ModelType
133
+
from minos.cqrs import CommandService
134
+
from minos.networks import enroute, Request
135
+
from minos.saga import Saga, SagaContext, SagaRequest, SagaResponse
@@ -45,17 +204,18 @@ The core packages provide the base implementation of the framework.
45
204
46
205
### Plugins
47
206
48
-
The plugin packages provide connectors to external technologies like brokers, discovery services, databases, serializers and so on.
207
+
The plugin packages provide connectors to external technologies like brokers, discovery services, databases, serializers and so on.
49
208
50
209
## Source Code
51
210
52
-
The source code of this project is hosted at [GitHub](https://github.com/minos-framework/minos-python).
211
+
The source code of this project is hosted at [GitHub](https://github.com/minos-framework/minos-python).
53
212
54
213
## Getting Help
55
214
56
215
For usage questions, the best place to go to is [StackOverflow](https://stackoverflow.com/questions/tagged/minos).
57
216
58
217
## Discussion and Development
218
+
59
219
Most development discussions take place over the [GitHub Issues](https://github.com/minos-framework/minos-python/issues). In addition, a [Gitter channel](https://gitter.im/minos-framework/community) is available for development-related questions.
0 commit comments