Closed darshanmehta10 closed 6 years ago
You have to first use a ParDo which converts your strings into PubsubMessages and then apply PubsubIO.writeMessages(). For example:
return collection.apply(ParDo.of(myDoFnThatConvertsStringsToPubsubMessagesWithAttributes))
.apply(PubsubIO.writeMessages().to(topic));
As a side note, please never use expand as it is the wrong API to apply transforms to PCollections. You should always rely on PCollection.apply(PTransform)
.
I am using the below code to publish messages to Pubsub from dataflow:
I want to write custom attributes as Key Value pairs with messages, such as
"type" : "some_type"
However, the library only allows to setId
andTimestamp
attribute names but not the custom ones.Is there any way to set these attributes/values?