Google cloud dataflow 如何将自定义MyPipelineOptions传递给Google数据流DoFN?

Google cloud dataflow 如何将自定义MyPipelineOptions传递给Google数据流DoFN?,google-cloud-dataflow,apache-beam,Google Cloud Dataflow,Apache Beam,当我尝试将MyPipelineOptions参数添加到我的Google Dataflow DoFN时,我得到一个编译器错误: java.lang.IllegalArgumentException: com.xxx.MyProcessor, @ProcessElement parseItem(PubsubMessage, MyPipelineOptions, OutputReceiver), @ProcessElement parseItem(PubsubMessage, MyPipelineOp

当我尝试将MyPipelineOptions参数添加到我的Google Dataflow DoFN时,我得到一个编译器错误:

java.lang.IllegalArgumentException:
com.xxx.MyProcessor,
@ProcessElement parseItem(PubsubMessage, MyPipelineOptions, OutputReceiver),
@ProcessElement parseItem(PubsubMessage, MyPipelineOptions, OutputReceiver),
parameter of type MyPipelineOptions at index 1:
MyPipelineOptions is not a valid context parameter.
Should be one of [BoundedWindow, RestrictionTracker<?, ?>]
公共类MyProcessor扩展DoFn{
@过程元素
public void parseItem(@Element PubsubMessage message、MyPipelineOptions po、OutputReceiver out)引发异常{
...
}
}
注意:仅显示非自定义管线选项的示例:

PipelineOptions:通过将当前管道的PipelineOptions添加为参数,始终可以在流程方法中访问它:

.of(新的DoFn(){
公共无效处理元素(
@元素字符串字、管道选项){
}
})

确定找到问题。参数PipelineOptions是一个代理。为了正确获取,我需要执行以下操作:

公共类MyProcessor扩展DoFn{
@过程元素
公共项目(
@元素PubsubMessage消息,
管道选项po,
OutputReceiver(输出)抛出异常{
MyPipelineOptions opts=po.as(MyPipelineOptions.class);
...
}
}
}

通常我通过将其作为参数传递给构造函数来实现。如果我需要传递多个参数,并且忽略了管道选项可用性和设计的全部要点,请参阅“不太方便”。(plus没有解释为什么Beam explicity说它受支持。