drone/events/stream.go
Johannes Batzill c3dadcce7b [Events] introduce options to event and stream framework (#255)
This change is adding the following:
- Add ConsumerOption and HandlerOption for configuring stream consumers and handlers.
- Add Readeroption and HandlerOption for configuring event readers and handlers
- Add HandlerOption and ReaderOption support to all existing event reader implementations
2023-01-28 13:34:04 -08:00

29 lines
984 B
Go

// Copyright 2022 Harness Inc. All rights reserved.
// Use of this source code is governed by the Polyform Free Trial License
// that can be found in the LICENSE.md file for this repository.
package events
import (
"context"
"github.com/harness/gitness/stream"
)
// StreamProducer is an abstraction of a producer from the streams package.
type StreamProducer interface {
Send(ctx context.Context, streamID string, payload map[string]interface{}) (string, error)
}
// StreamConsumer is an abstraction of a consumer from the streams package.
type StreamConsumer interface {
Register(streamID string, handler stream.HandlerFunc, opts ...stream.HandlerOption) error
Configure(opts ...stream.ConsumerOption)
Start(ctx context.Context) error
Errors() <-chan error
Infos() <-chan string
}
// StreamConsumerFactoryFunc is an abstraction of a factory method for stream consumers.
type StreamConsumerFactoryFunc func(groupName string, consumerName string) (StreamConsumer, error)