No project description provided
Project description
MessageFlux
messageflux is a framework for creating long-running services, that read messages from devices, and handles them.
Devices are composable components - meaning that added functionality can come from wrapping devices in other devices.
You can find the full documentation here
Requirements
Python 3.7+
Installation
$ pip install messageflux
Extra Requirements (Example)
$ pip install messageflux[rabbitmq]
Example
Create it
- Create a file
main.py
with:
from messageflux import MessageHandlingService, MessageHandlerBase, InputDevice, ReadResult
from messageflux.iodevices.in_memory_device import InMemoryDeviceManager
class MyMessageHandler(MessageHandlerBase):
def handle_message(self, input_device: InputDevice, read_result: ReadResult):
message = read_result.message
print(f'message bytes: {message.bytes}') # Do somthing with the message...
input_device_manager = InMemoryDeviceManager()
# write messages to devices here...
my_example_service = MessageHandlingService(message_handler=MyMessageHandler(),
input_device_manager=input_device_manager,
input_device_names=['MY_QUEUE'])
if __name__ == '__main__':
my_example_service.start() # this blocks indefinitely (until CTRL-C or sigterm)
Run it
python main.py
Using Multi Processing for concurrency
from messageflux import MessageHandlingService, MessageHandlerBase, InputDevice, ReadResult
from messageflux.multiprocessing import get_service_runner, ServiceFactory
class MyMessageHandler(MessageHandlerBase):
def handle_message(self, input_device: InputDevice, read_result: ReadResult):
message = read_result.message
print(f'message bytes: {message.bytes}') # Do somthing with the message...
class MyServiceFactory(ServiceFactory):
def create_service(self) -> MessageHandlingService:
"""
we import the devices in 'create_service' so that all the imports will be in the child process.
this is only a precaution, but recommended
"""
from messageflux.iodevices.in_memory_device import InMemoryDeviceManager
input_device_manager = InMemoryDeviceManager()
# write messages to devices here...
my_example_service = MessageHandlingService(message_handler=MyMessageHandler(),
input_device_manager=input_device_manager,
input_device_names=['MY_QUEUE'])
return my_example_service
if __name__ == '__main__': # you must do this in multiprocess running
service_to_run = get_service_runner(service_factory=MyServiceFactory(),
instance_count=5) # this will run 5 child processes
service_to_run.start() # this starts the child processes and blocks indefinitely (until CTRL-C or sigterm)
Optional Requirements
messageflux[rabbitmq]
- for using the rabbitmq devicemessageflux[objectstorage]
- for using the s3 device wrappersmessageflux[dev]
- for running tests and developing for this packagemessageflux[all]
- all extras required for all devices
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
messageflux-0.1.1.tar.gz
(72.6 kB
view details)
Built Distribution
messageflux-0.1.1-py3-none-any.whl
(100.9 kB
view details)
File details
Details for the file messageflux-0.1.1.tar.gz
.
File metadata
- Download URL: messageflux-0.1.1.tar.gz
- Upload date:
- Size: 72.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c89ab4845e1705511ba4396a905db95369edad9d3e7b48a6f4bf7e66ef31486 |
|
MD5 | 24b2928b2ace47cb145f611d11342e81 |
|
BLAKE2b-256 | 1ba301456a474313fdf1138d405a710af41c3ac0e27905d032ee80e16d99c985 |
File details
Details for the file messageflux-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: messageflux-0.1.1-py3-none-any.whl
- Upload date:
- Size: 100.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c08c09a6b22def5ce99ddd970763febf4078785abb281b46adffa2469ffaa43d |
|
MD5 | 3597775f0bb662600139c20d0b8d56e2 |
|
BLAKE2b-256 | e2dc7d41bf9f6b86e1b12180edd986b3e5ad483e8a13cdde5752982957c6b016 |