I have two Google Cloud functions, one that publishes and another that subscribes.
This is the code
public void publisXeroTeannt(XeroTenant xeroTenant) {
Gson gson = new Gson();
String xeroTenantMessage = gson.toJson(xeroTenant);
ByteString byteString = ByteString.copyFrom(xeroTenantMessage, StandardCharsets.UTF_8);
PubsubMessage pubsubMessage = PubsubMessage.newBuilder()
.setData(byteString)
.build();
log.info("Data being published in string utf 8 is {}", pubsubMessage.getData().toStringUtf8());
publisher.publish(pubsubMessage);
}
When I publish, I can clearly see the log
The tenant Id being published is f837ea57-feae-4965-92c5-bc1b7cd6b2a0"
I have a subscriber
@Override
public void accept(CloudEvent event) throws Exception {
try {
String cloudEventData = new String(event.getData().toBytes(), StandardCharsets.UTF_8);
Gson gson = new Gson();
PubsubMessage pubsubMessage = gson.fromJson(cloudEventData, PubsubMessage.class);
String encodedData = pubsubMessage.getData().toStringUtf8();
String decodedData =
new String(Base64.getDecoder().decode(encodedData), StandardCharsets.UTF_8);
log.info("Decoded message is {}", decodedData);
} catch (Exception e) {
log.error("Error in processing message", e);
}
}
But the log always says it's an empty message
INFO com.demo.SubscriberFunction - The decoded message is
What's wrong here?