Azure: How to move messages from poison queue to back to main queue?

前端 未结 7 1794
慢半拍i
慢半拍i 2020-12-30 06:57

I\'m wondering if there is a tool or lib that can move messages between queues? Currently, i\'m doing something like below

public static void ProcessQueueMes         


        
相关标签:
7条回答
  • 2020-12-30 07:46

    Updated python based on Jon Canning's answer:

    from azure.storage.queue import QueueServiceClient
    
    
    queueService = QueueServiceClient.from_connection_string(conn_str="DefaultEndpointsProtocol=https;AccountName=<account>;AccountKey=<key>;EndpointSuffix=core.windows.net")
    
    for queue in queueService.list_queues():
      if "poison" in queue.name:
        print(queue.name)
        targetQueueName = queue.name.replace("-poison", "")
        queue = queueService.get_queue_client(queue=queue.name)
        targetQueue = queueService.get_queue_client(queue=targetQueueName)
        while queue.peek_messages() :
            messages = queue.receive_messages()
            for msg in messages:
                targetQueue.send_message(msg.content)
                queue.delete_message(msg)            
    
    0 讨论(0)
提交回复
热议问题