本文整理汇总了Python中azure.storage.queue.QueueService.delete_message方法的典型用法代码示例。如果您正苦于以下问题:Python QueueService.delete_message方法的具体用法?Python QueueService.delete_message怎么用?Python QueueService.delete_message使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类azure.storage.queue.QueueService
的用法示例。
在下文中一共展示了QueueService.delete_message方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AzureProvider
# 需要导入模块: from azure.storage.queue import QueueService [as 别名]
# 或者: from azure.storage.queue.QueueService import delete_message [as 别名]
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,
)
示例2: RegistrationQueueClient
# 需要导入模块: from azure.storage.queue import QueueService [as 别名]
# 或者: from azure.storage.queue.QueueService import delete_message [as 别名]
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)
示例3: SimulationListener
# 需要导入模块: from azure.storage.queue import QueueService [as 别名]
# 或者: from azure.storage.queue.QueueService import delete_message [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()
示例4: __init__
# 需要导入模块: from azure.storage.queue import QueueService [as 别名]
# 或者: from azure.storage.queue.QueueService import delete_message [as 别名]
class TimeLineWorker:
QUEUE_KEY = ''
ACCOUNT_NAME = ''
QUEUE_NAME = ''
def __init__(self):
self.queue_service = QueueService(account_name=TimeLineWorker.ACCOUNT_NAME,
account_key=TimeLineWorker.QUEUE_KEY)
def insert_message(self):
obj = {
"message": "test message",
"other_key": 10
}
message = unicode(json.dumps(obj))
self.queue_service.put_message(TimeLineWorker.QUEUE_NAME, message)
def get_next_message(self):
messages = self.queue_service.get_messages(TimeLineWorker.QUEUE_NAME)
for message in messages:
print message.content
self.queue_service.delete_message(TimeLineWorker.QUEUE_NAME, message.id, message.pop_receipt)
示例5: __init__
# 需要导入模块: from azure.storage.queue import QueueService [as 别名]
# 或者: from azure.storage.queue.QueueService import delete_message [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
示例6: QueueService
# 需要导入模块: from azure.storage.queue import QueueService [as 别名]
# 或者: from azure.storage.queue.QueueService import delete_message [as 别名]
# Pedro Perez - 2015
#
# -----------------------------------------------------------------------------
import sys
import os
import subprocess
from azure.storage.queue import QueueService
account_name = "mcdockerqueue"
account_key = sys.argv[1]
queuename = "servers"
queue_service = QueueService(account_name, account_key)
queue_metadata = queue_service.get_queue_metadata(queuename)
count = queue_metadata['x-ms-approximate-messages-count']
print "There are %s messages in the queue" % count
if count > 0:
messages = queue_service.get_messages(queuename)
for message in messages:
print(message.message_text)
# Remove message from the queue
queue_service.delete_message(queuename, message.message_id, message.pop_receipt)
else:
print "There are no messages to process"
示例7: QueueService
# 需要导入模块: from azure.storage.queue import QueueService [as 别名]
# 或者: from azure.storage.queue.QueueService import delete_message [as 别名]
if "chronos" in os.environ:
chronos = os.environ['chronos']
while True:
# set up azure queue
queue_service = QueueService(account_name=azurestoracct, account_key=azurequeuekey)
# get messages from azure queue
messages = queue_service.get_messages(azurequeue, num_messages=5)
# delete from queue, create container, start container
for message in messages:
# delete message from azure queue
queue_service.delete_message(azurequeue, message.id, message.pop_receipt)
if "docker" in os.environ:
# sample json
# {"Image": "neilpeterson/stock-report","Cmd": ["--symbols=msft;lnkd", "[email protected]"],"Env": ["gmuser = [email protected]", "gmpass = TempForDemo2016"]}
s = message.content.split(':')
data = json.loads('{"Image": "' + docker_image + '","Cmd": ["--symbols=' + s[0] +'", "--email=' + s[1] + '","--delay=' + str(delay) + '"]}')
print(data)
# create and start docker container
headers = {'Content-Type': 'application/json'}
r = requests.post(docker + "create", data=json.dumps(data), headers=headers)
b = json.loads(r.text)
x = requests.post(docker + b['Id'] + "/start")
示例8: QueueService
# 需要导入模块: from azure.storage.queue import QueueService [as 别名]
# 或者: from azure.storage.queue.QueueService import delete_message [as 别名]
'redis_server': os.environ['REDIS_SERVER'],
'sms_user': os.environ['SMS_USER'],
'sms_pass': os.environ['SMS_PASS']
}
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']
sms_user = service_keys['sms_user']
sms_pass = service_keys['sms_pass']
# storage
queue_service = QueueService(account_name=stor_acc_name, account_key=stor_acc_key)
# redis
r = redis.StrictRedis(host=redis_server, port=6380, db=0, password=redis_pass, ssl=True)
while True:
messages = queue_service.get_messages('taskqueue', numofmessages=16, visibilitytimeout=5*60)
for message in messages:
d = json.loads(message.message_text)
suffix = d['suffix']
mobile = r.get(suffix)
image = d['image']
odp = str(image)
payload = {'username': sms_user, 'password': sms_pass, 'from': 'Alert', 'to': mobile, 'message': odp}
post = requests.post('https://api.smsapi.pl/sms.do', data=payload)
queue_service.delete_message('taskqueue', message.message_id, message.pop_receipt)