Skip to main content

No project description provided

Project description

Generic Consumer

A flexible Python library for implementing consumer patterns with a focus on payload processing and queue management.

Overview

Generic Consumer provides a framework for creating consumer classes that can process data payloads from various sources. It supports both synchronous and asynchronous processing with features like:

  • Prioritized execution order
  • Payload preprocessing
  • Conditional activation
  • Nested consumer hierarchies
  • Robust error handling
  • Customizable logging

Installation

Using pip

pip install generic-consumer

Quick Start

from generic_consumer import GenericConsumer

class MyConsumer(GenericConsumer):
    # Set the queue this consumer responds to
    @classmethod
    def queue_name(cls):
        return "my_queue"
    
    # Define where to get payloads from
    def get_payloads(self):
        return [1, 2, 3, 4, 5]
    
    # Process a single payload
    def process_one(self, payload):
        print(f"Processing: {payload}")
        
# Run all consumers for a queue
GenericConsumer.start("my_queue")

Key Features

Consumer Configuration

  • queue_name: Define which queue a consumer belongs to
  • priority_number: Set execution priority (lower numbers run first)
  • condition: Determine whether a consumer should run based on runtime conditions
  • enabled: Toggle consumer activation
  • process_empty_payloads: Handle cases where no payloads are available
  • passive: Create consumers that monitor but don't process (useful for logging)

Processing Pipeline

  1. get_payloads: Retrieve data to be processed
  2. payload_preprocessors: Transform payloads before processing
  3. process: Handle batch processing of all payloads
  4. process_one: Process individual payloads

Utility Methods

  • start_all/start: Run all consumers for a given queue
  • print_available_consumers: Display all registered consumers and their configurations
  • run: Execute a specific consumer
  • run_all: Execute all consumers

Advanced Usage

Passive Consumers

Use PassiveConsumer for monitoring or logging without modifying data:

from generic_consumer import PassiveConsumer

class LoggingConsumer(PassiveConsumer):
    @classmethod
    def queue_name(cls):
        return "my_queue"
    
    def process(self, payloads):
        print(f"Observed {len(payloads)} items")

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

generic_consumer-0.19.1.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

generic_consumer-0.19.1-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file generic_consumer-0.19.1.tar.gz.

File metadata

  • Download URL: generic_consumer-0.19.1.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.12.3 Linux/6.11.0-19-generic

File hashes

Hashes for generic_consumer-0.19.1.tar.gz
Algorithm Hash digest
SHA256 8b02d25cec9c504fc1a7159932739dde3d9c9705f76cc6f10aee34fa327536c4
MD5 78be4fc3fc690e55730c78cc4c290cbe
BLAKE2b-256 da06921649402a64f3930136499b5b52620eb489e02a3ec85b90ba7c4128f38e

See more details on using hashes here.

File details

Details for the file generic_consumer-0.19.1-py3-none-any.whl.

File metadata

  • Download URL: generic_consumer-0.19.1-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.12.3 Linux/6.11.0-19-generic

File hashes

Hashes for generic_consumer-0.19.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ed80cf73ccdd4e4b9b54c3c71e0069739f5af2c7135476283e127ddc3031db39
MD5 b9d024cdd0d0fd4c1b31aad673008265
BLAKE2b-256 d635d966fd894a1f32e03030687f7c7c2ff4bfa7c70408adbc025b0d78cf5c76

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page