Documentation
¶
Index ¶
- Constants
- func Close(ic *Intracom) error
- func CreateSubscription[T any](ctx context.Context, ic *Intracom, topic string, maxWait time.Duration, ...) (<-chan T, error)
- func RemoveSubscription[T any](ic *Intracom, topic string, consumer string, ch <-chan T) error
- func RemoveTopic[T any](ic *Intracom, name string) error
- type Action
- type Broadcaster
- type BufferPolicyDropNewest
- type BufferPolicyDropNewestAfterTimeout
- type BufferPolicyDropNone
- type BufferPolicyDropOldest
- type BufferPolicyDropOldestAfterTimeout
- type BufferPolicyHandler
- type Channel
- type ChannelCloser
- type ChannelSender
- type ErrIntracom
- type ErrSubscribe
- type ErrTopic
- type Error
- type Intracom
- type Option
- type SubscriberConfig
- type Subscription
- type SyncBroadcaster
- type Topic
- type TopicConfig
- type TopicOption
Constants ¶
const ( ErrInvalidIntracomNil = Error("invalid intracom, cannot be nil") ErrIntracomClosed = Error("intracom is closed") ErrTopicNotFound = Error("topic not found") ErrTopicAlreadyExists = Error("topic already exists") ErrTopicDoesNotExist = Error("topic does not exist") ErrInvalidTopicType = Error("topic exists but with a different type") ErrTopicClosed = Error("topic is closed") ErrConsumerAlreadyExists = Error("consumer already exists") ErrMaxTimeoutReached = Error("max timeout reached") )
const ( ActionClosingIntracom = Action("closing intracom") ActionClosingTopic = Action("closing topic") ActionRemovingTopic = Action("removing topic") ActionCreatingTopic = Action("creating topic") ActionRemovingSubscription = Action("removing subscription") ActionCreatingSubscription = Action("creating subscription") )
Variables ¶
This section is empty.
Functions ¶
func CreateSubscription ¶
func CreateSubscription[T any](ctx context.Context, ic *Intracom, topic string, maxWait time.Duration, conf SubscriberConfig[T]) (<-chan T, error)
CreateSubscription will (if set) wait a max timeout for a topic to exist and the proceed to subscribe to that topic. If the topic does not exist within the maxWait duration, an error is returned. If maxWait is 0, the function will wait indefinitely for the topic to exist. If the intracom is closed, an error is returned. If the context is canceled, a context error is returned.
func RemoveSubscription ¶
RemoveSubscription removes a subscription from a topic consumer name and consumer channel are required to remove the subscription. Normally whoever created the subscription should also be in-charge of removing it.
Types ¶
type Broadcaster ¶ added in v1.2.1
type BufferPolicyDropNewest ¶ added in v1.2.1
type BufferPolicyDropNewest[T any] struct{}
func (BufferPolicyDropNewest[T]) Handle ¶ added in v1.2.1
func (d BufferPolicyDropNewest[T]) Handle(ch chan T, message T, stopC <-chan struct{}) error
type BufferPolicyDropNewestAfterTimeout ¶ added in v1.2.1
type BufferPolicyDropNewestAfterTimeout[T any] struct { Timer *time.Timer DropTimout time.Duration }
func (BufferPolicyDropNewestAfterTimeout[T]) Handle ¶ added in v1.2.1
func (d BufferPolicyDropNewestAfterTimeout[T]) Handle(ch chan T, message T, stopC <-chan struct{}) error
type BufferPolicyDropNone ¶ added in v1.2.1
type BufferPolicyDropNone[T any] struct{}
func (BufferPolicyDropNone[T]) Handle ¶ added in v1.2.1
func (d BufferPolicyDropNone[T]) Handle(ch chan T, message T, stopC <-chan struct{}) error
type BufferPolicyDropOldest ¶ added in v1.2.1
type BufferPolicyDropOldest[T any] struct{}
func (BufferPolicyDropOldest[T]) Handle ¶ added in v1.2.1
func (d BufferPolicyDropOldest[T]) Handle(ch chan T, message T, stopC <-chan struct{}) error
type BufferPolicyDropOldestAfterTimeout ¶ added in v1.2.1
type BufferPolicyDropOldestAfterTimeout[T any] struct { Timer *time.Timer DropTimeout time.Duration }
func (BufferPolicyDropOldestAfterTimeout[T]) Handle ¶ added in v1.2.1
func (d BufferPolicyDropOldestAfterTimeout[T]) Handle(ch chan T, message T, stopC <-chan struct{}) error
type BufferPolicyHandler ¶ added in v1.2.1
type Channel ¶ added in v1.2.1
type Channel[T any] interface { ChannelCloser[T] ChannelSender[T] Chan() <-chan T }
type ChannelCloser ¶ added in v1.2.1
type ChannelSender ¶ added in v1.2.1
type ErrIntracom ¶
func (ErrIntracom) Error ¶
func (e ErrIntracom) Error() string
type ErrSubscribe ¶
func (ErrSubscribe) Error ¶
func (e ErrSubscribe) Error() string
type Intracom ¶
type Intracom struct {
// contains filtered or unexported fields
}
Intracom acts as a registry for all topic channels. The Intracom struct is thread-safe and can be used concurrently. Use the pure generic functions below to operate against the Intracom struct: CreateTopic, CreateSubscription, RemoveSubscription, Close
type SubscriberConfig ¶
type Subscription ¶
type SyncBroadcaster ¶ added in v1.2.1
type SyncBroadcaster[T any] struct { SubscriberAware bool // if true, broadcaster wont broadcast if there are no subscribers. }
func (SyncBroadcaster[T]) Broadcast ¶ added in v1.2.1
func (b SyncBroadcaster[T]) Broadcast(requests <-chan any, broadcast chan T)
type Topic ¶
type Topic[T any] interface { Name() string // Name returns the unique name of the topic. PublishChannel() chan<- T // PublishChannel returns the channel publishers use to send messages to the topic. Subscribe(ctx context.Context, conf SubscriberConfig[T]) (<-chan T, error) // Subscribe will attemp to add a consumer group to the topic. Unsubscribe(consumer string, ch <-chan T) error // Unsubscribe will remove the consumer group from the topic and close the subscriber channel. Close() error // Close will remove all consumer groups from the topic and close all channels. }
func CreateTopic ¶
func CreateTopic[T any](ic *Intracom, conf TopicConfig) (Topic[T], error)
CreateTopic creates a new topic with the given configuration. Topic names must be unique, if the topic already exists, an error is returned.
func NewTopic ¶ added in v1.2.1
func NewTopic[T any](conf TopicConfig, opts ...TopicOption[T]) Topic[T]
type TopicConfig ¶
type TopicOption ¶ added in v1.2.1
type TopicOption[T any] func(*topic[T])
func WithBroadcaster ¶ added in v1.2.1
func WithBroadcaster[T any](b Broadcaster[T]) TopicOption[T]