Added
- Support for `drain mode` (https://github.com/nats-io/asyncio-nats/pull/82)
This feature allows clients to gracefully disconect, letting the subscribers
handle any inflight messages that may have been sent by the server already.
python
async def handler(msg):
print("[Received] ", msg)
await nc.publish(msg.reply, b'I can help')
Can check whether client is in draining state
if nc.is_draining:
print("Connection is draining")
await nc.subscribe("help", "workers", cb=handler)
requests = []
for i in range(0, 1000):
request = nc.request("help", b'help!', 0.2)
requests.append(request)
Wait for all the responses
responses = await asyncio.gather(*requests)
print("Received {} responses", len(responses))
Gracefully close the connection.
await nc.drain()
Example usage can be found at:
https://github.com/nats-io/asyncio-nats/blob/e1996e7c4ae30daa63c49af20700d42fad1bd2f2/examples/drain-sub.py
- Support for `no_echo` mode (https://github.com/nats-io/asyncio-nats/pull/74)
When connected to a NATS Server v1.2.0 or above, a client can now opt to avoid
receiving messages that it itself has published.
python
await ncA.connect(no_echo=True)
await ncB.connect()
async def handler(msg):
Messages sent by `ncA' will not be received.
print("[Received] ", msg)
await ncA.subscribe("greetings", cb=handler)
await ncA.publish("greetings", b'Hello World!')
await ncB.publish("greetings", b'Hello World!')
- Added `connect_timeout` option to disconnect from unhealthy servers in the pool (https://github.com/nats-io/asyncio-nats/pull/83/files)
python
Give up if can't connect to a server in 5 seconds
await nc.connect("demo.nats.io:4222", connect_timeout=5)
- Added `loop` parameter to connect to set the event loop like in `asyncio` APIs
python
await nc.connect("demo.nats.io", loop=asyncio.new_event_loop())
Improved
- `connect` API is now modeled to work more closely to how the Go client works:
python
Assume 'nats://' scheme
await nc.connect("demo.nats.io:4222")
Complete with scheme a la Go client classic usage.
await nc.connect("nats://demo.nats.io:4222")
Use default 4222 port.
await nc.connect("demo.nats.io")
Explicit cluster list
await nc.connect(servers="demo.nats.io")
Fixed
- Examples and tests now support Python 3.7 (https://github.com/nats-io/asyncio-nats/issues/71)
- Added `user`, `password`, `token` parameters to set the auth credentials for servers that were discovered implicitly. (https://github.com/nats-io/asyncio-nats/commit/f8c28b346fd5fbc852b7e046edf0ef4810cdf823)
python
Set user and info credentials
await nc.connect("127.0.0.1:4222", user="foo", password="bar")
Token
await nc.connect("127.0.0.1:4222", token="secretoken")
Changed
- Examples were changed to use `async`/ `await` instead of `asyncio.coroutine` and `yield from` (https://github.com/nats-io/asyncio-nats/commit/e1996e7c4ae30daa63c49af20700d42fad1bd2f2)
Deprecated
- Removed Python 3.4 from build (https://github.com/nats-io/asyncio-nats/commit/b2ee929367d3bf6b06bed0ab32e3a9f27b041747)
- Tests are now using `async`/`await` syntax throughout (https://github.com/nats-io/asyncio-nats/pull/78)
In the next v1.0 release client will be solely using `async`/`await` syntax (https://github.com/nats-io/asyncio-nats/issues/68)