当前位置: 首页>>代码示例>>Python>>正文


Python queue.QueueService类代码示例

本文整理汇总了Python中azure.storage.queue.QueueService的典型用法代码示例。如果您正苦于以下问题:Python QueueService类的具体用法?Python QueueService怎么用?Python QueueService使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了QueueService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_sas_process

    def test_sas_process(self):
        # SAS URL is calculated from storage key, so this test runs live only
        if TestMode.need_recording_file(self.test_mode):
            return

        # Arrange
        queue_name = self._create_queue()
        self.qs.put_message(queue_name, u'message1')
        token = self.qs.generate_queue_shared_access_signature(
            queue_name,
            QueuePermissions.PROCESS,
            datetime.utcnow() + timedelta(hours=1),
        )

        # Act
        service = QueueService(
            account_name=self.settings.STORAGE_ACCOUNT_NAME,
            sas_token=token,
        )
        self._set_service_options(service, self.settings)
        result = service.get_messages(queue_name)

        # Assert
        self.assertIsNotNone(result)
        self.assertEqual(1, len(result))
        message = result[0]
        self.assertIsNotNone(message)
        self.assertNotEqual('', message.id)
        self.assertEqual(u'message1', message.content)
开发者ID:afshinm,项目名称:azure-storage-python,代码行数:29,代码来源:test_queue.py

示例2: AzureProvider

class AzureProvider(BaseProvider):
    """Queue Provider for the Microsoft Azure."""

    def __init__(self, account_name, account_key):
        self.queue_service = QueueService(
            account_name=account_name, account_key=account_key
        )

    def put_message(self, queue_name: str, message: str):
        self.queue_service.put_message(
            queue_name=queue_name,
            message_text=message,
        )

    def get_message(self, queue_name: str):
        try:
            queue_message = self.queue_service.get_messages(
                queue_name=queue_name, numofmessages=1
            ).queue_messages[0]
        except IndexError:
            return {}
        else:
            return {
                attr_name: getattr(queue_message, attr_name)
                for attr_name in dir(queue_message)
                if not attr_name.startswith('_')
            }

    def delete_message(self, queue_name: str, message: dict):
        message_id = message.get('message_id')
        pop_receipt = message.get('pop_receipt')

        self.queue_service.delete_message(
            queue_name, message_id=message_id, popreceipt=pop_receipt,
        )
开发者ID:kkorekk,项目名称:simple_encrypt,代码行数:35,代码来源:azure_provider.py

示例3: test_sas_process

    def test_sas_process(self):
        # SAS URL is calculated from storage key, so this test runs live only
        if TestMode.need_recordingfile(self.test_mode):
            return

        # Arrange
        self.qs.put_message(self.test_queues[0], 'message1')
        token = self.qs.generate_shared_access_signature(
            self.test_queues[0],
            self._get_shared_access_policy(QueueSharedAccessPermissions.PROCESS),
        )

        # Act
        service = QueueService(
            account_name=self.settings.STORAGE_ACCOUNT_NAME,
            sas_token=token,
        )
        self._set_service_options(service, self.settings)
        result = service.get_messages(self.test_queues[0])

        # Assert
        self.assertIsNotNone(result)
        self.assertEqual(1, len(result))
        message = result[0]
        self.assertIsNotNone(message)
        self.assertNotEqual('', message.message_id)
        self.assertEqual('message1', message.message_text)
开发者ID:bbayles,项目名称:azure-storage-python,代码行数:27,代码来源:test_storage_queue.py

示例4: test_sas_update

    def test_sas_update(self):
        # SAS URL is calculated from storage key, so this test runs live only
        if TestMode.need_recordingfile(self.test_mode):
            return

        # Arrange
        self.qs.put_message(self.test_queues[0], 'message1')
        token = self.qs.generate_shared_access_signature(
            self.test_queues[0],
            self._get_shared_access_policy(QueueSharedAccessPermissions.UPDATE),
        )
        result = self.qs.get_messages(self.test_queues[0])

        # Act
        service = QueueService(
            account_name=self.settings.STORAGE_ACCOUNT_NAME,
            sas_token=token,
        )
        self._set_service_options(service, self.settings)
        service.update_message(
            self.test_queues[0],
            result[0].message_id,
            'updatedmessage1',
            result[0].pop_receipt,
            visibilitytimeout=0,
        )

        # Assert
        result = self.qs.get_messages(self.test_queues[0])
        self.assertEqual('updatedmessage1', result[0].message_text)
开发者ID:bbayles,项目名称:azure-storage-python,代码行数:30,代码来源:test_storage_queue.py

示例5: get_queue_client_by_uri

    def get_queue_client_by_uri(queue_uri):
        queue_name, storage_name, key = StorageUtilities.get_storage_from_uri(queue_uri)

        queue_service = QueueService(account_name=storage_name, account_key=key)
        queue_service.create_queue(queue_name)

        return queue_service, queue_name
