我想为我们从主题中消耗的东西生成唯一的有序Id,而且它应该在多个实例中是唯一的。(不是uuid)
不知道为什么你不想使用UUID。但你可以使用偏移量和分区号的组合来计算一个唯一的ID。比如说:
// you need to know upfront how many partitions the input topis has
private final static int NUMBER_OF_PARTITIONS = ...
// within `Transformer#transform()` using `KStream#transform()`
// (also consider to use #transformValues() instead).
// `context` is given via `init()`
long id = context.offset() * NUMBER_OF_PARTITIONS + context.partition();