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.5.tar.gz
(45.0 kB
view details)
Built Distribution
File details
Details for the file messageflux-0.0.5.tar.gz
.
File metadata
- Download URL: messageflux-0.0.5.tar.gz
- Upload date:
- Size: 45.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | abf21c3881e72f8c01f06dbb2aadcb0ad3e2b93725a8960a02e462324ef86773 |
|
MD5 | d9bf33c670ed0daeeabb4b043ec1f5d8 |
|
BLAKE2b-256 | e9395405b58ff937bfa7ce476a687c3de6ea8f697b9bec7ca80f7c6a4b3247d9 |
File details
Details for the file messageflux-0.0.5-py3-none-any.whl
.
File metadata
- Download URL: messageflux-0.0.5-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 | 57c46c577b8dd24b491d905d934319de26c74bc981ef313299b13e459c896cdd |
|
MD5 | ff0b1ebc4dfeb5da3df5391a38d9c539 |
|
BLAKE2b-256 | 15b94072d517e171d29bed49ea41e85a1d6f7f12e280da580f25a71864b024cd |