Skip to content

Commit

Permalink
Merge pull request #146 from arun11299/master
Browse files Browse the repository at this point in the history
Ability to access the connection identifier
  • Loading branch information
wallyqs committed Mar 30, 2020
2 parents 5a798b6 + e855808 commit b365db2
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions nats/aio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ def __init__(self):
self._reconnection_task = None
self._reconnection_task_future = None
self._max_payload = DEFAULT_MAX_PAYLOAD_SIZE
# This is the client id that the NATS server knows
# about. Useful in debugging application errors
# when logged with this identifier along
# with nats server log.
# This would make more sense if we log the server
# connected to as well in case of cluster setup.
self._client_id = None
self._ssid = 0
self._subs = {}
self._status = Client.DISCONNECTED
Expand Down Expand Up @@ -510,6 +517,9 @@ async def _close(self, status, do_cbs=True):
if self._closed_cb is not None:
await self._closed_cb()

# Set the client_id back to None
self._client_id = None

async def drain(self, sid=None):
"""
Drain will put a connection into a drain state. All subscriptions will
Expand Down Expand Up @@ -1015,6 +1025,13 @@ def max_payload(self):
"""
return self._max_payload

@property
def client_id(self):
"""
Returns the client id which we received from the servers INFO
"""
return self._client_id

@property
def last_error(self):
"""
Expand Down Expand Up @@ -1510,6 +1527,9 @@ async def _process_connect_init(self):
if 'max_payload' in self._server_info:
self._max_payload = self._server_info["max_payload"]

if 'client_id' in self._server_info:
self._client_id = self._server_info["client_id"]

if 'tls_required' in self._server_info and self._server_info[
'tls_required']:
ssl_context = None
Expand Down

0 comments on commit b365db2

Please sign in to comment.