Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BufferPolicy ¶ added in v1.1.0
type BufferPolicy int
const ( DropNone BufferPolicy = iota DropOldest DropOldestAfterTimeout DropNewest DropNewestAfterTimeout )
type Intracom ¶
type Intracom[T any] struct { // contains filtered or unexported fields }
Intracom is an in-memory pub/sub wrapper to enable communication between routines.
func (*Intracom[T]) Close ¶
Close will shutdown the Intracom instance and all of its subscriptions. Intracom instance will no longer be usable after calling this function. This function is not safe to call from multiple routines and should only be called once from the parent thread designated to manage the Intracom instance.
NOTE: Calling Register() or Subscribe() after calling Close will panic.
Returns: - error: nil if successful, error if not.
func (*Intracom[T]) Register ¶ added in v1.1.0
Register will register a topic with the Intracom instance. It is safe to call this function multiple times for the same topic. If the topic already exists, this function will return the existing publisher channel.
Parameters: - topic: name of the topic to register
Returns: - publishC: the channel used to publish messages to the topic - unregister: a function bound to this topic that can be used to unregister the topic
func (*Intracom[T]) SetLogHandler ¶ added in v1.1.0
SetLogHandler will set the logger used by the Intracom instance. If this function is not called, the slog Default() log handler will be used. NOTE: This function must be called before intracom.Start()
Parameters: - handler: a slog.Handler interface to use for logging
func (*Intracom[T]) Start ¶ added in v1.1.0
Start will enable the broker to start processing requests. If the broker is already running, this function will return an error.
NOTE: This function must be called before Register, Subscribe, or Close. This function is not thread-safe and should only be called once from the parent thread designated to manage the Intracom instance.
func (*Intracom[T]) Subscribe ¶
func (i *Intracom[T]) Subscribe(conf SubscriberConfig) (<-chan T, func())
Subscribe will be used to subscribe to a topic. It is safe to call this function multiple times from multiple routines.
* If the topic does not exist, it will be automatically registered. * If the consumer group already exists, the existing channel will be returned. * If the consumer group does not exist, it will be created.
Parameters:
- conf: a pointer to a SubscriberConfig struct, a nil pointer will use default values (not recommended). Default values: -- Topic: "" -- ConsumerGroup: "" -- BufferSize: 1 -- BufferPolicy: DropNone
Returns: - ch: the channel used to receive messages from the topic - unsubscribe: a function bound to this subscription that can be used to unsubscribe the consumer group