[英]Azure Eventhubs (Python): checkpointing with blob storage - keyerror issue in EventProcessor when checkpointing is enabled
我在 eventthubs 中遇到 blob 存儲檢查點問題。 如果我在獲取消費者客戶端時沒有設置 checkpoint_store,我的應用程序運行良好。 每當我嘗試設置 checkpoint_store 變量並運行我的代碼時,它都會引發以下異常:
EventProcessor 實例 'xxxxxxxxxxx' 的 eventthub <name of my eventthub> 消費者組 <name of my consumer group>。 負載平衡和聲明所有權時出錯。 例外是 KeyError('ownerid')。 xxxx 秒后重試
我能找到的唯一一個 github 條目甚至提到了這種錯誤,但是問題本身從未解決,有問題的人最終改用了不同的庫。
我正在使用的相關庫是 azure-eventhub 和 azure-eventhub-checkpointstoreblob-aio
以下是我正在使用的代碼的相關片段( 我使用本教程作為指南):
import asyncio
from azure.eventhub.aio import EventHubConsumerClient, EventHubProducerClient
from azure.eventhub import EventData
from azure.eventhub.extensions.checkpointstoreblobaio import BlobCheckpointStore
async def on_event(partition_context, event):
await partition_context.update_checkpoint(event)
#<do stuff with event data>
checkpoint_store = BlobCheckpointStore.from_connection_string(blob_connection_string, container_name)
client = EventHubConsumerClient.from_connection_string(connection_str, consumer_group, eventhub_name=input_eventhub_name, checkpoint_store=checkpoint_store)
async def main():
async with client:
await client.receive(
on_event=on_event,
)
print("Terminated.")
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
問題似乎完全在於 blob 存儲檢查點; 如果我在創建消費者客戶端時注釋掉“checkpoint_store=checkpoint_store”,那么一切運行都沒有問題。
與 blob 存儲的連接看起來很好,因為我進行了一些挖掘,發現在 blob 存儲中創建了一些文件夾“檢查點”和“所有權”: blob 存儲快照后者包含一些帶有“ownerid”的文件在他們的元數據中:所有者文件元數據
即密鑰肯定存在。 我認為正在發生的是 EventProcessor 正在嘗試獲取這些 blob 的所有權元數據,但不知何故未能這樣做。 如果有人對如何解決此問題有任何想法,我將不勝感激!
這看起來像是從其中一個 blob 中檢索“ownerid”的問題。 你能幫我測試一下這些場景嗎?
"owner_id": blob.metadata.get("ownerid"),
根本原因是存儲 sdk 的list_blobs
功能在啟用數據湖(分層命名空間)的 v2 存儲 blob 上調用時,不僅會獲得每個分區的檢查點/所有權,還會獲得不包含元數據的父 blob 節點。
為了更好地說明這一點,假設我們有以下 blob 結構:
- fullqualifiednamespace (directory)
- eventhubname (directory)
- $default (directory)
- ownership (directory)
- 0 (blob)
- 1 (blob)
...
在啟用數據湖(分層命名空間)的 v2 存儲中,當代碼使用前綴{<fully_qualified_namespace>/<eventhub_name>/<consumer_group>/ownership
搜索 blob 時, {<fully_qualified_namespace>/<eventhub_name>/<consumer_group>/ownership
當我們嘗試提取信息時, {<fully_qualified_namespace>/<eventhub_name>/<consumer_group>/ownership
目錄本身也將返回,其中不包含導致KeyError
的元數據。
checkpointstoreblob sdk 有一個錯誤修復版本,請升級到最新版本,看看它是否能解決您的問題。
如果您有更多問題,請告訴我。
鏈接:
同步: https://pypi.org/project/azure-eventhub-checkpointstoreblob/1.1.2/
對於異步: https://pypi.org/project/azure-eventhub-checkpointstoreblob-aio/1.1.2/
github 問題: https://github.com/Azure/azure-sdk-for-python/issues/13060
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.