本文整理汇总了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
示例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
示例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
示例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
示例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()
示例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.')
示例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
示例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)
示例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)
示例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'])
示例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
示例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()
示例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)