問題描述
在使用Java 代碼向 Azure Event Hub發(fā)送數(shù)據(jù)時趣竣,先后遇見了如下兩種異常消息:
**1)ERROR c.t.d.h.s.source.EventHubLogConsumer - Error occurred in partition processor for partition **
com.azure.core.amqp.exception.AmqpException: New receiver '********-****-****-****-************' with higher epoch of '0' is created hence current receiver 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' with epoch '0' is getting disconnected. If you are recreating the receiver, make sure a higher epoch is used
2) ERROR c.a.c.amqp.implementation.RetryUtil - partitionId[null]: Sending messages timed out
問題解答
一:ERROR c.t.d.h.s.source.EventHubLogConsumer - Error occurred in partition processor for partition
New receiver '********-****-****-****-************' with higher epoch of '0' is created hence current receiver 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' with epoch '0' is getting disconnected
這個錯誤表明當前的客戶端已經(jīng)丟失了Event Hub的分區(qū)所有權(quán), 一個新的客戶端(receiver)搶占了當前分區(qū)的所有權(quán),分區(qū)中的消息會繼續(xù)由新的客戶端消費。所以當前消費端日志中出現(xiàn)這樣的錯誤日志蔽豺。
該錯誤主要起一個提示作用坪哄,對Event Hub消費數(shù)據(jù)無影響, 可以忽略。關(guān)于分區(qū)的所有權(quán)介紹,請參考:分區(qū)所有權(quán)(https://docs.azure.cn/zh-cn/event-hubs/event-processor-balance-partition-load#partition-ownership)
2) ERROR c.a.c.amqp.implementation.RetryUtil - partitionId[null]: Sending messages timed out
因為在發(fā)送消息的代碼中诗祸,添加了自定義元數(shù)據(jù)。而因為自定義元數(shù)據(jù)的值為null轴总,所以引發(fā)了發(fā)送消息time out的問題直颅。
通過實驗,添加 properties.put("test",null); 消息發(fā)送時怀樟,返回partitionId[null]: Sending messages timed out 異常功偿。如下圖:
自定義元數(shù)據(jù)的實例代碼見:向 Azure 事件中心中的事件添加自定義數(shù)據(jù):https://docs.azure.cn/zh-cn/event-hubs/add-custom-data-event#java
EventData firstEvent = new EventData("EventData Sample 1".getBytes(UTF_8));
firstEvent.getProperties().put("EventType", "com.microsoft.samples.hello-event");
firstEvent.getProperties().put("priority", 1);
firstEvent.getProperties().put("score", 9.0);
參考資料
分區(qū)所有權(quán) : https://docs.azure.cn/zh-cn/event-hubs/event-processor-balance-partition-load#partition-ownership
Azure 事件中心中的事件添加自定義數(shù)據(jù) :https://docs.azure.cn/zh-cn/event-hubs/add-custom-data-event#java
當在復雜的環(huán)境中面臨問題,格物之道需:濁而靜之徐清往堡,安以動之徐生械荷。 云中,恰是如此!
分類: 【Azure 事件中心】
標簽: Event Hub Java SDK, event.metadata["PartitionContext"]["PartitionId"], properties.put("test",null), Eventhub中發(fā)送數(shù)據(jù)異常