Skip to main content

Python agent for microServiceBus.com. Please visit https://microservicebus.com for more information.

Project description

microservicebus-py

Installation

How to install pip package:

python3 -m pip install microservicebus-py

Overview

With the microservicebus-py Node, everything is about services communicating over a single queue managed by the Orchestrator (which is also a service). Some services are internal (inherits from BaseService), while others are custom (inherits from CustomService).

Requirements

Python 3.8

Pip3

sudo apt-get install python3-pip

Install required packages

pip install -r requirements.txt

Run using Docker

docker build -t microservicebus-py .;
docker run -it --rm microservicebus-py

BaseService (base_service)

All services inherit from BaseService either directly or through CustomService. Inheriting from BaseService provides a number of functions such as self.Debug(text) and self.SubmitMessage(message). Such methods are predefined to target specific destinations and functions. A service can also call self.SubmitAction(destination, action, message) to more flexibility is needed.

For instance, if you had a custom service called emailhandler which would send emails through the Process function and you'd like to send a message to it you would write:

message = {'to':'foo@bar.com', 'subject':'Hello', 'body':'...from foo'}
await self.SubmitAction("emailhandler", "Process", message)

Note that the action is set to "Process". All services inheriting from BaseService has a Start. Stop and Proccess function. However, you could have created a SendEmail function and set the action to "SendEmail".

If, on the other hand, you'd like to send a message to the IoT Hub you would set the destination to "com". However, there is already a simplified function called SubmitMessage predefined with both destination and action:

message = {'ts':'2021-01-01 01:01:01', 'temperature':22}
await self.SubmitMessage(message)

Similarly there is a predefined function to logging:

await self.Debug("Hello from Python")

Internal services

Internal services are used as any other service but are never stopped.

Orchestrator (orchestrator_service)

The Orchestrator is responsible for starting up services and correlate messages between then. All messages on the queue are of type QueueMessage (baseservice) and contains information such as the destination and action. When the Orchestrator receives a message on the queue, it will resolve the destination and call the function (_action).

microServiceBusHandler (msb_handler)

As the name implies the microServiceBusHandler is responsible for all communication with microServiceBus.com. When staring up the service will sign in to msb.com and set up channels for different commands in msb. After successful sign-in, the service will call the Orchestrator to start up the these services.

Logger (logger_service)

The Logger service outputs data to the terminal and forward debugging info to microServiceBusHandler if enabled

Com (downloaded at startup) (Currently not used)

The Com service is responsible for all communication with the IoT Hub provider. The only implementation as for now is the AzureIoT service.

The Com service is also responsible to handle state changes. These is expected to be a msb-state in the desired state:

"msb-state": {
    "enabled": true,
    "debug": false
},

If any of the elements in the msb-state changes, the Com service is responsible for taking actions, such as stopping and starting custom services. State changes will also get forwarded to all other services.

Com does not have any inbound functions and can not be stopped.

Custom services

All custom services inherit from BaseService and must expose the following functions:

Start

The Start function will be called when the when custom service is started. This is the where the services should start any kind of interval or work to produce readings.

Readings can be submitted using the self.SubmitMessage(message) function which forwards the message to the Process function of the Com service.

Stop

The Stop function is called as the service is getting stopped and can be used for any cleanup.

Process

The Process method can optionally be used for transmitting messages between services using the self.SubmitAction(destination, action, message) E.g

await self.SubmitAction('MyOtherService', 'Process', message)

StateUpdate

State updates received by the Com service are forwarded to all services and accessible through the StateUpdate function

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

microservicebus-py-0.0.1.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

microservicebus_py-0.0.1-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file microservicebus-py-0.0.1.tar.gz.

File metadata

  • Download URL: microservicebus-py-0.0.1.tar.gz
  • Upload date:
  • Size: 14.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.22.0 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/18.0.1 rfc3986/2.0.0 colorama/0.4.3 CPython/3.8.10

File hashes

Hashes for microservicebus-py-0.0.1.tar.gz
Algorithm Hash digest
SHA256 d66bcc947f1e145625b1a6f36080e32fd02a6cf85b1c6ee4fee979be49c0f2e1
MD5 ea998818db51ebbc6acf925abad86d1f
BLAKE2b-256 93285bee433a754679a278e527158d103bf56d716e02c01fd4e3aaa78b690fb3

See more details on using hashes here.

File details

Details for the file microservicebus_py-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: microservicebus_py-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 17.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.22.0 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/18.0.1 rfc3986/2.0.0 colorama/0.4.3 CPython/3.8.10

File hashes

Hashes for microservicebus_py-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3cbb512711baf9df9eec7763686423814bcb08d9526e70e02005687d96c32840
MD5 3e76bcffcb876392255e4e0e93e06a94
BLAKE2b-256 c4ea29325391a9eb25d2477091571e8c721b6cba7dec9e6091db66e286a787be

See more details on using hashes here.

Supported by

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