Documentation
¶
Overview ¶
Package GoBroke provides a flexible message broker implementation for handling client-to-client and client-to-logic communication patterns. It supports different types of message routing, client management, and custom logic handlers.
Package GoBroke provides configuration options for the GoBroke message broker system.
Package GoBroke provides the base implementation for logic handlers in the GoBroke message broker system.
Index ¶
- func WithChannelSize(size int) brokeOptsFunc
- func WithContext(ctx context.Context) brokeOptsFunc
- type Broke
- func (broke *Broke) AddLogic(logic types.Logic) error
- func (broke *Broke) AttachReceiveMiddleware(mFunc middlewareFunc)
- func (broke *Broke) AttachSendMiddleware(mFunc middlewareFunc)
- func (broke *Broke) GetAllClients() []*clients.Client
- func (broke *Broke) GetClient(uuid string) (*clients.Client, error)
- func (broke *Broke) RegisterClient(client *clients.Client) error
- func (broke *Broke) RemoveClient(client *clients.Client) error
- func (broke *Broke) RemoveLogic(name types.LogicName) error
- func (broke *Broke) SendMessage(message types.Message)
- func (broke *Broke) SendMessageQuickly(message types.Message)
- func (broke *Broke) Start()
- type LogicBase
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithChannelSize ¶
func WithChannelSize(size int) brokeOptsFunc
WithChannelSize returns a brokeOptsFunc that sets the message channel buffer size. This affects how many messages can be queued before blocking occurs.
func WithContext ¶
WithContext returns a brokeOptsFunc that sets a custom context for the broker. The context can be used to control the broker's lifecycle and pass values.
Types ¶
type Broke ¶
type Broke struct {
// contains filtered or unexported fields
}
Broke represents a message broker instance that manages client connections, message routing, and custom logic handlers.
func New ¶
New creates a new GoBroke instance with the specified endpoint and optional configuration. It returns an error if the endpoint is nil or if there are issues setting up message queues.
func (*Broke) AddLogic ¶
AddLogic adds a new logic handler to the GoBroke instance. It returns an error if a logic handler with the same name already exists.
func (*Broke) AttachReceiveMiddleware ¶ added in v0.0.2
func (broke *Broke) AttachReceiveMiddleware(mFunc middlewareFunc)
AttachReceiveMiddleware adds a middleware function to the receive message pipeline. Middleware functions are executed in the order they are attached and can modify or filter messages before they are processed by the broker.
The middleware function receives a Message and returns a modified Message or nil if the message should be dropped from the pipeline.
func (*Broke) AttachSendMiddleware ¶ added in v0.0.2
func (broke *Broke) AttachSendMiddleware(mFunc middlewareFunc)
AttachSendMiddleware adds a middleware function to the send message pipeline. Middleware functions are executed in the order they are attached and can modify or filter messages before they are sent to clients.
The middleware function receives a Message and returns a modified Message or nil if the message should be dropped from the pipeline.
func (*Broke) GetAllClients ¶
GetAllClients returns a slice containing all currently connected clients.
func (*Broke) GetClient ¶
GetClient retrieves a client by their UUID. It returns the client instance and nil if found, or nil and an error if not found.
func (*Broke) RegisterClient ¶
RegisterClient registers a new client in the GoBroke instance. This method should be called from the endpoint implementation. It returns an error if the client is already registered.
func (*Broke) RemoveClient ¶
RemoveClient removes a client from the GoBroke instance and disconnects them from the endpoint. It returns an error if the client doesn't exist or if the disconnection fails.
func (*Broke) RemoveLogic ¶
RemoveLogic removes a logic handler from the GoBroke instance by its name. It returns nil even if the logic handler doesn't exist.
func (*Broke) SendMessage ¶
SendMessage queues a message for processing by GoBroke. This method can be used to send messages to both logic handlers and clients. If the message is from a client, their last message timestamp is updated.
func (*Broke) SendMessageQuickly ¶
SendMessageQuickly sends a message directly to the endpoint for processing. This method should only be used for client-to-client communication as it bypasses logic handlers.
type LogicBase ¶
type LogicBase struct { Ctx context.Context // Context for cancellation and value propagation *Broke // Embedded broker instance for accessing broker functionality // contains filtered or unexported fields }
LogicBase provides a base implementation of the types.Logic interface. It implements common functionality that can be embedded in specific logic handlers.
func NewLogicBase ¶
NewLogicBase creates a new LogicBase instance with the specified configuration. Parameters:
- name: Unique identifier for the logic handler
- logicType: Determines how messages are processed (WORKER, DISPATCHED, or PASSIVE)
- broke: Reference to the broker instance
Returns a LogicBase configured with the provided parameters and a derived context.
Directories
¶
Path | Synopsis |
---|---|
Package clients provides client management functionality for the GoBroke system.
|
Package clients provides client management functionality for the GoBroke system. |
Package endpoint defines the interface for communication endpoints in the GoBroke system.
|
Package endpoint defines the interface for communication endpoints in the GoBroke system. |
Package brokeerrors provides error definitions for the GoBroke message broker system.
|
Package brokeerrors provides error definitions for the GoBroke message broker system. |
examples
|
|
logic/broadcaster
Package broadcaster provides example implementations of logic handlers for broadcasting messages.
|
Package broadcaster provides example implementations of logic handlers for broadcasting messages. |
logic/inactivitymonitor
Package inactivitymonitor provides a passive logic handler that monitors client activity and automatically removes clients that have been inactive for a specified duration.
|
Package inactivitymonitor provides a passive logic handler that monitors client activity and automatically removes clients that have been inactive for a specified duration. |
Package message provides message creation and management functionality for the GoBroke system.
|
Package message provides message creation and management functionality for the GoBroke system. |
Package types provides core type definitions for the GoBroke message broker system.
|
Package types provides core type definitions for the GoBroke message broker system. |