Documentation
¶
Index ¶
- Constants
- func FrameScanner(conn io.Reader) <-chan []byte
- func StartTcpBroker(host, port string) error
- func StopTcpBroker()
- type AckMode
- type ClientHandler
- func (c *ClientHandler) BeginTransaction() (*Transaction, error)
- func (c *ClientHandler) Connect(useStompCmd bool) error
- func (c *ClientHandler) Disconnect() error
- func (c *ClientHandler) Send(dest string, body []byte, contentType string, customHeaders map[string]string) error
- func (c *ClientHandler) SetMessageHandler(handlerFunc MessageHandlerFunc)
- func (c *ClientHandler) Subscribe(dest string, mode AckMode) (*Subscription, error)
- type ClientOpts
- type Command
- type Frame
- type FrameSource
- type Header
- type LoginFunc
- type MessageHandlerFunc
- type SessionHandler
- type Subscription
- type Transaction
- type UserMessage
Constants ¶
const (
DefaultPort = "61613"
)
const (
// DisconnectID is used as a `receipt` header value in the DISCONNECT message from client
DisconnectID = "BYE-BYE!"
)
Variables ¶
This section is empty.
Functions ¶
func FrameScanner ¶
FrameScanner reads from the reader and splits the byte-stream into chucks around the Frame delimiter/length. These chunks are then sent over the returned channel.
func StartTcpBroker ¶
StartTcpBroker is the entry point for starting a TCP server for STOMP broker
func StopTcpBroker ¶
func StopTcpBroker()
StopTcpBroker closes the TCP connection and turns off the server
Types ¶
type ClientHandler ¶
type ClientHandler struct { SessionID string // Session ID for the connection with the STOMP Broker // contains filtered or unexported fields }
ClientHandler is the control struct for Client's connection with the STOMP Broker
func NewClientHandler ¶
func NewClientHandler(conn net.Conn, opts *ClientOpts) *ClientHandler
NewClientHandler creates the Client for STOMP
func StartTcpClient ¶
func StartTcpClient(host, port string, fn MessageHandlerFunc) (*ClientHandler, error)
StartTcpClient is an entry point for connecting to the TCP STOMP broker. Apart from the hostname and port for the TCP server, it also accepts a function of type MessageHandlerFunc (defined as `func(message *UserMessage)`). This function definition is provided by the user and servers as a callback that processes every MESSAGE received from the STOMP broker.
func (*ClientHandler) BeginTransaction ¶
func (c *ClientHandler) BeginTransaction() (*Transaction, error)
func (*ClientHandler) Connect ¶
func (c *ClientHandler) Connect(useStompCmd bool) error
Connect connects with the broker and starts listening to the messages from broker
func (*ClientHandler) Disconnect ¶
func (c *ClientHandler) Disconnect() error
func (*ClientHandler) SetMessageHandler ¶
func (c *ClientHandler) SetMessageHandler(handlerFunc MessageHandlerFunc)
SetMessageHandler accepts the user-defined function to handle the messages
func (*ClientHandler) Subscribe ¶
func (c *ClientHandler) Subscribe(dest string, mode AckMode) (*Subscription, error)
type ClientOpts ¶
type ClientOpts struct { Host string // Virtual host Login string // AuthN Username Passcode string // AuthN Password HeartBeat [2]int // HeartBeats config [2]int{ outgoing-freq, incoming-freq } MessageHandler MessageHandlerFunc // User-defined callback function to handle MESSAGEs }
ClientOpts provides the options as argument to NewClientHandler
type Command ¶
type Command string
Command represents the STOMP message-type
const ( CmdConnected Command = "CONNECTED" CmdMessage Command = "MESSAGE" CmdReceipt Command = "RECEIPT" CmdError Command = "ERROR" )
Server Frame Commands
const ( CmdConnect Command = "CONNECT" CmdStomp Command = "STOMP" CmdSend Command = "SEND" CmdSubscribe Command = "SUBSCRIBE" CmdUnsubscribe Command = "UNSUBSCRIBE" CmdAck Command = "ACK" CmdNack Command = "NACK" CmdBegin Command = "BEGIN" CmdCommit Command = "COMMIT" CmdAbort Command = "ABORT" CmdDisconnect Command = "DISCONNECT" )
Client Frame Commands
type Frame ¶
type Frame struct {
// contains filtered or unexported fields
}
Frame represents the stomp protocol frame
func NewFrameFromBytes ¶
NewFrameFromBytes creates a new Frame that is populated with deserialized raw input
func (*Frame) Deserialize ¶
Deserialize takes the wire-format and unmarshalls it into Frame struct. It also internally validates the wire-format while parsing to some extent.
func (*Frame) Validate ¶
func (f *Frame) Validate(s FrameSource) error
Validate checks both client and server STOMP frames. It also checks if the mandatory headers are present for a given message.
type FrameSource ¶
type FrameSource int
FrameSource is the source of frame: either Broker or Client
const ( ServerFrame FrameSource = 0 ClientFrame FrameSource = 1 )
Modes: server/client
type Header ¶
type Header string
Header represents the header-keys in the STOMP Frame
const ( HdrKeyAcceptVersion Header = "accept-version" HdrKeyAck Header = "ack" HdrKeyContentLength Header = "content-length" HdrKeyContentType Header = "content-type" HdrKeyDestination Header = "destination" HdrKeyHeartBeat Header = "heart-beat" HdrKeyHost Header = "host" HdrKeyID Header = "id" HdrKeyLogin Header = "login" HdrKeyMessage Header = "message" HdrKeyMessageID Header = "message-id" HdrKeyPassCode Header = "passcode" HdrKeyReceipt Header = "receipt" HdrKeyReceiptID Header = "receipt-id" HdrKeyServer Header = "server" HdrKeySession Header = "session" HdrKeySubscription Header = "subscription" HdrKeyTransaction Header = "transaction" HdrKeyVersion Header = "version" )
Frame headers
type MessageHandlerFunc ¶
type MessageHandlerFunc func(message *UserMessage)
MessageHandlerFunc is the function-type for user-defined function to handle the messages
type SessionHandler ¶
type SessionHandler struct {
// contains filtered or unexported fields
}
SessionHandler handles the STOMP client session on connection
func NewSessionHandler ¶
func NewSessionHandler(conn net.Conn, loginFunc LoginFunc) *SessionHandler
NewSessionHandler creates a new session object & maintains the session state internally
func (*SessionHandler) Start ¶
func (sh *SessionHandler) Start()
Start begins the STOMP session with the Client
type Subscription ¶
type Subscription struct { SubsID string // contains filtered or unexported fields }
Subscription represents the state of subscription
func (*Subscription) Unsubscribe ¶
func (s *Subscription) Unsubscribe() error
type Transaction ¶
type Transaction struct { TxID string // contains filtered or unexported fields }
Transaction represents the state of transaction
func (*Transaction) AbortTransaction ¶
func (t *Transaction) AbortTransaction() error
func (*Transaction) CommitTransaction ¶
func (t *Transaction) CommitTransaction() error
type UserMessage ¶
type UserMessage struct { Headers map[string]string // STOMP and custom headers received in MESSAGE Body []byte // MESSAGE payload }
UserMessage represents the messages and the user-headers to be received by the user