开发者ID:joshuaroot,项目名称:cloud-custodian,代码行数:7,代码来源:storage_utils.py

示例6: test_sas_update

    def test_sas_update(self):
        # SAS URL is calculated from storage key, so this test runs live only
        if TestMode.need_recording_file(self.test_mode):
            return

        # Arrange
        queue_name = self._create_queue()
        self.qs.put_message(queue_name, u'message1')
        token = self.qs.generate_queue_shared_access_signature(
            queue_name,
            QueuePermissions.UPDATE,
            datetime.utcnow() + timedelta(hours=1),
        )
        result = self.qs.get_messages(queue_name)

        # Act
        service = QueueService(
            account_name=self.settings.STORAGE_ACCOUNT_NAME,
            sas_token=token,
        )
        self._set_service_options(service, self.settings)
        service.update_message(
            queue_name,
            result[0].id,
            result[0].pop_receipt,
            visibility_timeout=0,
            content=u'updatedmessage1',
        )

        # Assert
        result = self.qs.get_messages(queue_name)
        self.assertEqual(u'updatedmessage1', result[0].content)
开发者ID:afshinm,项目名称:azure-storage-python,代码行数:32,代码来源:test_queue.py

示例7: sas_with_signed_identifiers

    def sas_with_signed_identifiers(self):
        queue_name = self._create_queue()
        self.service.put_message(queue_name, u'message1')

        # Set access policy on queue
        access_policy = AccessPolicy(permission=QueuePermissions.PROCESS,
                                     expiry=datetime.utcnow() + timedelta(hours=1))
        identifiers = {'id': access_policy}
        acl = self.service.set_queue_acl(queue_name, identifiers)

        # Wait 30 seconds for acl to propagate
        time.sleep(30)

        # Indicates to use the access policy set on the queue
        token = self.service.generate_queue_shared_access_signature(
            queue_name,
            id='id'
        )

        # Create a service and use the SAS
        sas_service = QueueService(
            account_name=self.account.account_name,
            sas_token=token,
        )

        messages = sas_service.get_messages(queue_name)
        for message in messages:
            print(message.content) # message1

        self.service.delete_queue(queue_name)
开发者ID:Siriuszyq,项目名称:azure-storage-python,代码行数:30,代码来源:sas_usage.py

示例8: get_queue_client_by_uri

    def get_queue_client_by_uri(queue_uri, session=None):
        storage = StorageUtilities.get_storage_from_uri(queue_uri, session)

        queue_service = QueueService(account_name=storage.storage_name, account_key=storage.key)
        queue_service.create_queue(storage.container_name)

        return queue_service, storage.container_name
开发者ID:tim-elliott,项目名称:cloud-custodian,代码行数:7,代码来源:storage_utils.py

示例9: QueueStorageHandler

class QueueStorageHandler(logging.Handler):
    """
    Handler class which sends log messages to a Azure Storage queue.
    """
    def __init__(self, 
                 account_name=None,
                 account_key=None,
                 protocol='https',
                 queue='logs',
                 message_ttl=None,
                 visibility_timeout=None,
                 base64_encoding=False,
                 is_emulated=False,
                 ):
        """
        Initialize the handler.
        """
        logging.Handler.__init__(self)
        self.service = QueueService(account_name=account_name,
                                    account_key=account_key,
                                    is_emulated=is_emulated,
                                    protocol=protocol)
        self.meta = {'hostname': gethostname(), 'process': os.getpid()}
        self.queue = _formatName(queue, self.meta)
        self.queue_created = False
        self.message_ttl = message_ttl
        self.visibility_timeout = visibility_timeout
        self.base64_encoding = base64_encoding

    def emit(self, record):
        """
        Emit a record.

        Format the record and send it to the specified queue.
        """
        try:
            if not self.queue_created:
                self.service.create_queue(self.queue)
                self.queue_created = True
            record.hostname = self.meta['hostname']
            msg = self._encode_text(self.format(record))
            self.service.put_message(self.queue,
                                     msg,
                                     self.visibility_timeout,
                                     self.message_ttl)
        except (KeyboardInterrupt, SystemExit):
            raise
        except:
            self.handleError(record)

    def _encode_text(self, text):
        if self.base64_encoding:
            text = b64encode(text.encode('utf-8')).decode('ascii')
        # fallback for the breaking change in azure-storage 0.33
        elif sys.version_info < (3,):
            if not isinstance(text, unicode):
                text = text.decode('utf-8')
        return text
开发者ID:michiya,项目名称:azure-storage-logging,代码行数:58,代码来源:handlers.py

