def test_connection(self):
     config = self._setup_config()
     pika_string = 'socorro.external.rabbitmq.connection_context.pika'
     with patch(pika_string) as mocked_pika_module:
         conn_context_functor = ConnectionContext(config)
         conn = conn_context_functor.connection()
         mocked_pika_module.credentials.PlainCredentials \
             .assert_called_once_with('guest', 'guest')
         mocked_pika_module.ConnectionParameters.assert_called_once_with(
             host=conn_context_functor.config.host,
             port=conn_context_functor.config.port,
             virtual_host=conn_context_functor.config.virtual_host,
             credentials=mocked_pika_module.credentials. \
                 PlainCredentials.return_value
         )
         mocked_pika_module.BlockingConnection.assert_called_one_with(
             mocked_pika_module.ConnectionParameters.return_value
         )
         self.assertTrue(isinstance(conn, Connection))
         self.assertTrue(conn.config is config)
         self.assertTrue(
             conn.connection is
                 mocked_pika_module.BlockingConnection.return_value
         )
         self.assertTrue(
             conn.channel is conn.connection.channel.return_value
         )
     expected_queue_declare_call_args = [
         call(queue='dwight', durable=True),
         call(queue='wilma', durable=True),
     ]
     self.assertEqual(
         conn.channel.queue_declare.call_args_list,
         expected_queue_declare_call_args
     )
示例#2
0
    def __init__(self, config):
        rabbitconfig = DotDict()
        rabbitconfig.host = config['rabbitMQHost']
        rabbitconfig.port = config['rabbitMQPort']
        rabbitconfig.virtual_host = config['rabbitMQVirtualhost']
        rabbitconfig.rabbitmq_user = config['rabbitMQUsername']
        rabbitconfig.rabbitmq_password = config['rabbitMQPassword']
        rabbitconfig.standard_queue_name = config['rabbitMQStandardQueue']
        rabbitconfig.priority_queue_name = config['rabbitMQPriorityQueue']
        rabbitconfig.rabbitmq_connection_wrapper_class = Connection

        self.context = ConnectionContext(config=rabbitconfig)
 def test_call_and_close_connecton(self):
     config = self._setup_config()
     pika_string = 'socorro.external.rabbitmq.connection_context.pika'
     with patch(pika_string) as mocked_pika_module:
         conn_context_functor = ConnectionContext(config)
         with conn_context_functor() as conn_context:
             self.assertTrue(isinstance(conn_context, Connection))
         conn_context.connection.close.assert_called_once_with()
示例#4
0
    def __init__(self, config):
        rabbitconfig = DotDict()
        rabbitconfig.host = config['rabbitMQHost']
        rabbitconfig.port = config['rabbitMQPort']
        rabbitconfig.virtual_host = config['rabbitMQVirtualhost']
        rabbitconfig.rabbitmq_user = config['rabbitMQUsername']
        rabbitconfig.rabbitmq_password = config['rabbitMQPassword']
        rabbitconfig.standard_queue_name = config['rabbitMQStandardQueue']
        rabbitconfig.priority_queue_name = config['rabbitMQPriorityQueue']
        rabbitconfig.rabbitmq_connection_wrapper_class = Connection

        self.context = ConnectionContext(config=rabbitconfig)
