This release is a pre-release and may not be stable for production use.
Python MQTT based microservice base daemon
Since this is a recurring task this project contains a base implementation for a simple MQTT based service that offers just some basic features required for simple MQTT based microservices:
- Daemonizing
- PID file handling
- Log file handling
- Handling signals like SIGHUP and SIGTERM
- Connecting to an MQTT service using the Paho MQTT client, keeping the connection active
- Processing JSON configuration files to gather MQTT configuration and reloading of that configuration
- Allowing to specify topics relative to a base topic
Services are able to simply subclass and implement their own message processing functions. This makes life a little bit easier. This repository also implements some client utilities that wrap the Paho MQTT library that implement a similar pattern.
Note that this library does not work when subscribing to a huge number of topics with different handlers since it uses an own callback registration mechanism that all messages go through. It also does not work well when one wants to dynamically register or unregister from topics. Also in it's current implementation it linearly iterates over all registered handlers for each message and does not use any kind of trie.
Usage
The most simple usage possible just registers topic handlers and reacts to the received messages.
from mqttservice import mqttbaseservice
class EchoService(mqttbaseservice.MQTTBaseService):
def __init__(self):
super().__init__(
applicationName = "MQTTEchoService",
topicHandlers = [
{ 'topic' : 'echoservice/echo', 'handler' : [ self._handleEchoRequestMessage ] }
]
)
def _handleEchoRequestMessage(self, topic, msg):
self._logger.debug("Received echo request")
self.mqttPublish('echoservice/reply', { 'some' : "payload", 'will' : "be serialized", 'to' : "JSON from dict" })
def __enter__(self):
return self
def __exit__(self, type, value, tb):
pass
if __name__ == "__main__":
with EchoService() as service:
service.main()
Metadata
Release files for pymqttmicroservicebase-tspspi 0.0.1a0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pymqttmicroservicebase-tspspi-0.0.1a0.tar.gz | 8.2 kB | Without provenance | Details for pymqttmicroservicebase-tspspi-0.0.1a0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pymqttmicroservicebase_tspspi-0.0.1a0-py3-none-any.whl | Python 3 | none | any | Details for pymqttmicroservicebase_tspspi-0.0.1a0-py3-none-any.whl |
Total release size: 16.2 kB
Release files / pymqttmicroservicebase-tspspi-0.0.1a0.tar.gz
| Download URL | pymqttmicroservicebase-tspspi-0.0.1a0.tar.gz |
|---|---|
| Size | 8.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0725af89d9fae33d27429bfb53556b18aceaae7c8b2b3e6ae6499ea3c882bf6d
|
|
BLAKE2b-256 checksum How to use checksums |
c74aa69ec48d6dd8f849b0c032120d418ba56e34d7e05de88e327f6c3e240944
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.8.13
|
Release files / pymqttmicroservicebase_tspspi-0.0.1a0-py3-none-any.whl
| Download URL | pymqttmicroservicebase_tspspi-0.0.1a0-py3-none-any.whl |
|---|---|
| Size | 8.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f6be04b1dd131d9bd60e75b834a08ddac7bd6d98da686f757a86406c386493ba
|
|
BLAKE2b-256 checksum How to use checksums |
7bad72b87ce399f7e074c4afef461650005ef7de57e2611f14cc01271a4de35c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.8.13
|
Security for pymqttmicroservicebase-tspspi 0.0.1a0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.