예제 #1
0
    def _open(self):
        conninfo = self.connection.client
        mongoconn = Connection(host=conninfo.hostname, port=conninfo.port)
        dbname = conninfo.virtual_host
        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, ))
        if not dbname or dbname == "/":
            dbname = "kombu_default"
        database = getattr(mongoconn, dbname)
        if conninfo.userid:
            database.authenticate(conninfo.userid, conninfo.password)

        self.db = database
        col = database.messages
        col.ensure_index([("queue", 1)])

        if "messages.broadcast" not in database.collection_names():
            capsize = conninfo.transport_options.get(
                "capped_queue_size") or 100000
            database.create_collection("messages.broadcast",
                                       size=capsize,
                                       capped=True)

        self.bcast = getattr(database, "messages.broadcast")
        self.bcast.ensure_index([("queue", 1)])

        self.routing = getattr(database, "messages.routing")
        self.routing.ensure_index([("queue", 1), ("exchange", 1)])
        return database
예제 #2
0
파일: mongodb.py 프로젝트: Kronuz/kombu
    def _open(self):
        conninfo = self.connection.client
        mongoconn = Connection(host=conninfo.hostname, port=conninfo.port)
        dbname = conninfo.virtual_host
        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, ))
        if not dbname or dbname == "/":
            dbname = "kombu_default"
        database = getattr(mongoconn, dbname)
        if conninfo.userid:
            database.authenticate(conninfo.userid, conninfo.password)

        self.db = database
        col = database.messages
        col.ensure_index([("queue", 1)])

        if "messages.broadcast" not in database.collection_names():
            capsize = conninfo.transport_options.get(
                            "capped_queue_size") or 100000
            database.create_collection("messages.broadcast", size=capsize,
                                                             capped=True)

        self.bcast = getattr(database, "messages.broadcast")
        self.bcast.ensure_index([("queue", 1)])

        self.routing = getattr(database, "messages.routing")
        self.routing.ensure_index([("queue", 1), ("exchange", 1)])
        return database
예제 #3
0
    def _open(self):
        """
        See mongodb uri documentation:
        http://www.mongodb.org/display/DOCS/Connections
        """
        client = self.connection.client
        hostname = client.hostname or DEFAULT_HOST
        authdb = dbname = client.virtual_host

        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=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+ (server is {0})'.format(
                    version))

        self.db = database
        col = database.messages
        col.ensure_index([('queue', 1), ('_id', 1)], background=True)

        if 'messages.broadcast' not in database.collection_names():
            capsize = (client.transport_options.get('capped_queue_size')
                       or 100000)
            database.create_collection('messages.broadcast',
                                       size=capsize,
                                       capped=True)

        self.bcast = getattr(database, 'messages.broadcast')
        self.bcast.ensure_index([('queue', 1)])

        self.routing = getattr(database, 'messages.routing')
        self.routing.ensure_index([('queue', 1), ('exchange', 1)])
        return database
예제 #4
0
    def _open(self):
        """
        See mongodb uri documentation:
        http://www.mongodb.org/display/DOCS/Connections
        """
        client = self.connection.client
        hostname = client.hostname or DEFAULT_HOST
        authdb = dbname = client.virtual_host

        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=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+ (server is {0})'.format(
                    version))

        self.db = database
        col = database.messages
        col.ensure_index([('queue', 1), ('_id', 1)], background=True)

        if 'messages.broadcast' not in database.collection_names():
            capsize = (client.transport_options.get('capped_queue_size')
                       or 100000)
            database.create_collection('messages.broadcast',
                                       size=capsize, capped=True)

        self.bcast = getattr(database, 'messages.broadcast')
        self.bcast.ensure_index([('queue', 1)])

        self.routing = getattr(database, 'messages.routing')
        self.routing.ensure_index([('queue', 1), ('exchange', 1)])
        return database
예제 #5
0
def main():
    connection = Connection()
    runner = BenchmarkRunner(10000, connection.server_info()["gitVersion"])

    runner.run_benchmark(Encode(small, "small"))
    runner.run_benchmark(Encode(medium, "medium"))
    runner.run_benchmark(Encode(large, "large"))

    runner.run_benchmark(Decode(BSON.from_dict(small), "small"))
    runner.run_benchmark(Decode(BSON.from_dict(medium), "medium"))
    runner.run_benchmark(Decode(BSON.from_dict(large), "large"))

    runner.run_benchmark(Insert(connection.benchmark, medium, "medium"))

    runner.run_benchmark(FindOne(connection.benchmark.medium_no_index, {"x": 5000}, "medium"))
