Is there a way to receive a message from pubsub in Java code and then turn that code into a String of some sort to be parsed for which can then be used as input variables in code?
有没有办法从Java代码中的pubsub接收消息,然后将该代码转换为某种类型的字符串进行解析,然后可以将其用作代码中的输入变量?
I have retrieved the pubsub message using PubSubIO, However I only know how to get it as a PCollection of Strings or as a side input using views, however I cannot find anyway to get an actual string out of this data for use in the Java code.
我已经使用PubSubIO检索了pubsub消息,但是我只知道如何将它作为字符串的PCollection或使用视图作为侧输入,但无论如何我无法找到从这些数据中获取实际字符串以用于Java代码。
Can anyone point me in the right direction?
谁能指出我正确的方向?
Thanks!
谢谢!
2 个解决方案
#1
2
If I'm understanding your question correctly, this is not possible. It's not possible to use the value of an element from the PCollection
outside of the definition of the Pipeline
. Intuitively, it seems like this is possible when writing the Java code (possibly no compilation errors), but this is not how Apache Beam actually works. I imagine you'd get some kind of runtime/serialization error during execution.
如果我正确理解你的问题,这是不可能的。在管道定义之外的PCollection中不可能使用元素的值。直观地说,在编写Java代码时可能会出现这种情况(可能没有编译错误),但这并不是Apache Beam实际工作的方式。我想你在执行期间会遇到某种运行时/序列化错误。
Presumably, you want to use some value of an element to alter the Pipeline
. In this case, you'd need to know all of the possible values ahead of time in order to partition/construct the Pipeline
; the values need to be predetermined.
据推测,您希望使用元素的某个值来更改管道。在这种情况下,您需要提前知道所有可能的值,以便分区/构造管道;价值需要预先确定。
#2
2
Maybe I'm misunderstanding, but what exactly is the problem? Yes, PubsubIO.readStrings() will produce a PColleciton of Strings, not Strings per se, but the next transform that will be chained to this one will receive those Strings, so you can easily apply JAVA code to each of them there using ProcessContext.element() within the @ProcessElement function of that transform. That's where you do all your splitting/etc. Is that what you are after?
也许我误解了,但究竟是什么问题?是的,PubsubIO.readStrings()将生成一个字符串的PColleciton,而不是字符串本身,但下一个将链接到这个字符串的转换将接收这些字符串,因此您可以使用ProcessContext轻松地将JAVA代码应用于每个字符串。该变换的@ProcessElement函数中的element()。这就是你所做的所有分裂/等等。这就是你追求的吗?
#1
2
If I'm understanding your question correctly, this is not possible. It's not possible to use the value of an element from the PCollection
outside of the definition of the Pipeline
. Intuitively, it seems like this is possible when writing the Java code (possibly no compilation errors), but this is not how Apache Beam actually works. I imagine you'd get some kind of runtime/serialization error during execution.
如果我正确理解你的问题,这是不可能的。在管道定义之外的PCollection中不可能使用元素的值。直观地说,在编写Java代码时可能会出现这种情况(可能没有编译错误),但这并不是Apache Beam实际工作的方式。我想你在执行期间会遇到某种运行时/序列化错误。
Presumably, you want to use some value of an element to alter the Pipeline
. In this case, you'd need to know all of the possible values ahead of time in order to partition/construct the Pipeline
; the values need to be predetermined.
据推测,您希望使用元素的某个值来更改管道。在这种情况下,您需要提前知道所有可能的值,以便分区/构造管道;价值需要预先确定。
#2
2
Maybe I'm misunderstanding, but what exactly is the problem? Yes, PubsubIO.readStrings() will produce a PColleciton of Strings, not Strings per se, but the next transform that will be chained to this one will receive those Strings, so you can easily apply JAVA code to each of them there using ProcessContext.element() within the @ProcessElement function of that transform. That's where you do all your splitting/etc. Is that what you are after?
也许我误解了,但究竟是什么问题?是的,PubsubIO.readStrings()将生成一个字符串的PColleciton,而不是字符串本身,但下一个将链接到这个字符串的转换将接收这些字符串,因此您可以使用ProcessContext轻松地将JAVA代码应用于每个字符串。该变换的@ProcessElement函数中的element()。这就是你所做的所有分裂/等等。这就是你追求的吗?