pubsub

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: May 25, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package pubsub is the GCP PubSub implementation of an event stream.

Index

Examples

Constants

View Source
const (
	// TopicNameOption is the topic name option.
	TopicNameOption = "topic_name"

	// OrderingKeyOption is the ordering key option.
	OrderingKeyOption = "ordering_key"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Pubsub

type Pubsub struct {
	// contains filtered or unexported fields
}

Pubsub is the wrapper for the Pubsub library.

func New

func New(c *pubsub.Client) *Pubsub

New creates a new instance of Kinesis.

Example
package main

import (
	"context"
	"fmt"
	"os"

	pubsubraw "cloud.google.com/go/pubsub"
	"github.com/artsv79/outboxer"
	"github.com/artsv79/outboxer/es/pubsub"
)

func main() {
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	client, err := pubsubraw.NewClient(ctx, os.Getenv("GCP_PROJECT_ID"))
	if err != nil {
		fmt.Printf("failed to connect to gcp: %s", err)
		return
	}

	es := pubsub.New(client)

	// this is done internally by outboxer
	if err := es.Send(ctx, &outboxer.OutboxMessage{
		Payload: []byte("test payload"),
		Options: map[string]interface{}{
			pubsub.TopicNameOption:   "test",
			pubsub.OrderingKeyOption: "order",
		},
	}); err != nil {
		fmt.Printf("an error was not expected: %s", err)
		return
	}
}
Output:

func (*Pubsub) Send

func (p *Pubsub) Send(ctx context.Context, evt *outboxer.OutboxMessage) error

Send sends the message to the event stream.

Jump to

Keyboard shortcuts

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