AetherMagic - Communications between microservices over MQTT
Project description
AetherMagic
Communications between microservices over MQTT
The goal is to create communication between microservices, using such advantages as:
- Scaling (multiple microservices to perform one group of tasks)
- Distribution of tasks (only one microserver receives a task in a group)
- Distribution of access rights for specific tasks/roles (setting or execution) and division, if necessary, by projects (by configuring access rights on the server side in the MQTT broker)
Installation
pip install aethermagic
Example
To launch a task on master-server / separate process:
from aethermagic import AetherTask
async def complete(ae, success, output_data):
print('complete')
async def status(ae, complete, success, progress, output_data):
print('status')
input_data = {}
await AetherTask(None, 'worker', 'collect', on_complete=complete, on_status=status).perform(input_data)
Variables and values:
completeTrue / FalsesuccessTrue / Falseprogress0...100input_datauser-defined data to serialize into JSONoutput_datauser-defined data unserialized from JSON
To perform task on worker-server / separate process:
from aethermagic import AetherTask
async def perform(ae, input_data):
print('perform')
await ae.status(100) # Optional
output_data = {}
success = True
await ae.complete(success, output_data)
await AetherTask(None, 'worker', 'collect', on_perform=perform).idle()
Variables and values:
input_datauser-defined data to serialize into JSONoutput_datauser-defined data unserialized from JSON
AetherMagic requires running or joining an existing async loop:
For example, in simple python app you can do it with the following code:
import threading
import asyncio
from aethermagic import AetherMagic
def startloop(self, args=[None]) -> None:
async def starttask() -> None:
aem = AetherMagic(server=settings.MQTT_BROKER, port=settings.MQTT_PORT, ssl=True, user=settings.MQTT_USER, password=settings.MQTT_PASSWORD, union=settings.AETHER_UNION)
async with asyncio.TaskGroup() as group:
group.create_task(aem.main())
#group.create_task(your_loop.main()) # Optional: You can create your own async loop
asyncio.run(starttask())
thread = threading.Thread(target=startloop, args=[None])
thread.start()
thread.join() # Will wait for thread execution to complete ==> never
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
aethermagic-0.0.4.tar.gz
(7.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aethermagic-0.0.4.tar.gz.
File metadata
- Download URL: aethermagic-0.0.4.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc4f417faba1abe85a50a7ab43b16b3d081028c754c47d8b9cec586ff6e31940
|
|
| MD5 |
d3f10384ffd5593700d3d0169e269fdc
|
|
| BLAKE2b-256 |
faf33264406f17b8ccacb3009eeab32c416e0cffd2de6e5cd44c213394672dc8
|
File details
Details for the file aethermagic-0.0.4-py3-none-any.whl.
File metadata
- Download URL: aethermagic-0.0.4-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b4e50e7076aa5af079d05e64325bb8fc334e3b392dd23fffa2409a06804ea35
|
|
| MD5 |
050175be753488eff868ebeb90c512d1
|
|
| BLAKE2b-256 |
aab2f8c608fae4fb5d368612344845483f46acc884695161e9ba3f8d2e606c7e
|