从pubsub读取时有两种方法“ withCoderAndParseFn”,而在写入pubsub时有“ withFormatFn”方法。这些功能对于读取或写入消息时的解析很有用。也许您可以通过在其中应用自己的逻辑来使用它们,例如登录到stackdriver或将错误数据推送到pubsub。
更多信息,请点击这里
https://www.codota.com/web/assistant/code/rs/5c6563f8138b620001f3aa7c#L470
PubsubIO.<t>read().withCoderAndParseFn(coder,new ParsePayloadUsingCoder<>(coder));
private static class ParsePayloadUsingCoder<t> extends SimpleFunction<pubsubmessage,t=""> {
private Coder<t> coder;
public ParsePayloadUsingCoder(Coder<t> coder) {
this.coder = coder;
}
@Override
public T apply(PubsubMessage input) {
try {
return CoderUtils.decodeFromByteArray(coder,input.getPayload());
} catch (CoderException e) {
throw new RuntimeException("Could not decode Pubsub message",e);
}
}
}
本文链接:https://www.f2er.com/3151093.html