broker

package
v0.1.53 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: LGPL-2.1 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Name  = self.Name
	Using = self.Using
)
View Source
var (
	// ErrUnsubscribed is an error indicating that the subscriber has been unsubscribed. It is returned by the ISyncSubscriber.Next method when the subscriber has been unsubscribed.
	ErrUnsubscribed = errors.New("broker: unsubscribed")
)
View Source
var With _Option

Functions

func MakeReadChan

func MakeReadChan(broker IBroker, ctx context.Context, pattern, queue string, size int, recyclable ...bool) (<-chan binaryutil.RecycleBytes, error)

MakeReadChan creates a new channel for receiving data from a specific pattern.

func MakeWriteChan

func MakeWriteChan(broker IBroker, topic string, size int, errorHandler ...ErrorHandler) chan<- binaryutil.RecycleBytes

MakeWriteChan creates a new channel for publishing data to a specific topic.

Types

type DeliveryReliability

type DeliveryReliability int32

DeliveryReliability Message delivery reliability.

const (
	AtMostOnce      DeliveryReliability = iota // At most once
	AtLeastOnce                                // At last once
	ExactlyOnce                                // Exactly once
	EffectivelyOnce                            // Effectively once
)

type ErrorHandler

type ErrorHandler = generic.DelegateAction1[error] // 错误处理器

type EventHandler

type EventHandler = generic.DelegateFunc1[IEvent, error]

EventHandler is used to process messages via a subscription of a topic. The handler is passed a publication interface which contains the message and optional Ack method to acknowledge receipt of the message.

type IBroker

type IBroker interface {
	// Publish the data argument to the given topic. The data argument is left untouched and needs to be correctly interpreted on the receiver.
	Publish(ctx context.Context, topic string, data []byte) error
	// Subscribe will express interest in the given topic pattern. Use option EventHandler to handle message events.
	Subscribe(ctx context.Context, pattern string, settings ...option.Setting[SubscriberOptions]) (ISubscriber, error)
	// SubscribeSync will express interest in the given topic pattern.
	SubscribeSync(ctx context.Context, pattern string, settings ...option.Setting[SubscriberOptions]) (ISyncSubscriber, error)
	// SubscribeChan will express interest in the given topic pattern.
	SubscribeChan(ctx context.Context, pattern string, settings ...option.Setting[SubscriberOptions]) (IChanSubscriber, error)
	// Flush will perform a round trip to the server and return when it receives the internal reply.
	Flush(ctx context.Context) error
	// GetDeliveryReliability return message delivery reliability.
	GetDeliveryReliability() DeliveryReliability
	// GetMaxPayload return max payload bytes.
	GetMaxPayload() int64
	// GetSeparator return topic path separator.
	GetSeparator() string
}

IBroker is an interface used for asynchronous messaging.

type IChanSubscriber

type IChanSubscriber interface {
	ISubscriber
	// EventChan returns a channel that can be used to receive events from the subscriber.
	EventChan() (<-chan IEvent, error)
}

IChanSubscriber is a convenience return type for the IBroker.SubscribeChan method.

type IEvent

type IEvent interface {
	// Pattern returns the subscription pattern used to create the event subscriber.
	Pattern() string
	// Topic returns the topic the event was received on.
	Topic() string
	// Queue subscribers with the same queue name will create a shared subscription where each receives a subset of messages.
	Queue() string
	// Message returns the raw message payload of the event.
	Message() []byte
	// Ack acknowledges the successful processing of the event. It indicates that the event can be removed from the subscription queue.
	Ack(ctx context.Context) error
	// Nak negatively acknowledges a message. This tells the server to redeliver the message.
	Nak(ctx context.Context) error
}

IEvent is given to a subscription handler for processing.

type ISubscriber

type ISubscriber interface {
	context.Context
	// Pattern returns the subscription pattern used to create the subscriber.
	Pattern() string
	// Queue subscribers with the same queue name will create a shared subscription where each receives a subset of messages.
	Queue() string
	// Unsubscribe unsubscribes the subscriber from the topic.
	Unsubscribe() <-chan struct{}
}

ISubscriber is a convenience return type for the IBroker.Subscribe method.

type ISyncSubscriber

type ISyncSubscriber interface {
	ISubscriber
	// Next is a blocking call that waits for the next event to be received from the subscriber.
	Next() (IEvent, error)
}

ISyncSubscriber is a convenience return type for the IBroker.SubscribeSync method.

type SubscriberOptions

type SubscriberOptions struct {
	// AutoAck defaults to true. When a handler returns with a nil error the message is acked.
	AutoAck bool
	// Queue subscribers with the same queue name will create a shared subscription where each receives a subset of messages.
	Queue string
	// EventHandler is the function that will be called to handle the received events.
	EventHandler EventHandler
	// EventChanSize specifies the size of the event channel used for received synchronously event.
	EventChanSize int
	// UnsubscribedCB Unsubscribed callback method.
	UnsubscribedCB UnsubscribedCB
}

SubscriberOptions represents the options for subscribe topic.

type UnsubscribedCB

type UnsubscribedCB = generic.DelegateAction1[ISubscriber]

UnsubscribedCB Unsubscribed callback method.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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