Skip to main content

A queue framework

Project description

Romeways

by: CenturyBoys

This project has as goal help developers to not reimplemented default queue consumer behaviour.

Basics

Romeways works with two basic concepts queue handler and queue connector. The queue connector is a queue consumer and can be spawned in a separate process or in async worker. The queue handler is the callback function that will be called for each retrieved message.

Here you can see all implemented consumer:

Queue Type Install using extra description
multiprocessing.Queue memory here

How to install extra packages?

poetry add romeways -E memory
OR
pip install 'romeways[memory]'

Configuration

Queue connector config

The queue connector config is all configurations that you need to be able to retrieve messages from the queue.

Bellow are the romeways.GenericConnectorConfig implementation. This class can be inheritance to allow extra configurations.

Params:

  • connector_name: str For what connector this queue must be delivered
from dataclasses import dataclass


@dataclass(slots=True, frozen=True)
class GenericConnectorConfig:
    """
    connector_name: str Connector name
    """
    connector_name: str

Queue handler config

When you register a queue consumer you are setting configs and a callback handler for each message that this queue receives.

Bellow are the romeways.GenericQueueConfig implementation. This class can be inheritance to allow extra configurations.

Params:

  • connector_name: str For what connector this queue must be delivered
  • frequency: float Time in seconds for retrieve messages from queue
  • max_chunk_size: int Max quantity for messages that one retrieve will get
  • sequential: bool If the handler call must be sequential or in asyncio.gather
from dataclasses import dataclass


@dataclass(slots=True, frozen=True)
class GenericQueueConfig:
    """
    connector_name: str For what connector this queue must be delivered
    frequency: float Time in seconds for retrieve messages from queue
    max_chunk_size: int Max quantity for messages that one retrieve will get
    sequential: bool If the handler call must be sequential or in asyncio.gather
    """
    connector_name: str
    frequency: float
    max_chunk_size: int
    sequential: bool

Resend on error

Romeways allow you to resend the message to the queue if something in your handler do not perform correctly. For that your code need tho raise the romeways.ResendException exception, the message will be resent to the same queue and the romeways.Message.rw_resend_times parameter will be raized

Spawn a process

Romeways can run each connector in a separate process or in async workers for that use the parameter spawn_process to configure that.

Example

For this example we are using the extra memory

from multiprocessing import Queue

import romeways

# Create a queue config
config_q = romeways.MemoryQueueConfig(
    connector_name="memory-dev1"
)

# Register a controller/consumer for the queue name
@romeways.queue_consumer(queue_name="queue.payment.done", config=config_q)
async def controller(message: romeways.Message):
    print(message)

# Config the connector
queue = Queue()

config_p = romeways.MemoryConnectorConfig(connector_name="memory-dev1", queue=queue)

# Register a connector
romeways.connector_register(
    connector=romeways.MemoryQueueConnector, config=config_p, spawn_process=True
)

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

rome_ways-0.1.1.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

rome_ways-0.1.1-py3-none-any.whl (21.0 kB view details)

Uploaded Python 3

File details

Details for the file rome_ways-0.1.1.tar.gz.

File metadata

  • Download URL: rome_ways-0.1.1.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.10.6 Linux/5.19.0-41-generic

File hashes

Hashes for rome_ways-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e653f067ef8dde1533999afdc245279ada58bbc50830455efbfac929a24c1e7c
MD5 d2917ea251fd67b23b075583583ee263
BLAKE2b-256 80c15fa4adfb64bda12749afca8d9a4a774912346faa3ecbb2ca88520380d020

See more details on using hashes here.

File details

Details for the file rome_ways-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: rome_ways-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 21.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.10.6 Linux/5.19.0-41-generic

File hashes

Hashes for rome_ways-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9f47e63314905b518128b7f6da1a0a3a16301714e0bdab630a362e4b9148ff10
MD5 0c9e7bd2607159197d33b841a2041693
BLAKE2b-256 3f9bd4b9fa2c1b8e3349435e5b158b260f8efd5d0d897ed015abffede9343e8e

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