0

我写了一个 queueTrigger - Azure 函数

def main(msg: func.QueueMessage) -> None:
    logging.info('Python queue trigger function processed a queue item: %s',
                 msg.get_body().decode('utf-8'))
    
    mk_client = MyKiosk()
    storage = StorageAccount(os.environ["AzureWebJobsStorage"])

    data = mk_client.get_allgroupdata()


    for i in data:
        main_id = i["HauptgruppeId"]
        for j in i["Untergruppe"]:
            sub_id = j["UntergruppeId"]
            outbound_msg = {"mainid_val": main_id,"subid_val": sub_id,"n_records": 12}
              
              <code to remove duplicates>

            storage.write_queue_message("pricequeue", json.dumps(outbound_msg))

这是我的 QueueTrigger 脚本,我想确保“outbound_msg”中没有重复,并且可以在“pricequeue”中写入唯一消息

4

1 回答 1

0

您可以使用Popleftcollections dequeue从队列触发 python 脚本中删除重复项

下面是使用的示例脚本popleft

>>> from collections import deque
>>> queue = deque(["Eric", "John", "Michael"])
>>> queue.append("Terry")           # Terry arrives
>>> queue.append("Graham")          # Graham arrives
>>> queue.popleft()                 # The first to arrive now leaves
'Eric'
>>> queue.popleft()                 # The second to arrive now leaves
'John'
>>> queue                           # Remaining queue in order of arrival
deque(['Michael', 'Terry', 'Graham'])

此外,这里还有一些其他链接,它们将为您提供有关删除重复项的完整信息,并且正在进行相关讨论。

于 2022-01-31T10:45:38.237 回答