示例#5
0
class Priorityjobs(object):
    """Implement the /priorityjobs service with RabbitMQ."""

    def __init__(self, config):
        rabbitconfig = DotDict()
        rabbitconfig.host = config['rabbitMQHost']
        rabbitconfig.port = config['rabbitMQPort']
        rabbitconfig.virtual_host = config['rabbitMQVirtualhost']
        rabbitconfig.rabbitmq_user = config['rabbitMQUsername']
        rabbitconfig.rabbitmq_password = config['rabbitMQPassword']
        rabbitconfig.standard_queue_name = config['rabbitMQStandardQueue']
        rabbitconfig.priority_queue_name = config['rabbitMQPriorityQueue']
        rabbitconfig.rabbitmq_connection_wrapper_class = Connection

        self.context = ConnectionContext(config=rabbitconfig)

    def get(self, **kwargs):
        raise NotImplementedError(
            'RabbitMQ does not support queue introspection.'
        )

    post = get

    def create(self, **kwargs):
        """Add a new job to the priority queue
        """
        filters = [
            ("uuid", None, "str"),
        ]
        params = external_common.parse_arguments(filters, kwargs)

        if not params.uuid:
            raise MissingArgumentError('uuid')

        with closing(self.context.connection()) as connection:
            try:
                logger.debug(
                    'Inserting priority job into RabbitMQ %s', params.uuid
                )
                connection.channel.basic_publish(
                    exchange='',
                    routing_key='socorro.priority',
                    body=params.uuid,
                    properties=pika.BasicProperties(delivery_mode=2)
                )
            except ChannelClosed:
                logger.error(
                    "Failed inserting priorityjobs data into RabbitMQ",
                    exc_info=True
                )
                return False

        return True
示例#6
0
class Priorityjobs(object):
    """Implement the /priorityjobs service with RabbitMQ."""
    def __init__(self, config):
        rabbitconfig = DotDict()
        rabbitconfig.host = config['rabbitMQHost']
        rabbitconfig.port = config['rabbitMQPort']
        rabbitconfig.virtual_host = config['rabbitMQVirtualhost']
        rabbitconfig.rabbitmq_user = config['rabbitMQUsername']
        rabbitconfig.rabbitmq_password = config['rabbitMQPassword']
        rabbitconfig.standard_queue_name = config['rabbitMQStandardQueue']
        rabbitconfig.priority_queue_name = config['rabbitMQPriorityQueue']
        rabbitconfig.rabbitmq_connection_wrapper_class = Connection

        self.context = ConnectionContext(config=rabbitconfig)

    def get(self, **kwargs):
        raise NotImplementedError(
            'RabbitMQ does not support queue introspection.')

    post = get

    def create(self, **kwargs):
        """Add a new job to the priority queue
        """
        filters = [
            ("uuid", None, "str"),
        ]
        params = external_common.parse_arguments(filters, kwargs)

        if not params.uuid:
            raise MissingArgumentError('uuid')

        with closing(self.context.connection()) as connection:
            try:
                logger.debug('Inserting priority job into RabbitMQ %s',
                             params.uuid)
                connection.channel.basic_publish(
                    exchange='',
                    routing_key='socorro.priority',
                    body=params.uuid,
                    properties=pika.BasicProperties(delivery_mode=2))
            except ChannelClosed:
                logger.error(
                    "Failed inserting priorityjobs data into RabbitMQ",
                    exc_info=True)
                return False

        return True
示例#7
0
 def __init__(self, config):
     if 'rabbitmq' in config:
         # the normal configman case
         self.config = config.rabbitmq
         self.context = self.config.rabbitmq_class(self.config)
     else:
         # the old middleware case without configman
         rabbitconfig = DotDictWithAcquisition()
         rabbitconfig.host = config['rabbitMQHost']
         rabbitconfig.port = config['rabbitMQPort']
         rabbitconfig.virtual_host = config['rabbitMQVirtualhost']
         rabbitconfig.rabbitmq_user = config['rabbitMQUsername']
         rabbitconfig.rabbitmq_password = config['rabbitMQPassword']
         rabbitconfig.standard_queue_name = config['rabbitMQStandardQueue']
         rabbitconfig.priority_queue_name = config['rabbitMQPriorityQueue']
         rabbitconfig.logger = logger
         self.config = rabbitconfig
         self.context = ConnectionContext(rabbitconfig)
 def test_constructor(self):
     conn_context_functor = ConnectionContext(self._setup_config)
     self.assertTrue(
         conn_context_functor.config is conn_context_functor.local_config
     )