In R, I want to build json content according this Google Cloud Pub Sub message format: https://cloud.google.com/pubsub/docs/reference/rest/v1/PubsubMessage
It have to respect :
{
"data": string,
"attributes": {
string: string,
...
},
"messageId": string,
"publishTime": string,
"orderingKey": string
}
The message built will be readed from this Python code:
def pubsub_read(data, context):
'''This function is executed from a Cloud Pub/Sub'''
message = base64.b64decode(data['data']).decode('utf-8')
file_name = data['attributes']['file_name']
This following R code builds a R dataframe and converts it to json content:
library(jsonlite)
data="Hello World!"
df <- data.frame(data)
attributes <- data.frame(file_name=c('gfs_data_temp_FULL.csv'))
df$attributes <- attributes
msg <- df %>%
toJSON(auto_unbox = TRUE, dataframe = 'columns', pretty = T) %>%
# Pub/Sub expects a base64 encoded string
googlePubsubR::msg_encode() %>%
googlePubsubR::PubsubMessage()
It seems good but when I visualise it with a json editor :
indexes are added.
Additionally there is the message content:

I dont'sure it respects Google Cloud Pub Sub message format...
