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
Release history Release notifications | RSS feed
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.1.tar.gz
(16.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file timeplus_messaging-0.0.1.tar.gz.
File metadata
- Download URL: timeplus_messaging-0.0.1.tar.gz
- Upload date:
- Size: 16.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba0d5bf4a7e897f82a02005e5c43077d8ea81bc2e91b29cabc500212ab9bf93d
|
|
| MD5 |
5dcd59da1d3f3ed132c0cf802fb8bebe
|
|
| BLAKE2b-256 |
94ba0c1557ebc65e651e1aba41714baf69a5501df863b94b3582acfaa6dcea39
|
File details
Details for the file timeplus_messaging-0.0.1-py3-none-any.whl.
File metadata
- Download URL: timeplus_messaging-0.0.1-py3-none-any.whl
- Upload date:
- Size: 13.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7eb7c39809c5118c3667f33dcd965a82ad054047a4bab439ac44b78f818889ca
|
|
| MD5 |
25df4896915059004bcb1fc9905239a1
|
|
| BLAKE2b-256 |
6eec6285e04511f1d6ace93241e368160b4b3750f638c9d887afef00f8eaa448
|