Пример #1
0
 def _get_queues(self) -> List[QueueClient]:
     return [
         QueueServiceClient(q.account_uri).get_queue_client(
             queue=q.object_name,
             message_decode_policy=TextBase64DecodePolicy())
         for q in self.get_queues_func()
     ]
Пример #2
0
def get_queue(queue_name, create_queue, clear_queue):
    ''' Note that generating the queueclient does not mean there must a queue there as one of the properties of queueclient is "create_queue", so it's 
    really a representation of a queue which may or may not exist yet. '''
    keyVaultName = os.environ["KEY_VAULT_NAME"]
    keyVault_URI = "https://" + keyVaultName + ".vault.azure.net"
    credential = DefaultAzureCredential()
    client = SecretClient(vault_url=keyVault_URI, credential=credential)
    data_access_key = client.get_secret("thecupstore-key")
    account_url = "https://thecupstore.queue.core.windows.net/"
    queueclient = QueueClient(account_url=account_url,
                              queue_name=queue_name,
                              credential=data_access_key.value,
                              message_encode_policy=TextBase64EncodePolicy(),
                              message_decode_policy=TextBase64DecodePolicy())
    # Check that the queue exists and if not create it if the create switch has been passed as True
    try:
        queueclient.get_queue_properties()
    except:
        if create_queue:
            queueclient.create_queue()
        else:
            message = "Queue does not exist"
    else:
        if clear_queue:
            queueclient.clear_messages()

    if 'message' in locals():  # checks for existence of message variable
        return message
    else:
        return queueclient
    def test_message_text_base64(self, storage_account_name, storage_account_key):
        # Arrange.
        qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key)
        queue = QueueClient(
            account_url=self.account_url(storage_account_name, "queue"),
            queue_name=self.get_resource_name(TEST_QUEUE_PREFIX),
            credential=storage_account_key,
            message_encode_policy=TextBase64EncodePolicy(),
            message_decode_policy=TextBase64DecodePolicy())

        message = u'\u0001'

        # Asserts
        self._validate_encoding(queue, message)
    def test_message_text_base64(self):
        # Arrange.
        queue_url = self._get_queue_url()
        credentials = self._get_shared_key_credential()
        queue = QueueClient(
            queue_url=queue_url,
            queue=self.get_resource_name(TEST_QUEUE_PREFIX),
            credential=credentials,
            message_encode_policy=TextBase64EncodePolicy(),
            message_decode_policy=TextBase64DecodePolicy())

        message = u'\u0001'

        # Asserts
        self._validate_encoding(queue, message)
Пример #5
0
    async def test_message_text_base64(self, resource_group, location,
                                       storage_account, storage_account_key):
        # Arrange.
        qsc = QueueServiceClient(self._account_url(storage_account.name),
                                 storage_account_key,
                                 transport=AiohttpTestTransport())
        queue = QueueClient(queue_url=self._account_url(storage_account.name),
                            queue=self.get_resource_name(TEST_QUEUE_PREFIX),
                            credential=storage_account_key,
                            message_encode_policy=TextBase64EncodePolicy(),
                            message_decode_policy=TextBase64DecodePolicy(),
                            transport=AiohttpTestTransport())

        message = '\u0001'

        # Asserts
        await self._validate_encoding(queue, message)
Пример #6
0
                                 TextBase64DecodePolicy)

import os, uuid, time, json
import mysql.connector
from datetime import datetime

connect_str = "DefaultEndpointsProtocol=https;AccountName=replace;AccountKey=replacewithyours;EndpointSuffix=core.windows.net"
queue_name = "name of queue"

mySql_dbName = "sensordata"
mySql_tableName = "temperature"

queue_client = QueueClient.from_connection_string(
    conn_str=connect_str,
    queue_name=queue_name,
    message_decode_policy=TextBase64DecodePolicy())
messages = queue_client.receive_messages(messages_per_page=5)

db = mysql.connector.connect(host="db",
                             user="******",
                             passwd="example",
                             database=mySql_dbName)
cursor = db.cursor()


def processMessage():
    message_json = json.loads(message.content)
    payload_raw = message_json["payload_raw"]
    payload_bytes = bytes(payload_raw, 'ascii')
    sensor_counter = payload_bytes[0] + 256 * payload_bytes[1]
    sensor_temperature = payload_bytes[2] + (payload_bytes[3] / 100)