Documentation
¶
Overview ¶
Package pubsub provides helpers for converting CloudEvents to and from Google Cloud Pub/Sub messages.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FromCloudEvent ¶
FromCloudEvent converts a CloudEvent into a Pub/Sub message. Standard CloudEvent fields become message attributes and the event data becomes the body. The message carries no OrderingKey; use FromCloudEventWithOrdering to derive one from the event.
Example ¶
package main
import (
"context"
cloudevents "github.com/cloudevents/sdk-go/v2"
"github.com/chainguard-dev/terraform-infra-common/pkg/pubsub"
)
func main() {
ctx := context.Background()
event := cloudevents.NewEvent()
event.SetID("example-id")
event.SetSource("example/source")
event.SetType("example.type")
msg := pubsub.FromCloudEvent(ctx, event)
_ = msg
}
Output:
func FromCloudEventWithOrdering ¶ added in v1.8.0
FromCloudEventWithOrdering converts a CloudEvent into a Pub/Sub message like FromCloudEvent, and additionally sets the message OrderingKey from the event's CloudEvents Partitioning extension (partitionkey), per the CloudEvents Pub/Sub protocol binding.
Publishing a message with an OrderingKey requires EnableMessageOrdering on the publisher; without it, Publish rejects the message outright. An event without a partitionkey produces a message with no OrderingKey, which publishes fine either way.
Types ¶
This section is empty.