Skip to main content

No project description provided

Reason this release was yanked:

doesn't work

Project description

MessageFlux

License: GPL v3

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 #TODO: make examples

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


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.2a0.tar.gz (46.5 kB view details)

Uploaded Source

Built Distribution

messageflux-0.0.2a0-py3-none-any.whl (33.0 kB view details)

Uploaded Python 3

File details

Details for the file messageflux-0.0.2a0.tar.gz.

File metadata

  • Download URL: messageflux-0.0.2a0.tar.gz
  • Upload date:
  • Size: 46.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.7

File hashes

Hashes for messageflux-0.0.2a0.tar.gz
Algorithm Hash digest
SHA256 0f407c45dff2d81f715547037ecc112f35c1cc6f0b7124426629735c2fe14072
MD5 d70f8c4d1aeac719d72235d2f00c4470
BLAKE2b-256 9506ea49471e47a8967158b67358ea5119bc366f677c3052cba1ab08b5263a7f

See more details on using hashes here.

File details

Details for the file messageflux-0.0.2a0-py3-none-any.whl.

File metadata

File hashes

Hashes for messageflux-0.0.2a0-py3-none-any.whl
Algorithm Hash digest
SHA256 286de551e9603a6bd534661d81bf84ed4fa50da56ef64a10ad1e09f8dc72f932
MD5 b60e9efde52743d2d12d771c3b937ac7
BLAKE2b-256 0d2f22ab7efb451ba2f0b170d576093326e7685c95aa6b6b65f27998eeaccf9a

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