Skip to main content

Messaging library for Timeplus streams

Project description

Timeplus Messaging

A Python package for messaging with Timeplus streams. This library provides a simplified messaging interface on top of Timeplus, supporting message publishing and consumption patterns similar to traditional messaging systems.

Features

  • Producer API: Easily send messages to Timeplus streams
  • Consumer API: Consume messages from one or multiple Timeplus streams
  • Topic-based messaging: Use Timeplus streams as message topics
  • Message headers support: Include metadata with your messages
  • Batch consumption: Efficiently poll for multiple messages
  • Pause/resume capability: Control consumption flow
  • Stream auto-creation: Automatically create streams as needed
  • Callback-based processing: Register callbacks for specific topics

Installation

pip install timeplus-messaging

Requirements

  • Python 3.7 or higher
  • proton-driver (Timeplus client driver)

Quick Start

Producer Example

from timeplus_messaging import create_producer

# Create a producer
producer = create_producer(
    host="your-timeplus-host",
    port=8463,
    user="default",
    password="your-password",
    database="default"
)

# Send a simple message
producer.send(
    topic="my_topic",
    value="Hello, Timeplus!",
    key="greeting"
)

# Send a JSON message
producer.send(
    topic="my_topic",
    value={"message": "Hello, Timeplus!", "priority": "high"},
    headers={"source": "application", "version": "1.0"}
)

# Close the producer
producer.close()

Single Topic Consumer Example - Kafka Style

from timeplus_messaging import create_consumer

# Create a single topic consumer
consumer = create_consumer(
    topic="my_topic",
    host="your-timeplus-host",
    port=8463,
    user="default",
    password="your-password",
    database="default",
    auto_offset_reset="latest"  # or "earliest"
)

# Poll for messages
records = consumer.poll(timeout_ms=5000)
for topic, messages in records.items():
    for message in messages:
        print(f"Received: {message.value} with key={message.key}")

# Use as iterator
for record in consumer:
    print(f"Received: {record.value}")
    # Break out of the loop after processing
    break

# Close the consumer
consumer.close()

Multi-Topic Consumer Example - Queue Style

from timeplus_messaging import create_subscribe_consumer

# Create a multi-topic consumer
consumer = create_subscribe_consumer(
    host="your-timeplus-host",
    port=8463,
    user="default",
    password="your-password",
    database="default",
    auto_offset_reset="latest"
)


# Add a callback for a specific topic
def process_message(record):
    print(f"Callback received: {record.value}")

# Subscribe to multiple topics
consumer.subscribe(["topic1", "topic2"], callback=process_message)

# wait all message to be consumed
time.sleep(10) 

# Unsubscribe from topic
consumer.unsubscribe("topic2")

# Close the consumer
consumer.close()

Advanced Usage

Using Consumer Callbacks

from timeplus_messaging import create_subscribe_consumer

consumer = create_subscribe_consumer(
    host="your-timeplus-host",
    port=8463,
    user="default",
    password="your-password"
)

def process_logs(record):
    print(f"Log received: {record.value}")
    # Process log message
    
def process_metrics(record):
    print(f"Metric received: {record.value}")
    # Process metric data

# Subscribe with callbacks
consumer.subscribe("logs", callback=process_logs)
consumer.subscribe("metrics", callback=process_metrics)

License

MIT

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

timeplus_messaging-0.0.2.tar.gz (16.1 kB view details)

Uploaded Source

Built Distribution

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

timeplus_messaging-0.0.2-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file timeplus_messaging-0.0.2.tar.gz.

File metadata

  • Download URL: timeplus_messaging-0.0.2.tar.gz
  • Upload date:
  • Size: 16.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.12

File hashes

Hashes for timeplus_messaging-0.0.2.tar.gz
Algorithm Hash digest
SHA256 7a414193c316a585683ecae49e148c82188350c7aa5c0bf902557f49ed28aa18
MD5 3a11bd88d7d8791b2455ec1022aa10eb
BLAKE2b-256 9711ce5a182b5eb82547f1362899e1d534a9739cb0aab5b56766030403d51c1e

See more details on using hashes here.

File details

Details for the file timeplus_messaging-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for timeplus_messaging-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 19b57254df7b521813e5c86315f3c0ee45b0d6dfc5281b958da42f72413f9639
MD5 d958348076c7a8a9d256395f6d8fcada
BLAKE2b-256 1fd1209e6ada6ae67ad39a5f92ba17bfbbd7181f7cf72490549ba88db1d41964

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