Wrapper for pulsar-client that publishes messages asynchronously and handles consumed messages in an asyncio event loop
Project description
Pulsar AsyncIO Client
Wrapper for pulsar-client that publishes messages asynchronously and handles consumed messages in an asyncio event loop.
Installation
$ pip install pulsar-asyncio-client
Usage
import asyncio
import pulsar_asyncio
PULSAR_URL = 'pulsar://localhost:6650'
PULSAR_TOPIC = 'non-persistent://public/default/my-topic'
PULSAR_SUBSCRIPTION = 'my-sub'
async def handle_message_async(consumer, message):
message_text = message.data().decode('utf-8')
print(f"Started asynchronously handling message: {message_text}")
await asyncio.sleep(0.1)
print(f"Finished asynchronously handling message: {message_text}")
consumer.acknowledge(message)
async def main():
# Init Pulsar client
client = pulsar_asyncio.Client(PULSAR_URL)
# Start a consumer with an async message listener
consumer = client.subscribe(
PULSAR_TOPIC,
subscription_name=PULSAR_SUBSCRIPTION,
message_listener=handle_message_async
)
# Asynchronously publish some messages
producer = await client.create_producer(PULSAR_TOPIC)
for i in range(10):
message_text = f"My Message #{i}"
print(f"About to asynchronously publish message: {message_text}")
await producer.send(message_text.encode('utf-8'))
# Allow some time for all messages to be consumed
await asyncio.sleep(1)
# Stop consumer
consumer.close()
# Stop client
await client.close()
if __name__ == '__main__':
asyncio.run(main())
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
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 pulsar_asyncio_client-0.1.0.tar.gz.
File metadata
- Download URL: pulsar_asyncio_client-0.1.0.tar.gz
- Upload date:
- Size: 9.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3f4555819c33643db9278495c3a693229d06bc6f6eea9012ca6a51625d8f4fa3
|
|
| MD5 |
853bdf344f44a3ada0c3cade2a44686a
|
|
| BLAKE2b-256 |
a02e7886c1398f36ba12cc0f1db568b79bc6f4c1eb95876f4206353c384e87ac
|
Provenance
The following attestation bundles were made for pulsar_asyncio_client-0.1.0.tar.gz:
Publisher:
build-and-publish.yaml on U-238/pulsar-asyncio-client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pulsar_asyncio_client-0.1.0.tar.gz -
Subject digest:
3f4555819c33643db9278495c3a693229d06bc6f6eea9012ca6a51625d8f4fa3 - Sigstore transparency entry: 153757976
- Sigstore integration time:
-
Permalink:
U-238/pulsar-asyncio-client@dfd922949408ea438d36f4336442b4dcf78e71cb -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/U-238
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-and-publish.yaml@dfd922949408ea438d36f4336442b4dcf78e71cb -
Trigger Event:
push
-
Statement type:
File details
Details for the file pulsar_asyncio_client-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pulsar_asyncio_client-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dcec5b12ef2d07dad5ac5e446e95bb260588bc01982d99bb7b1726ede476c930
|
|
| MD5 |
a6daab6f9cc91f73317e2a6ae6ea54b0
|
|
| BLAKE2b-256 |
b2dffbd98003c134269313dbc207d06b7154302cc483f63a35ad156b0be03c52
|
Provenance
The following attestation bundles were made for pulsar_asyncio_client-0.1.0-py3-none-any.whl:
Publisher:
build-and-publish.yaml on U-238/pulsar-asyncio-client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pulsar_asyncio_client-0.1.0-py3-none-any.whl -
Subject digest:
dcec5b12ef2d07dad5ac5e446e95bb260588bc01982d99bb7b1726ede476c930 - Sigstore transparency entry: 153757977
- Sigstore integration time:
-
Permalink:
U-238/pulsar-asyncio-client@dfd922949408ea438d36f4336442b4dcf78e71cb -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/U-238
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-and-publish.yaml@dfd922949408ea438d36f4336442b4dcf78e71cb -
Trigger Event:
push
-
Statement type: