Documentation
¶
Index ¶
- type ApplicationRequestHandlerFunction
- type AuthInfo
- type ConnEvent
- type Connection
- type FrameHandlerFunc
- type IPBlockCheckHandler
- type MiddlewareFunc
- type MiddlewareRegistry
- type RawConnResult
- type RawConnection
- type RawConnectionListener
- func NewTcpConnectionListener(addr string) (RawConnectionListener, error)
- func NewWebSocketConnectionFromExistingHttpServer(httpServer *http.Server, handler *mux.Router, endpoint string, ...) (RawConnectionListener, error)
- func NewWebSocketConnectionListener(addr string, endpoint string, allowedOrigins []string, logger *slog.Logger, ...) (RawConnectionListener, error)
- type StompConfig
- type StompConn
- type StompServer
- type StompSessionEventType
- type SubscribeHandlerFunction
- type Subscription
- type UnsubscribeHandlerFunction
- type WebSocketStompConnection
- func (c *WebSocketStompConnection) Close() error
- func (c *WebSocketStompConnection) GetRemoteAddr() string
- func (c *WebSocketStompConnection) ReadFrame() (*frame.Frame, error)
- func (c *WebSocketStompConnection) SetReadDeadline(t time.Time)
- func (c *WebSocketStompConnection) WriteFrame(f *frame.Frame) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Connection ¶ added in v0.5.0
type Connection struct {
Source string
}
type FrameHandlerFunc ¶ added in v0.5.0
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 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)
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 Subscription ¶ added in v0.5.0
type Subscription struct {
// contains filtered or unexported fields
}
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
Click to show internal directories.
Click to hide internal directories.