Skip to content

An easy and intuitive way to create Pipeline Handlers for MessageFlux

License

Notifications You must be signed in to change notification settings

Avivsalem/FastMessage

Repository files navigation

FastMessage

stars license last commit tests Documentation Status pypi version python compatibility downloads

FastMessage is an easy framework to create PipelineHandlers for MessageFlux

You can find the full documentation here

Requirements

Python 3.7+

Installation

$ pip install fastmessage

Examples

from fastmessage import FastMessage, OtherMethodOutput
from messageflux.iodevices.rabbitmq import RabbitMQInputDeviceManager, RabbitMQOutputDeviceManager

fm = FastMessage()


@fm.map()
def hello(name: str, birthYear: int):
    age = 2023 - birthYear
    print(f'Hello {name}. your age is {age}')
    return OtherMethodOutput(next_year, age=age)  # this sends its output to 'next_year' method


@fm.map()
def next_year(age: int):
    print(f'next year you will be {age + 1}')


if __name__ == "__main__":
    input_device_manager = RabbitMQInputDeviceManager(hosts='my.rabbit.host',
                                                      user='username',
                                                      password='password')

    output_device_manager = RabbitMQOutputDeviceManager(hosts='my.rabbit.host',
                                                        user='username',
                                                        password='password')

    service = fm.create_service(input_device_manager=input_device_manager,
                                output_device_manager=output_device_manager)
    service.start()  # this runs the PipelineService and blocks

This example shows two methods: hello and next_year, each listening on its own queue (with the same name)

the __main__ creates an input and output device managers (RabbitMQ in this case), and starts the service with these devices.

every message that is sent to the hello queue should have the following format:

{
  "name": "john",
  "birthYear": 1999
}

in that case the process will print (in 2023...):

Hello john. your age is 24
next year you will be 25

About

An easy and intuitive way to create Pipeline Handlers for MessageFlux

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages