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


Python QueueService.create_queue方法代码示例

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


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

示例1: get_queue_client_by_uri

# 需要导入模块: from azure.storage.queue import QueueService [as 别名]
# 或者: from azure.storage.queue.QueueService import create_queue [as 别名]
    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,代码行数:9,代码来源:storage_utils.py

示例2: get_queue_client_by_uri

# 需要导入模块: from azure.storage.queue import QueueService [as 别名]
# 或者: from azure.storage.queue.QueueService import create_queue [as 别名]
    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,代码行数:9,代码来源:storage_utils.py

示例3: QueueStorageHandler

# 需要导入模块: from azure.storage.queue import QueueService [as 别名]
# 或者: from azure.storage.queue.QueueService import create_queue [as 别名]
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,代码行数:60,代码来源:handlers.py

示例4: get_queue_client_by_uri

# 需要导入模块: from azure.storage.queue import QueueService [as 别名]
# 或者: from azure.storage.queue.QueueService import create_queue [as 别名]
    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,代码行数:11,代码来源:storage_utils.py

示例5: SimulationListener

# 需要导入模块: from azure.storage.queue import QueueService [as 别名]
# 或者: from azure.storage.queue.QueueService import create_queue [as 别名]
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,代码行数:51,代码来源:listener.py

示例6: set_up_queue

# 需要导入模块: from azure.storage.queue import QueueService [as 别名]
# 或者: from azure.storage.queue.QueueService import create_queue [as 别名]
def set_up_queue(queue_name):
    account_name = input('Please provide Azure account name:')
    account_key = input('Please provide Azure access key:')

    queue_service = QueueService(account_name, account_key)

    print('Creating queue: {} ...'.format(queue_name))

    try:
        queue_service.create_queue(queue_name)
    except AzureException as exc:
        print('Cannot create queue, reason: {}'.format(exc), file=sys.stderr)
        sys.exit(1)
    else:
        print('Queue successfully created.')

    print('Generating SAS token...')

    expiry_date = datetime.date.today() + datetime.timedelta(days=30)

    print('SAS token will expire in', str(expiry_date))

    access_policy = AccessPolicy(
        expiry=str(expiry_date),
        permission=(
            QueueSharedAccessPermissions.READ +
            QueueSharedAccessPermissions.ADD +
            QueueSharedAccessPermissions.PROCESS
        ),
    )

    sas_token = queue_service.generate_shared_access_signature(
        queue_name, SharedAccessPolicy(access_policy),
    )

    print('Generated SAS token:', sas_token)
    print('Please use above token in QueueManager.')
开发者ID:kkorekk,项目名称:simple_encrypt,代码行数:39,代码来源:prepare_queue.py

示例7: get_queue_service

# 需要导入模块: from azure.storage.queue import QueueService [as 别名]
# 或者: from azure.storage.queue.QueueService import create_queue [as 别名]
def get_queue_service():
    "Returns the QueueService that can be used to put, peek, get and delete messages"
    queue_service = QueueService(ACCOUNT_NAME, ACCOUNT_KEY)
    queue_service.create_queue(QUEUE_NAME)
    return queue_service
开发者ID:austvik,项目名称:ntnu_queue_workshop,代码行数:7,代码来源:common.py

示例8: create_queue_from_storage_account

# 需要导入模块: from azure.storage.queue import QueueService [as 别名]
# 或者: from azure.storage.queue.QueueService import create_queue [as 别名]
 def create_queue_from_storage_account(storage_account, name, session):
     token = StorageUtilities.get_storage_token(session)
     queue_service = QueueService(
         account_name=storage_account.name,
         token_credential=token)
     return queue_service.create_queue(name)
开发者ID:capitalone,项目名称:cloud-custodian,代码行数:8,代码来源:storage_utils.py

示例9: create_queue_from_storage_account

# 需要导入模块: from azure.storage.queue import QueueService [as 别名]
# 或者: from azure.storage.queue.QueueService import create_queue [as 别名]
 def create_queue_from_storage_account(storage_account, name):
     keys = StorageUtilities.get_storage_keys(storage_account.id)
     queue_service = QueueService(account_name=storage_account.name,
                                  account_key=keys[0].value)
     return queue_service.create_queue(name)
开发者ID:tim-elliott,项目名称:cloud-custodian,代码行数:7,代码来源:storage_utils.py

示例10: BlobService

# 需要导入模块: from azure.storage.queue import QueueService [as 别名]
# 或者: from azure.storage.queue.QueueService import create_queue [as 别名]
    }

stor_acc_name = service_keys['stor_acc_name']
stor_acc_key = service_keys['stor_acc_key']
redis_pass = service_keys['redis_pass']
redis_server = service_keys['redis_server']
instr_key = service_keys['instr_key']


# storage
account_name = stor_acc_name
account_key = stor_acc_key
blob_service = BlobService(account_name, account_key)
blob_service.create_container('images')
queue_service = QueueService(account_name, account_key)
queue_service.create_queue('taskqueue')
table_service = TableService(account_name, account_key)
table_service.create_table('tasktable')


r = redis.StrictRedis(host=redis_server, port=6380, db=0, password=redis_pass, ssl=True)

tc = TelemetryClient(instr_key)

@app.route('/')
@app.route('/home')
def form():
    return render_template('form_submit.html')


@app.route('/hello/', methods=['POST'])
开发者ID:LukiTri,项目名称:azureday-flask,代码行数:33,代码来源:views.py

示例11: __init__

# 需要导入模块: from azure.storage.queue import QueueService [as 别名]
# 或者: from azure.storage.queue.QueueService import create_queue [as 别名]
class Queue:
    def __init__(self, account_name, account_key, queue_name="logqueue"):
        """Initialiaze a queue. The type is set by the
        'ACS_LOGGING_QUEUE_TYPE' environment variable. If it is set to
        'AzureStorageQueue' then values must be provided for
        'account_name' and 'account_key' which are values associated
        with the Azure Storage account. 'queue_name' is optional and
        defaults to 'logqueue'.

        """
        self.log = Log()
        self.queue_type = config.ACS_LOGGING_QUEUE_TYPE
        self.queue_name = queue_name
        # self.log.debug("Queue type: " + self.queue_type + " / " + self.queue_name)

        if self.queue_type == "AzureStorageQueue":
            self.createAzureQueues(account_name, account_key)
        elif self.queue_type == "LocalFile":
            self.file_queue = open(config.UNPROCESSED_LOG_FILE, "w+")
        else:
            self.log.error("Unknown queue type: " + queue_type)

    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)

    def close(self):
        """Perform any necessary clearnup on the queue
           at the end of a run.
        """
        if self.queue_type == "AzureStorageQueue":
            pass
        elif self.queue_type == "LocalFile":
            self.file_queue.close()
        else:
            self.log.error("Unknown queue type: " + queue_type)

    def enqueue(self, msg, level="INFO"):
        msg = level + " - " + msg
        if self.queue_type == "LocalFile":
            file_queue.write(msg + "\n")
        elif self.queue_type == "AzureStorageQueue":
            self.queue_service.put_message(self.queue_name, msg)
        self.log.debug(msg)

    def dequeue(self):
        messages = []
        if self.queue_type == "LocalFile":
            with open(config.UNPROCESSED_LOG_FILE, "r") as f:
                messages = f.readlines()[1]
        elif self.queue_type == "AzureStorageQueue":
            messages = self.queue_service.get_messages(self.queue_name)
        return messages

    def delete(self, message):
        self.queue_service.delete_message(self.queue_name, message.message_id, message.pop_receipt)
        #  with open(config.PROCESSED_LOG_FILE, 'a') as processed:
        #    processed.write(log)
        #  os.remove(config.UNPROCESSED_LOG_FILE)

    def delete_queue(self, queue_name):
        self.queue_service.delete_queue(queue_name, False)

    def getLength(self):
        """
        Get the approximate length of the queue
        """
        queue_metadata = self.queue_service.get_queue_metadata(self.queue_name)
        count = queue_metadata["x-ms-approximate-messages-count"]
        return count
开发者ID:chzbrgr71,项目名称:acs-logging-test,代码行数:76,代码来源:messageQueue.py

示例12: instance

# 需要导入模块: from azure.storage.queue import QueueService [as 别名]
# 或者: from azure.storage.queue.QueueService import create_queue [as 别名]
# Main thread - Check if port 25565 and move to the next if it's not. Once a free port has been found, create a new instance (up to 3)
while instanceCreated == 0:
        freeport = checkPort(defaultport)
        if freeport == 0:
                defaultport += 1
                counter += 1
                if counter > maxInstances:
                        print "Too many instances! you can't run more than %s instances" % maxInstances
                        sys.exit()
        else:
                if debug == 1: print "Port %s is free" % defaultport
                container = createMcInstance(defaultport)
                instanceCreated = 1
                counter +=1

# Return Instance ID, port and total number of instances once finished creating the server
print "Instance ID: %s" % container["Id"]
print "Listening on port %s" % defaultport
print "There are %s instances running on this server" % counter

# Update servers queue
queue_service = QueueService(account_name, account_key)
try:
	queue_service.create_queue(queuename)
except:
	print "Queue creation failed."

queue_service.put_message(queuename, '{"ContainerID":"%s", "ContainerPort":"%s", "ServerID":"%s"}' % container["Id"], defaultport, socket.gethostname())

sys.exit()
开发者ID:pjperez,项目名称:Multicraft,代码行数:32,代码来源:multicraft.py

示例13: put_to_queue

# 需要导入模块: from azure.storage.queue import QueueService [as 别名]
# 或者: from azure.storage.queue.QueueService import create_queue [as 别名]
def put_to_queue(name, content):
    queue_service = QueueService(account_name=config.AZURE_STORAGE_NAME, account_key=config.AZURE_STORAGE_KEY)
    queue_service.create_queue(name)
    queue_service.put_message(name, content)
开发者ID:hungys,项目名称:DockerVC,代码行数:6,代码来源:azure_storage.py


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