Skip to content

Commit

Permalink
Merge branch 'release/v0.7.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
wallyqs committed Jun 13, 2018
2 parents 7518aa4 + 6038b3d commit 2494c12
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
7 changes: 3 additions & 4 deletions examples/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand All @@ -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
Expand Down
13 changes: 7 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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...")
Expand All @@ -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
Expand All @@ -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)
```
Expand Down

0 comments on commit 2494c12

Please sign in to comment.