コード例 #1
0
 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
ファイル: priorityjobs.py プロジェクト: sideffect0/socorro
    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)
コード例 #3
0
 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
ファイル: priorityjobs.py プロジェクト: hanzhinstas/socorro
    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
ファイル: priorityjobs.py プロジェクト: hanzhinstas/socorro
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
ファイル: priorityjobs.py プロジェクト: sideffect0/socorro
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)
コード例 #8
0
 def test_constructor(self):
     conn_context_functor = ConnectionContext(self._setup_config)
     self.assertTrue(
         conn_context_functor.config is conn_context_functor.local_config
     )