stomp

package
v0.2.9 Latest Latest
Warning

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

Go to latest
Published: May 31, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultPort = "61613"
)
View Source
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

func FrameScanner(conn io.Reader) <-chan []byte

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

func StartTcpBroker(host, port string) error

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 AckMode

type AckMode string
const (
	HdrValAckAuto             AckMode = "auto"
	HdrValAckClient           AckMode = "client"
	HdrValAckClientIndividual AckMode = "client-individual"
)

Header values for AckMode

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) Send

func (c *ClientHandler) Send(dest string, body []byte, contentType string, customHeaders map[string]string) 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 NewFrame

func NewFrame(cmd Command, headers map[Header]string, body []byte) *Frame

NewFrame creates an empty new Frame

func NewFrameFromBytes

func NewFrameFromBytes(raw []byte) (*Frame, error)

NewFrameFromBytes creates a new Frame that is populated with deserialized raw input

func (*Frame) Deserialize

func (f *Frame) Deserialize(buf []byte) error

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) Serialize

func (f *Frame) Serialize() []byte

Serialize marshals the Frame struct into wire-format of the protocol

func (Frame) String

func (f Frame) String() string

String method gives a printable version of the Frame

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 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 LoginFunc

type LoginFunc func(login, passcode string) error

LoginFunc represents the user-defined authentication function

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

func (*Transaction) Send

func (t *Transaction) Send(dest string, body []byte, contentType string, headers map[string]string) 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

Jump to

Keyboard shortcuts

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