示例10: get_queue_client_by_uri

    def get_queue_client_by_uri(queue_uri, session):
        storage = StorageUtilities.get_storage_from_uri(queue_uri, session)

        queue_service = QueueService(
            account_name=storage.storage_name,
            token_credential=storage.token)
        queue_service.create_queue(storage.container_name)

        return queue_service, storage.container_name
开发者ID:capitalone,项目名称:cloud-custodian,代码行数:9,代码来源:storage_utils.py

示例11: RegistrationQueueClient

class RegistrationQueueClient(object):
    """Obtains next registration object from queue"""
    queueName = 'registrationsqueue'

    def __init__(self, account_name, account_key):
        self._queueService = QueueService(account_name, account_key)
        print("RegistrationQueue Initialized")

    def LookupTicket(self, processData):
        message = self._queueService.get_messages(self.queueName, num_messages=1)
        if(processData(message)):
            self._queueService.delete_message(self.queueName, message.message_id, message.pop_receipt)
开发者ID:cwuenstel,项目名称:southwest-autocheckin,代码行数:12,代码来源:RegistrationQueueClient.py

示例12: SimulationListener

class SimulationListener(Thread):
    def __init__(self):
        Thread.__init__(self)
        self._quit = Event()
        self.daemon = True
        self.log = logging.getLogger(__name__)

        settings = Settings()
        self.create_queue = 'create-simulated-machine'
        self.destroy_queue = 'destroy-simulated-machine'

        self.queue_service = QueueService(
            account_name=settings.azure_queue_account,
            account_key=settings.azure_queue_key
        )
        self.queue_service.create_queue(self.create_queue)
        self.queue_service.create_queue(self.destroy_queue)

    def run(self):
        # dislike of unstoppable threads
        while not self._quit.is_set():
            try:
                messages = self.queue_service.get_messages(self.create_queue, numofmessages=10)
                for m in messages:
                    machine_json = b64decode(m.message_text)
                    machine = json.loads(machine_json)
                    self.log.info("Creating: " + machine["Name"] + " on " + machine["Provider"])
                    self.log.debug(machine_json)
                    requests.post("http://localhost:8080/machines", machine_json)
                    self.queue_service.delete_message(self.create_queue, m.message_id, m.pop_receipt)
            except Exception as e:
                self.log.error(e.message)

            try:
                messages = self.queue_service.get_messages(self.destroy_queue, numofmessages=10)
                for m in messages:
                    machine_json = b64decode(m.message_text)
                    machine = json.loads(machine_json)
                    self.log.info("Deleting: " + machine["Name"] + " on " + machine["Provider"])
                    self.log.debug(machine_json)
                    requests.delete("http://localhost:8080/machines/" + machine["MachineId"])
                    self.queue_service.delete_message(self.destroy_queue, m.message_id, m.pop_receipt)
            except Exception as e:
                self.log.error(e.message)

            sleep(1)

    def quit(self):
        self._quit.set()
开发者ID:witlox,项目名称:cumulonimbi,代码行数:49,代码来源:listener.py

示例13: createAzureQueues

 def createAzureQueues(self, account_name, account_key):
     """
     Create a queue for unprocessed log messages. Entries in the queue
     will be dequeued, processed and deleted upon success.
     """
     self.queue_service = QueueService(account_name, account_key)
     self.queue_service.create_queue(self.queue_name)
开发者ID:chzbrgr71,项目名称:acs-logging-test,代码行数:7,代码来源:messageQueue.py

示例14: get_queue_details

def get_queue_details(creds, resource_group_name, account_name, queue_name):
    keys = _get_storage_account_keys(creds, resource_group_name, account_name)
    queue_service = QueueService(account_name, keys.key1)

    model = StorageAccountQueueDetails()
    model.queue_name = queue_name
    model.metadata = queue_service.get_queue_metadata(queue_name)
    count = int(model.metadata.get("x-ms-approximate-messages-count", "0"))
    model.messages = queue_service.peek_messages(queue_name, count) if count else []
    for msg in model.messages:
        try:
            msg.decoded_text = b64decode(msg.message_text).decode()
        except:
            msg.decoded_text = None

    return model
开发者ID:yunjing,项目名称:azure-sdk-for-python,代码行数:16,代码来源:models.py

示例15: setUp

 def setUp(self):
     self.service = QueueService(ACCOUNT_NAME, ACCOUNT_KEY)
     # ensure that there's no message on the queue before each test
     queues = set()
     for cfg in LOGGING['handlers'].values():
         if 'queue' in cfg:
             queues.add(cfg['queue'])
     for queue in self.service.list_queues():
         if queue.name in queues:
             self.service.clear_messages(queue.name)
开发者ID:smonani,项目名称:azure-storage-logging,代码行数:10,代码来源:tests.py


注:本文中的azure.storage.queue.QueueService类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。