Example #1
0
 def consume_from_fedora_messaging(self):
     """
     fedora-messaging is written in an async way: callbacks
     """
     # Start consuming messages using our callback. This call will block until
     # a KeyboardInterrupt is raised, or the process receives a SIGINT or SIGTERM
     # signal.
     api.consume(self.fedora_messaging_callback)
Example #2
0
 def test_bindings_list_of_dict(self, mock_session):
     """Assert consume is working(bindings type is dict)"""
     mock_session.return_value = mock_session
     api.consume("test_callback", [{"example": "binding"}])
     mock_session.assert_called_once()
     mock_session.consume.assert_called_once_with(
         "test_callback", [{"example": "binding"}]
     )
    def test_bindings_dict(self, mock_session):
        """Assert consume wraps bindings in a list of just a plain dict"""
        bindings = {"queue": "q1", "exchange": "e1", "routing_keys": ["#"]}

        api.consume("test_callback", bindings)

        mock_session.assert_called_once()
        mock_session.return_value.consume.assert_called_once_with(
            "test_callback", bindings=[bindings], queues=config.conf["queues"])
    def test_defaults(self, mock_session):
        """Assert that bindings and queues come from the config if not provided."""
        api.consume("test_callback")

        mock_session.return_value.consume.assert_called_once_with(
            "test_callback",
            bindings=config.conf["bindings"],
            queues=config.conf["queues"],
        )
Example #5
0
def listen_from_fedora_messaging():
    """
    fedora-messaging is written in an async way: callbacks
    """
    # Start consuming messages using our callback. This call will block until
    # a KeyboardInterrupt is raised, or the process receives a SIGINT or SIGTERM
    # signal.
    celerize = Celerize(
        os.path.join(get_configuration_path(), "fedmsg-celerize-map.yaml"))
    api.consume(celerize.fedora_messaging_callback)
Example #6
0
def fedora_messaging_backend():
    """
    Launch consumer backend based on fedora-messaging to consume message from
    Fedora infra RabbitMQ message bus

    Refer to config file mts.toml for details of how the consumer is configured
    to receive messages from fedora-messaging.
    """
    from fedora_messaging import api
    api.consume(consume)
    def test_bindings_list_of_dict(self, mock_session):
        """Assert consume is working(bindings type is dict)"""
        bindings = [{"queue": "q1", "exchange": "e1", "routing_keys": ["#"]}]
        mock_session.return_value = mock_session

        api.consume("test_callback", bindings)

        mock_session.assert_called_once()
        mock_session.consume.assert_called_once_with(
            "test_callback", bindings=bindings, queues=config.conf["queues"])
Example #8
0
 def main(self):
     def callback(message):
         self.notify_watchdog()
         topic = message.topic
         msg = {'msg': message.body}
         try:
             if topic.startswith(get_config('fedmsg.topic') + '.'):
                 self.consume(topic, msg)
             plugin.dispatch_event('fedmsg_event', self.session, topic, msg)
         finally:
             self.db.rollback()
         self.memory_check()
     fedmsg.consume(callback)
    def test_with_queues(self, mock_session):
        """Assert queues is used over the config if provided."""
        queues = {
            "q1": {
                "durable": True,
                "auto_delete": False,
                "exclusive": False,
                "arguments": {},
            }
        }

        api.consume("test_callback", bindings=[], queues=queues)
        mock_session.return_value.consume.assert_called_once_with(
            "test_callback", bindings=[], queues=queues)
def listen():
    queues = {
        'demo': {
            'durable': False,  # Delete the queue on broker restart
            'auto_delete': True,  # Delete the queue when the client terminates
            'exclusive': False,  # Allow multiple simultaneous consumers
            'arguments': {},
        },
    }
    binding = {
        'exchange': 'amq.topic',  # The AMQP exchange to bind our queue to
        'queue': 'demo',  # The unique name of our queue on the AMQP broker
        'routing_keys':
        ['#'],  # The topics that should be delivered to the queue
    }

    # Start consuming messages using our callback. This call will block until
    # a KeyboardInterrupt is raised, or the process receives a SIGINT or SIGTERM
    # signal.
    api.consume(printer_callback, bindings=binding, queues=queues)
Example #11
0
 def test_bindings_is_None(self, mock_session):
     """Assert consume is working(bindings type is None)"""
     mock_session.return_value = mock_session
     api.consume("test_callback")
     mock_session.assert_called_once()
     mock_session.consume.assert_called_once_with("test_callback", None)
Example #12
0
 def test_bindings_are_dict(self, mock_session):
     """Assert consume is working(bindings type is dict)"""
     mock_session.return_value = mock_session
     api.consume("test_callback", dict())
     mock_session.assert_called_once()
     mock_session.consume.assert_called_once_with("test_callback", [dict()])
Example #13
0
from fedora_messaging.api import consume
from fedora_messaging.config import conf

conf.setup_logging()
def print_message(message):
    print(message)

if __name__ == "__main__":
    conf.setup_logging()
    consume(print_message)
Example #14
0
    def test_consume(self, mock_wrapper, mock_crochet):
        """Assert the consume call forwards to the twisted wrapper."""
        api.consume(1, 2, 3)

        mock_crochet.setup.assert_called_once_with()
        mock_wrapper.assert_called_once_with(1, 2, 3)