Skip to content

WritePubSubMessage requires pubsubMessage to have Attributes #1092

@toshi38

Description

@toshi38

Since the change in #976 it seems that Attributes property needs to be defined on the output message prior to calling WritePubSubMessage previously this wasn't strictly needed (at least it didn't exist this way in our code).

Which raises the question, should I need to have an Attributes field prior to calling WritePubSubMessage() or should it work with an empty message?

Alternatively is there a proper way that I should instantiate a pubsub.Message other than how I have below?

Broken:

import("github.com/cloudevents/sdk-go/v2/binding")
	
func writeMsg(ctx context.Context, in binding.Message) {
  msg := &pubsub.Message{}

  err := WritePubSubMessage(ctx, in, msg);  // Results in Panic
  
  //Do something with msg

}

Working:

import("github.com/cloudevents/sdk-go/v2/binding")
	
func writeMsg(ctx context.Context, in binding.Message) {
msg := &pubsub.Message{
	Attributes: AttributesFrom(ctx),
}

  err := WritePubSubMessage(ctx, in, msg); // Does not result in Panic
  
  //Do something with msg

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions