Skip to main content

No project description provided

Project description

MessageFlux

stars license last commit tests pypi version python compatibility downloads

This package is used to create long-running services, that read messages from devices, and handles them. The devices in this package are meant to be composable - meaning that added functionality can come from wrapping devices in other 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 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 device
  • messageflux[objectstorage] - for using the s3 device wrappers
  • 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.1.0.tar.gz (73.5 kB view details)

Uploaded Source

Built Distribution

messageflux-0.1.0-py3-none-any.whl (102.3 kB view details)

Uploaded Python 3

File details

Details for the file messageflux-0.1.0.tar.gz.

File metadata

  • Download URL: messageflux-0.1.0.tar.gz
  • Upload date:
  • Size: 73.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.7

File hashes

Hashes for messageflux-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5dd3325bca8b7879898828faa20abe8ee5d84d164cd458af39948d9fe86d67bb
MD5 0e703c5ae50730b21a65bd868c0a6a9f
BLAKE2b-256 565550ac8fd8de31e71f94fe178f3e0d833d5285385ae023319f4e60fb406687

See more details on using hashes here.

File details

Details for the file messageflux-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: messageflux-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 102.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.7

File hashes

Hashes for messageflux-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b34cd8f6228bb6933c57a6bdffc96315f6d12066192ceee9722383483456b6c8
MD5 3e6a3bfcadcb7a567602da0c2ccd9ad7
BLAKE2b-256 f5e26a0de892f1b31ee3bf81b00dfa383bd80087034d268627a4fb7f833a1ea0

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