Comments (3)
Hi @gitdlam thanks for the feedback, I will be adding more examples... Here below there is a snippet of how subscriptions work that I can add to the repo. Let me know if it works for you.
import asyncio
from nats.aio.client import Client as NATS
def run(loop):
nc = NATS()
options = {
"servers": ["nats://127.0.0.1:4222"],
"io_loop": loop
}
yield from nc.connect(**options)
print("Connected to NATS at {}...".format(nc.connected_url.netloc))
@asyncio.coroutine
def subscribe_handler(msg):
subject = msg.subject
reply = msg.reply
data = msg.data.decode()
print("Received a message on '{subject} {reply}': {data}".format(
subject=subject, reply=reply, data=data))
# Basic subscription to receive all published messages
# which are being sent to a single topic 'discover'
yield from nc.subscribe("discover", cb=subscribe_handler)
# Subscription on queue named 'workers' so that
# one subscriber handles a request at a time.
yield from nc.subscribe("help.*", "workers", subscribe_handler)
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(run(loop))
try:
loop.run_forever()
finally:
loop.close()
from nats.py.
Thanks @wallyqs for the quick response. This example is perfect!!!
from nats.py.
Good to hear that it helped, I added a couple more examples to the repo and some basic tools:
https://github.com/nats-io/asyncio-nats/blob/master/examples/nats-sub/__main__.py
https://github.com/nats-io/asyncio-nats/blob/master/examples/context-manager.py
Thanks for the feedback again!
from nats.py.
Related Issues (20)
- Publishers on same subject don't get processed in prallel HOT 3
- Can't install version 2.2.0 HOT 9
- Unable to connect using Bcrypted password HOT 1
- Add compression field for stream config
- ping/pong is not working HOT 1
- msg.ack_sync(timeout=15.0) but acknowledgment floor stays at 8 HOT 2
- CERTIFICATE_VERIFY_FAILED HOT 2
- Message publish failure after reconnection
- Jetstream no available responders HOT 1
- published wheels would be really helpful
- [JetStream] Publishing to a subject without stream will fail in nats.errors.TimeoutError
- Object Store replication from LeafNode to Cluster nats: error: nats: no stream matches subject HOT 2
- Placement setting has no effect when creating a new key-value bucket HOT 1
- Using the async iterator is significantly slower compared to using callbacks in a subscription
- Implement Consumer Pause
- Upon reconnect in k8s, python nats client does not receive messages
- Client does not handle connect URL containing multiple servers HOT 4
- nats-py broken while running opentelemetry instrumentation 0.44b0
- Add Service API HOT 3
- KV should raise an error if the key contains unacceptable characters
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nats.py.