예제 #6
0
 def _open(self):
     conninfo = self.connection.client
     mongoconn = Connection(host=conninfo.hostname, port=conninfo.port)
     dbname = conninfo.virtual_host
     version = mongoconn.server_info()["version"]
     if tuple(map(int, version.split("."))) < (1, 3):
         raise NotImplementedError(
             "Kombu requires MongoDB version 1.3+, but connected to %s" % (
                 version, ))
     if not dbname or dbname == "/":
         dbname = "kombu_default"
     database = getattr(mongoconn, dbname)
     col = database.messages
     col.ensure_index([("queue", 1)])
     return col
예제 #7
0
파일: mongodb.py 프로젝트: oremj/freddo-lib
 def _open(self):
     conninfo = self.connection.client
     mongoconn = Connection(host=conninfo.hostname, port=conninfo.port)
     dbname = conninfo.virtual_host
     version = mongoconn.server_info()["version"]
     if tuple(map(int, version.split("."))) < (1, 3):
         raise NotImplementedError(
             "Kombu requires MongoDB version 1.3+, but connected to %s" %
             (version, ))
     if not dbname or dbname == "/":
         dbname = "kombu_default"
     database = getattr(mongoconn, dbname)
     col = database.messages
     col.ensure_index([("queue", 1)])
     return col
예제 #8
0
def main():
    connection = Connection()
    runner = BenchmarkRunner(10000, connection.server_info()["gitVersion"])

    runner.run_benchmark(Encode(small, "small"))
    runner.run_benchmark(Encode(medium, "medium"))
    runner.run_benchmark(Encode(large, "large"))

    runner.run_benchmark(Decode(BSON.from_dict(small), "small"))
    runner.run_benchmark(Decode(BSON.from_dict(medium), "medium"))
    runner.run_benchmark(Decode(BSON.from_dict(large), "large"))

    runner.run_benchmark(Insert(connection.benchmark, medium, "medium"))

    runner.run_benchmark(
        FindOne(connection.benchmark.medium_no_index, {"x": 5000}, "medium"))
예제 #9
0
    def _open(self):
        conninfo = self.connection.client
        mongoconn = Connection(host=conninfo.hostname, port=conninfo.port)
        dbname = conninfo.virtual_host
        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, ))
        if not dbname or dbname == "/":
            dbname = "kombu_default"
        database = getattr(mongoconn, dbname)
        if conninfo.userid:
            database.authenticate(conninfo.userid, conninfo.password)
        col = database.messages
        #note, for existing installation one should drop the index on only queue
        col.ensure_index([("queue", pymongo.ASCENDING), ("priority", pymongo.ASCENDING), ("_id", pymongo.ASCENDING)])

        return col
예제 #10
0
파일: mongodb.py 프로젝트: maduhu/HDP-hue
    def _open(self):
        """
        See mongodb uri documentation:
        http://www.mongodb.org/display/DOCS/Connections
        """
        conninfo = self.connection.client

        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 == "/":
            dbname = "kombu_default"

        # 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)
        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
            database.create_collection('messages.broadcast',
                                       size=capsize, capped=True)

        self.bcast = getattr(database, 'messages.broadcast')
        self.bcast.ensure_index([('queue', 1)])

        self.routing = getattr(database, 'messages.routing')
        self.routing.ensure_index([('queue', 1), ('exchange', 1)])
        return database
예제 #11
0
파일: mongodb.py 프로젝트: imtapps/kombu
    def _open(self):
        """
        See mongodb uri documentation:
        http://www.mongodb.org/display/DOCS/Connections
        """
        conninfo = self.connection.client

        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

        # 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)
        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, ))

        if not dbname or dbname == "/":
            dbname = "kombu_default"

        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)])

        if "messages.broadcast" not in database.collection_names():
            capsize = conninfo.transport_options.get(
                            "capped_queue_size") or 100000
            database.create_collection("messages.broadcast", size=capsize,
                                                             capped=True)

        self.bcast = getattr(database, "messages.broadcast")
        self.bcast.ensure_index([("queue", 1)])

        self.routing = getattr(database, "messages.routing")
        self.routing.ensure_index([("queue", 1), ("exchange", 1)])
        return database