pubsub

package
v1.35.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 28, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

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

func FromCloudEvent(ctx context.Context, event cloudevents.Event) *pubsub.Message

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
}

func FromCloudEventWithOrdering added in v1.8.0

func FromCloudEventWithOrdering(ctx context.Context, event cloudevents.Event) *pubsub.Message

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL