最终找到了解决方案.编码不正确-内置的writeBytes()方法会自动为您写入长度.
然后,在使用者中,我们必须通过GenericDatumWriter进行操作,写入二进制流,然后使用ReflectDatumReader从二进制流中进行读取.这将自动调用UUIAsBytesEncoding read()方法并反序列化UUID.
我的使用者看起来像这样(作为使用者组执行者服务walkthrough here的一部分):
/**
* Start a single consumer instance
* This will use the schema built into the IndexedRecord to decode and create key/value for the message
*/
public void run() {
ConsumerIterator it = this.stream.iterator();
while (it.hasNext()) {
MessageAndMetadata messageAndMetadata = it.next();
try {
String key = (String) messageAndMetadata.key();
IndexedRecord value = (IndexedRecord) messageAndMetadata.message();
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
GenericDatumWriter genericRecordWriter = new GenericDatumWriter<>(value.getSchema());