Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to access the connection identifier #146

Merged
merged 3 commits into from
Mar 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1014,6 +1024,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 @@ -1509,6 +1526,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