azure-sdk-for-java eventhubs 分区已丢失

azure-sdk-for-java eventhubs Partition has been lost

我们最近通过关注 azure-docs.

部署了 azure event-hub java receiver/listener 客户端

我确实相信数组是从0开始的,但这与本题无关。所以无论如何,我观察到 processErrorprocessPartitionClose

引发的以下错误
Error occurred in partition14 - connectionId[MF_5fba9c_1636350888640] sessionName[eventhub-name/ConsumerGroups/consumer-group-name/Partitions/14] entityPath[eventhub-name/ConsumerGroups/consumer-group-name/Partitions/14] linkName[14_500701_1636350888641] Cannot create receive link from a closed session., errorContext[NAMESPACE: namespace.servicebus.windows.net. ERROR CONTEXT: N/A, PATH: eventhub-name/ConsumerGroups/consumer-group-name/Partitions/14]
ERROR  | Partition has been lost 14 reason LOST_PARTITION_OWNERSHIP

问题:

  1. 是否 azure-sdk-for-java-sdk-eventhubs 在这样的分区上自动重新连接丢失?
  2. 如果 NOT 那么手动重新启动之前的最佳做法是什么?
    • 我需要手动更新检查点吗?
    • 我需要对所有权做任何事情吗?

这是我们带有示例代码的 sdk 设置

EventProcessorClientBuilder eventProcessorClientBuilder = new EventProcessorClientBuilder()
                .checkpointStore(new BlobCheckpointStore(blobContainerAsyncClient))
                .connectionString(getEventHubConnectionString(), getEventHubName())
                .consumerGroup(getConsumerGroup())
                .initialPartitionEventPosition(initialPartitionEventPosition)
                .processEvent(PARTITION_PROCESSOR)
                .processError(ERROR_HANDLER)
                .processPartitionClose(CLOSE_HANDLER);

 EventProcessorClient eventProcessorClient = eventProcessorClientBuilder.buildEventProcessorClient();
 // Starts the event processor
 eventProcessorClient.start();

 private final Consumer < ErrorContext > ERROR_HANDLER = errorContext->{
     log.error("Error occurred in partition" + errorContext.getPartitionContext().getPartitionId()
          + " - " + errorContext.getThrowable().getMessage());
 };

 private final Consumer < CloseContext > CLOSE_HANDLER = closeContext->{
     log.error("Partition has been lost " + closeContext.getPartitionContext().getPartitionId()
          + " reason " + closeContext.getCloseReason());

     EventContext lastContext = lastEvent.get();
     if (lastContext != null && (lastContext.getEventData().getSequenceNumber() % 10) != 0) {
         lastContext.updateCheckpoint();
     }
 };

jdk : 1.8

<dependency>
    <groupId>com.azure</groupId>
    <artifactId>azure-messaging-eventhubs-checkpointstore-blob</artifactId>
    <version>1.10.0</version>
</dependency>

<dependency>
    <groupId>com.azure</groupId>
    <artifactId>azure-messaging-eventhubs</artifactId>
    <version>5.10.1</version>
</dependency>

我确实遇到了 github-issue-15164,但在提到的任何地方都找不到。

Do azure-sdk-for-java-sdk-eventhubs reconnect on such partition lost automatically ?

是的,azure-messaging-eventhubs 库中的 EventProcessorClient 将在此类分区上重新连接。您无需手动更改任何内容。

如果 EventProcessorClients 运行 有多个实例,并且它们都处理来自同一个事件中心的事件并使用同一个使用者组,那么你会看到这个 LOST_PARTITION_OWNERSHIP 错误一个处理器,因为分区的所有权可能已被另一个处理器占用。检查点从检查点存储(上面代码示例中的 Storage Blob)读取,处理从下一个序列号恢复。

详情请参考partition ownership and checkpointing