pubsub

package
v1.35.3 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: MPL-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSubscriptionTopicNotResource = errRange.New(
		"Invalid call to pubsub.NewSubscription",
		"pubsub.NewSubscription requires the first argument to be a resource of type pubsub.Topic.",
		errors.PrependDetails(pubsubNewSubscriptionHelp),
	)

	ErrTopicNameNotUnique = errRange.New(
		"Duplicate PubSub topic name",
		"A PubSub topic name must be unique within a service.",

		errors.PrependDetails("If you wish to reuse the same topic, then you can export the original Topic object import it here."),
	)

	ErrSubscriptionNameNotUnique = errRange.New(
		"Duplicate PubSub subscription on topic",
		"Subscription names on topics must be unique.",
	)

	ErrUnableToIdentifyServicesInvolved = errRange.New(
		"Unable to identify services involved",
		"Unable to identify services involved in the PubSub subscription.",
		errors.MarkAsInternalError(),
	)

	ErrSubscriptionHandlerNotDefinedInSameService = errRange.New(
		"Invalid PubSub subscription handler",
		"The handler for the subscription must be defined in the same service as the call to pubsub.NewSubscription.",
		errors.PrependDetails(pubsubNewSubscriptionHelp),
	)

	ErrTopicRefOutsideService = errRange.New(
		"Call to pubsub.TopicRef outside service",
		"pubsub.TopicRef can only be called from within a service.",
	)

	ErrInvalidMethodHandler = errRange.New(
		"Invalid call to pubsub.MethodHandler",
		"pubsub.MethodHandler requires the first argument to be a reference to a method on a service struct.",
		errors.PrependDetails(pubsubMethodHandlerHelp),
	)

	ErrMethodHandlerTypeNotServiceStruct = errRange.New(
		"Invalid call to pubsub.MethodHandler",
		"pubsub.MethodHandler can only reference methods that are defined on service structs.",
		errors.PrependDetails(pubsubMethodHandlerHelp),
	)

	ErrMethodHandlerDifferentPackage = errRange.New(
		"Invalid call to pubsub.MethodHandler",
		"pubsub.MethodHandler can only reference the service struct defined in the same package as the subscription.",
		errors.PrependDetails(pubsubMethodHandlerHelp),
	)
)
View Source
var SubscriptionParser = &resourceparser.Parser{
	Name: "PubSub Subscription",

	InterestingImports: []paths.Pkg{"encore.dev/pubsub"},
	Run: func(p *resourceparser.Pass) {
		name := pkginfo.QualifiedName{Name: "NewSubscription", PkgPath: "encore.dev/pubsub"}

		spec := &parseutil.ReferenceSpec{
			MinTypeArgs: 0,
			MaxTypeArgs: 1,
			Parse:       parsePubSubSubscription,
		}

		parseutil.FindPkgNameRefs(p.Pkg, []pkginfo.QualifiedName{name}, func(file *pkginfo.File, name pkginfo.QualifiedName, stack []ast.Node) {
			parseutil.ParseReference(p, spec, parseutil.ReferenceData{
				File:         file,
				Stack:        stack,
				ResourceFunc: name,
			})
		})
	},
}
View Source
var TopicParser = &resourceparser.Parser{
	Name: "PubSub Topic",

	InterestingImports: []paths.Pkg{"encore.dev/pubsub"},
	Run: func(p *resourceparser.Pass) {
		name := pkginfo.QualifiedName{Name: "NewTopic", PkgPath: "encore.dev/pubsub"}

		spec := &parseutil.ReferenceSpec{
			MinTypeArgs: 1,
			MaxTypeArgs: 1,
			Parse:       parsePubSubTopic,
		}

		parseutil.FindPkgNameRefs(p.Pkg, []pkginfo.QualifiedName{name}, func(file *pkginfo.File, name pkginfo.QualifiedName, stack []ast.Node) {
			parseutil.ParseReference(p, spec, parseutil.ReferenceData{
				File:         file,
				Stack:        stack,
				ResourceFunc: name,
			})
		})
	},
}

Functions

func ResolveTopicUsage

func ResolveTopicUsage(data usage.ResolveData, topic *Topic) usage.Usage

Types

type DeliveryGuarantee

type DeliveryGuarantee int
const (
	AtLeastOnce DeliveryGuarantee = iota
	ExactlyOnce
)

type MethodHandler added in v1.20.0

type MethodHandler struct {
	// The type declaration the handler is a method on.
	Decl *pkginfo.PkgDeclInfo
	// Method is the name of the method.
	Method string
}

MethodHandler is used to describe a handler that references a method on a service struct.

type Perm

type Perm string
const (
	PublishPerm Perm = "publish"
)

type PublishUsage

type PublishUsage struct {
	usage.Base
}

type RefUsage

type RefUsage struct {
	usage.Base
	Perms []Perm
}

func (*RefUsage) HasPerm added in v1.16.0

func (u *RefUsage) HasPerm(perm Perm) bool

type Subscription

type Subscription struct {
	AST   *ast.CallExpr
	File  *pkginfo.File
	Name  string // The unique name of the pub sub subscription
	Doc   string // The documentation on the pub sub subscription
	Topic pkginfo.QualifiedName
	Cfg   SubscriptionConfig

	// Handler is the AST expression defining the handler function.
	Handler ast.Expr

	// MethodHandler specifies whether the handler is a method on a service struct.
	MethodHandler option.Option[MethodHandler]
}

func (*Subscription) ASTExpr

func (s *Subscription) ASTExpr() ast.Expr

func (*Subscription) End

func (s *Subscription) End() token.Pos

func (*Subscription) Kind

func (s *Subscription) Kind() resource.Kind

func (*Subscription) Package

func (s *Subscription) Package() *pkginfo.Package

func (*Subscription) Pos

func (s *Subscription) Pos() token.Pos

func (*Subscription) ResourceName

func (s *Subscription) ResourceName() string

func (*Subscription) SortKey added in v1.16.3

func (s *Subscription) SortKey() string

type SubscriptionConfig

type SubscriptionConfig struct {
	AckDeadline      time.Duration
	MessageRetention time.Duration
	MinRetryBackoff  time.Duration
	MaxRetryBackoff  time.Duration
	MaxRetries       int
	MaxConcurrency   int
}

type Topic

type Topic struct {
	AST               *ast.CallExpr
	File              *pkginfo.File
	Name              string              // The unique name of the pub sub topic
	Doc               string              // The documentation on the pub sub topic
	DeliveryGuarantee DeliveryGuarantee   // What guarantees does the pub sub topic have?
	OrderingAttribute string              // What field in the message type should be used to ensure First-In-First-Out (FIFO) for messages with the same key
	MessageType       *schema.TypeDeclRef // The message type of the pub sub topic
}

func (*Topic) ASTExpr

func (t *Topic) ASTExpr() ast.Expr

func (*Topic) End

func (t *Topic) End() token.Pos

func (*Topic) Kind

func (t *Topic) Kind() resource.Kind

func (*Topic) Package

func (t *Topic) Package() *pkginfo.Package

func (*Topic) Pos

func (t *Topic) Pos() token.Pos

func (*Topic) ResourceName

func (t *Topic) ResourceName() string

func (*Topic) SortKey added in v1.16.3

func (t *Topic) SortKey() string

Jump to

Keyboard shortcuts

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