-
Notifications
You must be signed in to change notification settings - Fork 127
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
nsqd Authentication Support #72
Merged
+72
−7
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,7 +76,7 @@ def __init__(self, handlers, **settings): | |
|
||
:param \*\*kwargs: passed to :class:`nsq.AsyncConn` initialization | ||
""" | ||
def __init__(self, nsqd_tcp_addresses, name=None, **kwargs): | ||
def __init__(self, nsqd_tcp_addresses, reconnect_interval=15.0, name=None, **kwargs): | ||
super(Writer, self).__init__(**kwargs) | ||
|
||
if not isinstance(nsqd_tcp_addresses, (list, set, tuple)): | ||
|
@@ -88,6 +88,8 @@ def __init__(self, nsqd_tcp_addresses, name=None, **kwargs): | |
self.nsqd_tcp_addresses = nsqd_tcp_addresses | ||
self.conns = {} | ||
self.conn_kwargs = kwargs | ||
assert isinstance(reconnect_interval, (int, float)) | ||
self.reconnect_interval = reconnect_interval | ||
|
||
self.io_loop.add_callback(self._run) | ||
|
||
|
@@ -123,7 +125,13 @@ def _pub(self, command, topic, msg, callback): | |
logging.exception('[%s] failed to send %s' % (conn.id, command)) | ||
conn.close() | ||
|
||
def _on_connection_response(self, conn, data, **kwargs): | ||
def _on_connection_error(self, conn, error, **kwargs): | ||
super(Writer, self)._on_connection_error(conn, error, **kwargs) | ||
while conn.callback_queue: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good catch |
||
callback = conn.callback_queue.pop(0) | ||
callback(conn, error) | ||
|
||
def _on_connection_response(self, conn, data=None, **kwargs): | ||
if conn.callback_queue: | ||
callback = conn.callback_queue.pop(0) | ||
callback(conn, data) | ||
|
@@ -140,7 +148,9 @@ def connect_to_nsqd(self, host, port): | |
conn = async.AsyncConn(host, port, **self.conn_kwargs) | ||
conn.on('identify', self._on_connection_identify) | ||
conn.on('identify_response', self._on_connection_identify_response) | ||
conn.on('error', self._on_connection_response) | ||
conn.on('auth', self._on_connection_auth) | ||
conn.on('auth_response', self._on_connection_auth_response) | ||
conn.on('error', self._on_connection_error) | ||
conn.on('response', self._on_connection_response) | ||
conn.on('close', self._on_connection_close) | ||
conn.on('ready', self._on_connection_ready) | ||
|
@@ -173,10 +183,10 @@ def _on_connection_close(self, conn, **kwargs): | |
logging.exception('[%s] uncaught exception in callback', conn.id) | ||
|
||
logging.warning('[%s] connection closed', conn.id) | ||
logging.info('[%s] attempting to reconnect in 15s', conn.id) | ||
logging.info('[%s] attempting to reconnect in %0.2fs', conn.id, self.reconnect_interval) | ||
reconnect_callback = functools.partial(self.connect_to_nsqd, | ||
host=conn.host, port=conn.port) | ||
self.io_loop.add_timeout(time.time() + 15, reconnect_callback) | ||
self.io_loop.add_timeout(time.time() + self.reconnect_interval, reconnect_callback) | ||
|
||
def _finish_pub(self, conn, data, command, topic, msg): | ||
if isinstance(data, nsq.Error): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these two lines can be simplified to
self._authentication_required = data.get('auth_required', False)