问题描述

在使用Java 代码向 Azure Event Hub发送数据时,先后遇见了如下两种异常消息:

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

 

这个错误表明当前的客户端已经丢失了Event Hub的分区所有权, 一个新的客户端(receiver)抢占了当前分区的所有权,分区中的消息会继续由新的客户端消费。所以当前消费端日志中出现这样的错误日志。

该错误主要起一个提示作用,对Event Hub消费数据无影响, 可以忽略。关于分区的所有权介绍,请参考:分区所有权(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

因为在发送消息的代码中,添加了自定义元数据。而因为自定义元数据的值为null,所以引发了发送消息time out的问题。

通过实验,添加 properties.put("test",null); 消息发送时,返回 partitionId[null]: Sending messages timed out 异常。如下图:

自定义元数据的实例代码见:向 Azure 事件中心中的事件添加自定义数据: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);

 

 

参考资料

分区所有权 : https://docs.azure.cn/zh-cn/event-hubs/event-processor-balance-partition-load#partition-ownership

Azure 事件中心中的事件添加自定义数据 :https://docs.azure.cn/zh-cn/event-hubs/add-custom-data-event#java

查看原文