有什么办法只能从旧偏移量中寻找 1 条消息吗?

Is there any way I can only seek 1 message from the old offset?

我想知道有什么办法只能从旧偏移量中寻找 1 条消息吗?因为我只想重新处理 1 条消息。

您应该实施 ConsumerSeekAware 并在其:

/**
 * When using group management, called when partition assignments change.
 * @param assignments the new assignments and their current offsets.
 * @param callback the callback to perform an initial seek after assignment.
 */
void onPartitionsAssigned(Map<TopicPartition, Long> assignments, ConsumerSeekCallback callback);

在所需的 partition 上执行所需的 -1,并将其 offset 作为该 assignments 映射中的值。