Skip to content

Different data incoming into local pubsub function #1144

@vongohren

Description

@vongohren

So here is a list of pictures with explanatory text to it. My plea is in the bottom :D

These three images explains the issue and outcome of what I struggle with understanding why is happening. Using the same local pubsub emulator, with two different methods of sending, results in different outcome.
Screenshot 2020-10-29 at 16 52 03
Screenshot 2020-10-29 at 16 50 29
Screenshot 2020-10-29 at 16 50 56

The one that I think is proper also outputs this line as the context: Screenshot 2020-10-29 at 16 51 32

The attempt that gives the proper result looks like this, directly copy paste from here: https://github.com/GoogleCloudPlatform/functions-framework-nodejs/blob/master/docs/events.md
Screenshot 2020-10-29 at 16 51 24

The effort that results in the wrong result is through code and this is the following code.

const publish = async (topicName, data) => {
  try {
    const messageId = uuid();
    const customAttributes = {
      messageId,
    };
    const payload = Buffer.from(JSON.stringify(data));
    const topic = await getTopic(topicName);
    const pubsubMessageId = await topic.publish(payload, customAttributes);
    logger.info(`Message ${pubsubMessageId} published. Unique payload ID: ${messageId}`);
  } catch (err) {
    logger.error(err.message, { status: err.status, err: err, stack: err.stack, });
    throw err;
  }
};

const getTopic = async (name) => {
  try {
    const [ topic, ] = await pubsub.createTopic(name);
    return topic;
  } catch (err) {
    if (err.code === ErrorCodes.AlreadyExists) {
      return pubsub.topic(name);
    }
    throw err;
  }
};

So my plea

What are the reasons this might happen, I cannot try to think that one way or the other the first variable can be undefined, so just wondering what is wrong

Metadata

Metadata

Assignees

No one assigned

    Labels

    api: pubsubIssues related to the googleapis/nodejs-pubsub API.type: questionRequest for information or clarification. Not an issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions