stompserver

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2025 License: BSD-2-Clause Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApplicationRequestHandlerFunction

type ApplicationRequestHandlerFunction func(destination string, message []byte, connectionId string)

type AuthInfo added in v0.5.0

type AuthInfo struct {
	Username string
	Id       int
	Roles    []string
}

AuthInfo holds authentication details for the user.

func (*AuthInfo) HasRole added in v0.5.0

func (a *AuthInfo) HasRole(role string) bool

HasRole returns true if the user has the specified role.

type ConnEvent

type ConnEvent struct {
	ConnId string
	// contains filtered or unexported fields
}

type Connection added in v0.5.0

type Connection struct {
	Source string
}

type FrameHandlerFunc added in v0.5.0

type FrameHandlerFunc func(conn StompConn, f *frame.Frame) error

FrameHandlerFunc is a function that processes a STOMP frame.

func ChainCommandMiddleware added in v0.5.0

func ChainCommandMiddleware(reg MiddlewareRegistry, command string, coreHandler FrameHandlerFunc) FrameHandlerFunc

ChainCommandMiddleware returns a FrameHandlerFunc that wraps the provided core handler with both global middleware (key "*") and command-specific middleware.

func ChainMiddleware added in v0.5.0

func ChainMiddleware(mws []MiddlewareFunc, final FrameHandlerFunc) FrameHandlerFunc

ChainMiddleware applies the list of middleware in order so that the first in the slice is the outermost middleware.

type IPBlockCheckHandler added in v0.6.0

type IPBlockCheckHandler func(ip string) (blocked bool, errorMessage string)

type MiddlewareFunc added in v0.5.0

type MiddlewareFunc func(FrameHandlerFunc) FrameHandlerFunc

MiddlewareFunc is a function that wraps a FrameHandlerFunc.

func AuthzMiddleware added in v0.5.0

func AuthzMiddleware(action string) MiddlewareFunc

AuthzMiddleware returns a MiddlewareFunc that performs an authorization check. It expects that the frame has a Destination header. The `action` is a label (e.g., "send" or "subscribe") used for logging or error messages.

type MiddlewareRegistry added in v0.5.0

type MiddlewareRegistry map[string][]MiddlewareFunc

type RawConnResult added in v0.5.0

type RawConnResult struct {
	Conn RawConnection
	Err  error
}

type RawConnection

type RawConnection interface {
	// ReadFrame Reads a single frame object
	ReadFrame() (*frame.Frame, error)
	// WriteFrame Sends a single frame object
	WriteFrame(frame *frame.Frame) error
	// SetReadDeadline Set deadline for reading frames
	SetReadDeadline(t time.Time)
	// GetRemoteAddr Returns the remote address of the connection
	GetRemoteAddr() string
	// Close the connection
	Close() error
}

type RawConnectionListener

type RawConnectionListener interface {
	// Accept Blocks until a new RawConnection is established.
	Accept() (RawConnection, error)
	// Close Stops the connection listener.
	Close() error

	// GetConnectionOpenChannel will return a channel that emits connection results when clients connect.
	GetConnectionOpenChannel() chan *Connection

	// GetConnectionCloseChannel will return a channel the emits connection result when clients disconnect.
	GetConnectionCloseChannel() chan *Connection
}

func NewTcpConnectionListener

func NewTcpConnectionListener(addr string) (RawConnectionListener, error)

func NewWebSocketConnectionFromExistingHttpServer

func NewWebSocketConnectionFromExistingHttpServer(httpServer *http.Server, handler *mux.Router,
	endpoint string, allowedOrigins []string, logger *slog.Logger, debug bool, customSocketFunc http.HandlerFunc) (RawConnectionListener, error)

func NewWebSocketConnectionListener

func NewWebSocketConnectionListener(addr string, endpoint string, allowedOrigins []string, logger *slog.Logger, debug bool) (RawConnectionListener, error)

type StompConfig

type StompConfig interface {
	HeartBeat() int64
	AppDestinationPrefix() []string
	IsAppRequestDestination(destination string) bool
	GetMiddlewareRegistry() MiddlewareRegistry
	SetMiddlewareRegistry(registry MiddlewareRegistry)
}

func NewStompConfig

func NewStompConfig(heartBeatMs int64, appDestinationPrefix []string) StompConfig

type StompConn

type StompConn interface {
	// Return unique connection Id string
	GetId() string
	// Return IP address of the connection
	GetIPAddress() string
	SendFrameToSubscription(f *frame.Frame, sub *Subscription)
	Close()
	GetSubscriptions() map[string]*Subscription
	GetEventsChannel() chan *ConnEvent
	SendError(err error)
	SendMessage(msg string)
}

func NewStompConn

func NewStompConn(rawConnection RawConnection, config StompConfig, events chan *ConnEvent) StompConn

type StompServer

type StompServer interface {
	// starts the server
	Start()
	// stops the server
	Stop()
	// sends a message to a given stomp topic destination
	SendMessage(destination string, messageBody []byte)
	// sends a message to a single connection client
	SendMessageToClient(connectionId string, destination string, messageBody []byte)
	// closes all connections from a specific IP address with a custom error message
	CloseConnectionsByIP(ip string, errorMessage string)
	// sets an IP blocking checker function that gets called before allowing connections
	SetIPBlockChecker(checker IPBlockCheckHandler)
	// registers a callback for stomp subscribe events
	OnSubscribeEvent(callback SubscribeHandlerFunction)
	// registers a callback for stomp unsubscribe events
	OnUnsubscribeEvent(callback UnsubscribeHandlerFunction)
	// registers a callback for application requests
	OnApplicationRequest(callback ApplicationRequestHandlerFunction)
	// SetConnectionEventCallback is used to set up a callback when certain STOMP session events happen
	// such as ConnectionStarting, ConnectionClosed, SubscribeToTopic, UnsubscribeFromTopic and IncomingMessage.
	SetConnectionEventCallback(connEventType StompSessionEventType, cb func(connEvent *ConnEvent))
}

func NewStompServer

func NewStompServer(listener RawConnectionListener, config StompConfig) StompServer

type StompSessionEventType

type StompSessionEventType int
const (
	ConnectionStarting StompSessionEventType = iota
	ConnectionEstablished
	ConnectionClosed
	SubscribeToTopic
	UnsubscribeFromTopic
	IncomingMessage
)

type SubscribeHandlerFunction

type SubscribeHandlerFunction func(conId string, subId string, destination string, frame *frame.Frame)

type Subscription added in v0.5.0

type Subscription struct {
	// contains filtered or unexported fields
}

type UnsubscribeHandlerFunction

type UnsubscribeHandlerFunction func(conId string, subId string, destination string)

type WebSocketStompConnection added in v0.5.0

type WebSocketStompConnection struct {
	WSCon *websocket.Conn
	// contains filtered or unexported fields
}

func (*WebSocketStompConnection) Close added in v0.5.0

func (c *WebSocketStompConnection) Close() error

func (*WebSocketStompConnection) GetRemoteAddr added in v0.6.0

func (c *WebSocketStompConnection) GetRemoteAddr() string

func (*WebSocketStompConnection) ReadFrame added in v0.5.0

func (c *WebSocketStompConnection) ReadFrame() (*frame.Frame, error)

func (*WebSocketStompConnection) SetReadDeadline added in v0.5.0

func (c *WebSocketStompConnection) SetReadDeadline(t time.Time)

func (*WebSocketStompConnection) WriteFrame added in v0.5.0

func (c *WebSocketStompConnection) WriteFrame(f *frame.Frame) error

Jump to

Keyboard shortcuts

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