stomp

package
v0.2.18 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2022 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultPort = "61613"
)

Variables

This section is empty.

Functions

func ReleaseVersion added in v0.2.16

func ReleaseVersion() string

ReleaseVersion returns the version of the go-proto-stomp module

Types

type AckMode

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

Header values for AckMode

type Broker added in v0.2.15

type Broker interface {
	// ListenAndServe is a blocking method that keeps accepting the client connections and handles the STOMP messages.
	ListenAndServe()

	// Shutdown should be called to bring down the underlying server gracefully.
	Shutdown()
}

Broker lists the methods supported by the STOMP brokers

func StartBroker added in v0.2.15

func StartBroker(opts *BrokerOpts) (Broker, error)

StartBroker is the entry point for the STOMP broker.

type BrokerOpts added in v0.2.16

type BrokerOpts struct {
	// Transport refers to the underlying protocol for STOMP.
	// Choices: TransportTCP, TransportWebsocket. Default: TransportTCP
	Transport Transport

	// Host is the name of the host or IP to bind the server to. Default: localhost
	Host string

	// Port is the port number for the server to listen on. Default: 61613 (DefaultPort)
	Port string

	// LoginFunc is a user defined function for authenticating the user. Default: nil
	// It is of the form `func(login, passcode string) error`
	LoginFunc LoginFunc

	// HeartbeatSendIntervalMsec is the interval in milliseconds by which the broker can send heartbeats.
	// The broker will negotiate using this value with the client. Default: 0 (no heartbeats)
	// It will not send the heartbeats by an interval any smaller than this value.
	HeartbeatSendIntervalMsec int

	// HeartbeatReceiveIntervalMsec is the interval in milliseconds by which the broker can receive heartbeats.
	// The broker will negotiate using this value with the client. Default: 0 (no heartbeats)
	// This is to tell the client that the broker cannot receive heartbeats by any shorter interval than this value.
	HeartbeatReceiveIntervalMsec int
}

BrokerOpts is passed as an argument to StartBroker

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(transport Transport, host, port string, opts *ClientOpts) *ClientHandler

NewClientHandler creates the Client for STOMP

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 {
	VirtualHost              string             // Virtual host
	Login                    string             // AuthN Username
	Passcode                 string             // AuthN Password
	HeartbeatSendInterval    int                // Sending interval of heartbeats in milliseconds
	HeartbeatReceiveInterval int                // Receiving interval of heartbeats in milliseconds
	MessageHandler           MessageHandlerFunc // User-defined callback function to handle MESSAGE
}

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 Session added in v0.2.16

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

Session handles the STOMP client session on connection

func NewSession added in v0.2.16

func NewSession(conn net.Conn, loginFunc LoginFunc, wg *sync.WaitGroup,
	heartbeatSendIntervalMsec, heartbeatReceiveIntervalMsec int,
) *Session

NewSession creates a new session object & maintains the session state internally

func (*Session) Start added in v0.2.16

func (sess *Session) Start()

Start begins the STOMP session with the Client

type Subscription

type Subscription struct {
	SubsID      string
	Destination 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 Transport added in v0.2.15

type Transport string

Transport represents the underlying transporting protocol for STOMP

const (
	TransportTCP       Transport = "TCP"       // STOMP over TCP
	TransportWebsocket Transport = "Websocket" // STOMP over Websocket
)

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