'Java: PubsubMessage Subscriber receives message with no data or attribute

I'm trying to receive message to a topic and receive the message in the subscriber. But in the subscriber I don't receive any message, only an empty PubsubMessage.

Subscriber

package com.dsam.assignment02.functions;

import com.google.cloud.functions.BackgroundFunction;
import com.google.cloud.functions.Context;
import com.google.pubsub.v1.PubsubMessage;

import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.logging.Level;
import java.util.logging.Logger;

public class OrderBillPdfGeneratorFunction implements BackgroundFunction<PubsubMessage> {
    private static final Logger logger = Logger.getLogger(OrderBillPdfGeneratorFunction.class.getName());

    @Override
    public void accept(PubsubMessage payload, Context context) throws Exception {
        String s = payload.getData().isEmpty() ? "No data" : new String(
            Base64.getDecoder().decode(payload.getData().toByteArray()),
            StandardCharsets.UTF_8
        );
        String t = String.valueOf(payload.getAttributesCount());
        logger.log(Level.INFO, String.format("Data: %s\nAttribute Count: %s", s, t));
    }
}

Log Output

Data: No data
Attribute Count: 0

Any idea what I'm missing here?

Update

I published message from cloud console pub/sub topic, but still didn't receive any data, which rules out the possiblity of issue being related to the publisher code.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source