Exemplo n.º 1
0
def get_pubsub():
    """
    Helper function to get the pubsub client used to send and receive messages.

    :return: The pubsub object used to publish Eva messages to the clients.
    :rtype: `anypubsub.interfaces.PubSub  <https://github.com/smarzola/anypubsub>`_
    """
    mongo_client = get_mongo_client()
    return create_pubsub_from_settings({'backend': 'mongodb',
                                        'client': mongo_client,
                                        'database': 'eva',
                                        'collection': 'communications'})
Exemplo n.º 2
0
def get_pubsub():
    """
    Helper function to get a anypubsub.MongoPubSub object based on parameters
    specified by command line. Will tail the 'eva' database's 'communications'
    collection for pubsub messages.

    :return: The anypubsub object used for receiving Eva messages.
    :rtype: anypubsub.backends.MongoPubSub
    """
    global ARGS
    uri = 'mongodb://'
    if len(ARGS.mongo_username) > 0:
        uri = uri + ARGS.mongo_username
        if len(ARGS.mongo_password) > 0: uri = uri + ':' + ARGS.mongo_password + '@'
        else: uri = uri + '@'
    uri = '%s%s:%s' %(uri, ARGS.mongo_host, ARGS.mongo_port)
    client = MongoClient(uri)
    return create_pubsub_from_settings({'backend': 'mongodb',
                                        'client': client,
                                        'database': 'eva',
                                        'collection': 'communications'})
Exemplo n.º 3
0
    def get_pubsub(self):
        """
        Overriden method that returns the pubsub instance required to
        send/receive messages to/from Eva.

        :return: The pubsub object used to publish Eva messages to the clients.
        :rtype: `anypubsub.interfaces.PubSub  <https://github.com/smarzola/anypubsub>`_
        """
        uri = 'mongodb://'
        if len(self.username) > 0:
            uri = uri + self.username
            if len(self.password) > 0:
                uri = uri + ':' + self.password + '@'
            else:
                uri = uri + '@'
        uri = '%s%s:%s' %(uri, self.host, self.port)
        client = MongoClient(uri)
        return create_pubsub_from_settings({'backend': 'mongodb',
                                            'client': client,
                                            'database': 'eva',
                                            'collection': 'communications'})
Exemplo n.º 4
0
 def test_create_pubsub_from_settings_with_prefix(self):
     from anypubsub import create_pubsub_from_settings
     from anypubsub.backends.memory import MemoryPubSub
     pubsub = create_pubsub_from_settings({'foo.backend': 'memory'}, prefix='foo.')
     assert isinstance(pubsub, MemoryPubSub)
Exemplo n.º 5
0
 def test_create_pubsub_from_settings(self):
     from anypubsub import create_pubsub_from_settings
     from anypubsub.backends.memory import MemoryPubSub
     pubsub = create_pubsub_from_settings({'backend': 'memory'})
     assert isinstance(pubsub, MemoryPubSub)
Exemplo n.º 6
0
 def test_create_pubsub_from_settings_with_prefix(self):
     from anypubsub import create_pubsub_from_settings
     from anypubsub.backends.memory import MemoryPubSub
     pubsub = create_pubsub_from_settings({'foo.backend': 'memory'},
                                          prefix='foo.')
     assert isinstance(pubsub, MemoryPubSub)
Exemplo n.º 7
0
 def test_create_pubsub_from_settings(self):
     from anypubsub import create_pubsub_from_settings
     from anypubsub.backends.memory import MemoryPubSub
     pubsub = create_pubsub_from_settings({'backend': 'memory'})
     assert isinstance(pubsub, MemoryPubSub)