No project description provided
Reason this release was yanked:
doesn't work
Project description
MessageFlux
this package helps create long running services (that may handle items that comes from devices)
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 SingleMessageDeviceReaderService, InputDevice, ReadResult
from messageflux.iodevices.in_memory_device import InMemoryDeviceManager
class MyExampleService(SingleMessageDeviceReaderService):
def _handle_single_message(self, input_device: InputDevice, read_result: ReadResult):
message = read_result.message
# Do somthing with the message...
input_device_manager = InMemoryDeviceManager()
# write messages to devices here...
my_example_service = MyExampleService(input_device_manager=input_device_manager,
input_device_names=['MY_QUEUE'])
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 SingleMessageDeviceReaderService, InputDevice, ReadResult
from messageflux.multiprocessing import get_service_runner, ServiceFactory
class MyExampleService(SingleMessageDeviceReaderService):
def _handle_single_message(self, input_device: InputDevice, read_result: ReadResult):
message = read_result.message
# Do somthing with the message...
class MyServiceFactory(ServiceFactory):
def create_service(self) -> MyExampleService:
# 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 = MyExampleService(input_device_manager=input_device_manager,
input_device_names=['MY_QUEUE'])
return my_example_service
service_to_run = get_service_runner(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 device
- messageflux[dev] - for running tests and developing for this package
- messageflux[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.0.3.tar.gz
(45.1 kB
view details)
Built Distribution
File details
Details for the file messageflux-0.0.3.tar.gz
.
File metadata
- Download URL: messageflux-0.0.3.tar.gz
- Upload date:
- Size: 45.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5c19a79887a9af7bec9ce2b03b019ec3c7f7c6ce046149b5f5e032a1f51d246 |
|
MD5 | 6235e831b3563c03e5fd03abb5b51b67 |
|
BLAKE2b-256 | ea6a29cc8b7900dc3654ef3f8bf0172c6da7a9d307978f6e8ecea8c590928ebf |
File details
Details for the file messageflux-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: messageflux-0.0.3-py3-none-any.whl
- Upload date:
- Size: 33.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d2311dcfa8aa87a0827e09700981d64a7c5e5171535ccd9707604b769125d10 |
|
MD5 | e0588241e0925f2af33009c061bdb966 |
|
BLAKE2b-256 | 1a541bbdf4f91eff02a08510a205cfa3e58464054453cca7e9374a687dedcf63 |