From 6038b3df1dee826743fcd32974ccbe2784f63686 Mon Sep 17 00:00:00 2001 From: Waldemar Quevedo Date: Wed, 13 Jun 2018 14:32:09 -0700 Subject: [PATCH] Update readme examples Signed-off-by: Waldemar Quevedo --- examples/example.py | 7 +++---- readme.md | 13 +++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/examples/example.py b/examples/example.py index 8184fcb..83bd677 100644 --- a/examples/example.py +++ b/examples/example.py @@ -20,14 +20,12 @@ from nats.io.utils import new_inbox from nats.io.client import Client as NATS - @tornado.gen.coroutine def main(): nc = NATS() # Establish connection to the server. - options = {"verbose": True, "servers": ["nats://127.0.0.1:4222"]} - yield nc.connect(**options) + yield nc.connect(servers=["nats://127.0.0.1:4222"]) def discover(msg=None): print("[Received]: %s" % msg.data) @@ -53,7 +51,7 @@ def help_request_handler(msg): try: # Expect a single request and timeout after 500 ms - response = yield nc.timed_request( + response = yield nc.request( "help", "Hi, need help!", timeout=0.500) print("[Response]: %s" % response.data) except tornado.gen.TimeoutError, e: @@ -63,6 +61,7 @@ def help_request_handler(msg): def many_responses(msg=None): print("[Response]: %s" % msg.data) + # Async request expecting many responses yield nc.request("help", "please", expected=2, cb=many_responses) # Publish inbox diff --git a/readme.md b/readme.md index a268c19..51eeaf1 100644 --- a/readme.md +++ b/readme.md @@ -25,21 +25,19 @@ pip install nats-client ## Basic Usage ```python -# coding: utf-8 import tornado.ioloop import tornado.gen import time from datetime import datetime -from nats.io.utils import new_inbox -from nats.io import Client as NATS +from nats.io.utils import new_inbox +from nats.io.client import Client as NATS @tornado.gen.coroutine def main(): nc = NATS() # Establish connection to the server. - options = { "verbose": True, "servers": ["nats://127.0.0.1:4222"] } - yield nc.connect(**options) + yield nc.connect(servers=["nats://127.0.0.1:4222"]) def discover(msg=None): print("[Received]: %s" % msg.data) @@ -65,7 +63,8 @@ def main(): try: # Expect a single request and timeout after 500 ms - response = yield nc.timed_request("help", "Hi, need help!", timeout=0.5) + response = yield nc.request( + "help", "Hi, need help!", timeout=0.500) print("[Response]: %s" % response.data) except tornado.gen.TimeoutError, e: print("Timeout! Need to retry...") @@ -74,6 +73,7 @@ def main(): def many_responses(msg=None): print("[Response]: %s" % msg.data) + # Async request expecting many responses yield nc.request("help", "please", expected=2, cb=many_responses) # Publish inbox @@ -92,6 +92,7 @@ def main(): except tornado.gen.TimeoutError, e: print("Timeout! Roundtrip too slow...") + if __name__ == '__main__': tornado.ioloop.IOLoop.instance().run_sync(main) ```