From ff7a40e74d0d860fabeed16a2f05fa12fe876e01 Mon Sep 17 00:00:00 2001 From: Flaper Fesp Date: Thu, 17 Jan 2013 22:18:00 +0000 Subject: [PATCH 1/4] avoid mongodb warning 'database name in URI is being ignored' --- kombu/transport/mongodb.py | 50 ++++++++++++++------------------------ 1 file changed, 18 insertions(+), 32 deletions(-) diff --git a/kombu/transport/mongodb.py b/kombu/transport/mongodb.py index 1a09d1f4..b31fce9b 100644 --- a/kombu/transport/mongodb.py +++ b/kombu/transport/mongodb.py @@ -15,6 +15,7 @@ from Queue import Empty import pymongo from pymongo import errors +from pymongo.uri_parser import parse_uri from anyjson import loads, dumps from pymongo.connection import Connection @@ -101,57 +102,42 @@ class Channel(virtual.Channel): See mongodb uri documentation: http://www.mongodb.org/display/DOCS/Connections """ - conninfo = self.connection.client + client = self.connection.client + hostname = client.hostname or DEFAULT_HOST + authdb = dbname = client.virtual_host - dbname = None - hostname = None - - if not conninfo.hostname: - conninfo.hostname = DEFAULT_HOST - - for part in conninfo.hostname.split('/'): - if not hostname: - hostname = 'mongodb://' + part - continue - - dbname = part - if '?' in part: - # In case someone is passing options - # to the mongodb connection. Right now - # it is not permitted by kombu - dbname, options = part.split('?') - hostname += '/?' + options - - hostname = "%s/%s" % ( - hostname, dbname in [None, "/"] and "admin" or dbname, - ) - if not dbname or dbname == "/": + if dbname in ["/", None]: dbname = "kombu_default" + authdb = "admin" + if not client.userid: + hostname = hostname.replace('/' + client.virtual_host, '/') + else: + hostname = hostname.replace('/' + client.virtual_host, + '/' + authdb) + + mongo_uri = 'mongodb://' + hostname # At this point we expect the hostname to be something like # (considering replica set form too): # # mongodb://[username:password@]host1[:port1][,host2[:port2], # ...[,hostN[:portN]]][/[?options]] - mongoconn = Connection(host=hostname, ssl=conninfo.ssl) + mongoconn = Connection(host=mongo_uri, ssl=client.ssl) + database = getattr(mongoconn, dbname) + version = mongoconn.server_info()['version'] if tuple(map(int, version.split('.')[:2])) < (1, 3): raise NotImplementedError( 'Kombu requires MongoDB version 1.3+, but connected to %s' % ( version, )) - database = getattr(mongoconn, dbname) - - # This is done by the connection uri - # if conninfo.userid: - # database.authenticate(conninfo.userid, conninfo.password) self.db = database col = database.messages col.ensure_index([('queue', 1), ('_id', 1)], background=True) if 'messages.broadcast' not in database.collection_names(): - capsize = conninfo.transport_options.get( - 'capped_queue_size') or 100000 + capsize = (client.transport_options.get('capped_queue_size') + or 100000) database.create_collection('messages.broadcast', size=capsize, capped=True) From e428bcd1226029f6290034b8b25d28d55c1c321b Mon Sep 17 00:00:00 2001 From: Flaper Fesp Date: Sun, 28 Apr 2013 19:27:16 +0200 Subject: [PATCH 2/4] Removed unused import --- kombu/transport/mongodb.py | 1 - 1 file changed, 1 deletion(-) diff --git a/kombu/transport/mongodb.py b/kombu/transport/mongodb.py index b31fce9b..ff0ff3e8 100644 --- a/kombu/transport/mongodb.py +++ b/kombu/transport/mongodb.py @@ -15,7 +15,6 @@ from Queue import Empty import pymongo from pymongo import errors -from pymongo.uri_parser import parse_uri from anyjson import loads, dumps from pymongo.connection import Connection From faea22866b1781835a917904862e739973fa38f1 Mon Sep 17 00:00:00 2001 From: John Shuping Date: Thu, 2 May 2013 08:17:57 -0700 Subject: [PATCH 3/4] connection.info(): 'hostname' is misleading When multiple brokers are specified, dont show the the hostname as the entire python list. --- kombu/connection.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/kombu/connection.py b/kombu/connection.py index 00e0be18..77844db2 100644 --- a/kombu/connection.py +++ b/kombu/connection.py @@ -545,12 +545,9 @@ class Connection(object): transport_cls = RESOLVE_ALIASES.get(transport_cls, transport_cls) D = self.transport.default_connection_params - if self.alt: - hostname = ";".join(self.alt) - else: - hostname = self.hostname or D.get('hostname') - if self.uri_prefix: - hostname = '%s+%s' % (self.uri_prefix, hostname) + hostname = self.hostname or D.get('hostname') + if self.uri_prefix: + hostname = '%s+%s' % (self.uri_prefix, hostname) info = (('hostname', hostname), ('userid', self.userid or D.get('userid')), @@ -565,6 +562,10 @@ class Connection(object): ('login_method', self.login_method or D.get('login_method')), ('uri_prefix', self.uri_prefix), ('heartbeat', self.heartbeat)) + + if self.alt: + info += (('alternates', self.alt),) + return info def info(self): From 7f9674419b585921b1da4ecbd5f3dc203891955e Mon Sep 17 00:00:00 2001 From: Ask Solem Date: Tue, 14 May 2013 15:29:11 +0100 Subject: [PATCH 4/4] Adds John Shuping to AUTHORS --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index a08548e5..1644d828 100644 --- a/AUTHORS +++ b/AUTHORS @@ -42,6 +42,7 @@ James Turk Jason Cater Jasper Bryant-Greene Jeff Balogh +John Shuping John Spray John Watson Jonathan Halcrow