Skip to main content

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:

  • complete True / False
  • success True / False
  • progress 0...100
  • input_data user-defined data to serialize into JSON
  • output_data user-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 = {}
  await ae.complete(success, output_data)
  

await AetherTask(None, 'worker', 'collect', on_perform=perform).idle()

Variables and values:

  • input_data user-defined data to serialize into JSON
  • output_data user-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


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.2.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aethermagic-0.0.2-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file aethermagic-0.0.2.tar.gz.

File metadata

  • Download URL: aethermagic-0.0.2.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for aethermagic-0.0.2.tar.gz
Algorithm Hash digest
SHA256 aed5dfe5db9c7c0bf32d23139cc0f8882ab6b1206fbb21d885187cb53491e4ee
MD5 6cb16e285bb7f5b6314bcb9316f95b5a
BLAKE2b-256 e25efd724d297cdbb8d2c3bc2ca67705b102bd3a4988989796e73b005f6d0d12

See more details on using hashes here.

File details

Details for the file aethermagic-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: aethermagic-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for aethermagic-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 86321a8c220efe9c8f0e5286d1bb39dacc275b25d3b29391b8a9f6478abfbcb3
MD5 66fd72f3a5a7ab3b5d936bda256e4915
BLAKE2b-256 c55ec08042549a44304a0c6676f2d698e6412316f688cf1f7ee909e31c902bfe

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page