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.3.tar.gz
(16.2 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.3.tar.gz.
File metadata
- Download URL: timeplus_messaging-0.0.3.tar.gz
- Upload date:
- Size: 16.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9799507fc54a45510ed16094f3c6d738723e5c9f42e0fdeebb511601bce5f0ed
|
|
| MD5 |
3df257ad2071f0a9f552b501272f6339
|
|
| BLAKE2b-256 |
8f2f8f1a59f29c6dee1050d9efc0034fb0863edee49a222b03f1d232644d12ce
|
File details
Details for the file timeplus_messaging-0.0.3-py3-none-any.whl.
File metadata
- Download URL: timeplus_messaging-0.0.3-py3-none-any.whl
- Upload date:
- Size: 13.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e603467d7e692f8cd9152cddf36b38bd6fc00f0d446369401bb71b262cabcd14
|
|
| MD5 |
c5e8f60a7ef607f6d25112f41d2e5024
|
|
| BLAKE2b-256 |
74fa1f170f900f8b3285d74f5c9c3265e5358571b78c15bd92a18dd6d2d22ca4
|