我已启用将日志导出到 pub 子主题。我正在使用数据流来处理这些日志并将相关列存储在 BigQuery 中。有人可以帮助将 pubsub 消息有效负载转换为LogEntry
对象。我尝试了以下代码:
@ProcessElement
public void processElement(ProcessContext c) throws Exception {
PubsubMessage pubsubMessage = c.element();
ObjectMapper mapper = new ObjectMapper();
byte[] payload = pubsubMessage.getPayload();
String s = new String(payload, "UTF8");
LogEntry logEntry = mapper.readValue(s, LogEntry.class);
}
但我收到以下错误:
com.fasterxml.jackson.databind.JsonMappingException: Can not find a (Map) Key deserializer for type [simple type, class com.google.protobuf.Descriptors$FieldDescriptor]
编辑:我尝试了以下代码:
try {
ByteArrayInputStream stream = new ByteArrayInputStream(Base64.decodeBase64(pubsubMessage.getPayload()));
LogEntry logEntry = LogEntry.parseDelimitedFrom(stream);
System.out.println("Log Entry = " + logEntry);
} catch (InvalidProtocolBufferException e) {
e.printStackTrace();
}
但我现在收到以下错误:
com.google.protobuf.InvalidProtocolBufferException: Protocol message end-group tag did not match expected tag