github nats-io/nats.py v0.8.0
Release v0.8.0

latest releases: v2.8.0, v2.7.2, v2.7.0...
5 years ago

Added

  • Support for drain mode (#82)

    This feature allows clients to gracefully disconect, letting the subscribers
    handle any inflight messages that may have been sent by the server already.

    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 (#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.

    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)

    # 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

    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:

    # 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 (#71)

  • Added user, password, token parameters to set the auth credentials for servers that were discovered implicitly. (f8c28b3)

    # 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 (e1996e7)

Deprecated

  • Removed Python 3.4 from build (b2ee929)

  • Tests are now using async/await syntax throughout (#78)
    In the next v1.0 release client will be solely using async/await syntax (#68)

Don't miss a new nats.py release

NewReleases is sending notifications on new releases.