stompngo

package module
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2018 License: Apache-2.0 Imports: 17 Imported by: 0

README

stompngo - A STOMP 1.1+ Client Package

Features

References

Installation

Installation requires a working go environment. For current versions of go issue:

  • go get github.com/gmallard/stompngo

The GOPATH environment variable must be set properly.

Examples

The examples in the included unit tests can be used as a good starting point.

Also see the examples project:

QA

The tests for this STOMP client package run against recent releases of:

See the tests for relevant environment variables.

Contributions

Any and all are welcome by pull request or e-mail patch.

Wiki

News and notes will be posted from time to time at the stompngo wiki:

Please review and update that on occaision.

Canonical Repository

For the record, the canonical repository for this project is at:

Issues

Please review issues at the canonical repository. File any new issues there as well:

Contributors (by first author date)

Contribution information (maintained semiautomatically, best efforts basis):

First Author Date (Commit Count) Name / E-mail
2011-10-10 (0240) gmallard / <allard.guy.m@gmail.com>
2014-02-02 (0001) Kelsey Hightower / <kelsey.hightower@gmail.com>
2014-12-12 (0001) Logan Attwood / <logan@therounds.ca>
2015-04-16 (0002) Max Garvey / <mgarvey@monsooncommerce.com>
2016-04-11 (0001) Joakim Sernbrant / <joakim.sernbrant@trioptima.com>
2016-07-30 (0115) Guy M. Allard / <allard.guy.m@gmail.com>
2017-03-01 (0001) Dan Corin / <danielcorin@users.noreply.github.com>
2017-05-05 (0001) Jason Libbey / <jlibbey@uber.com>
2017-06-05 (0001) Dan Corin / <dancorin@uber.com>
2017-11-06 (0001) tomsawyer / <tomsawyer126@gmail.com>
2017-11-20 (0001) itomsawyer / <tomsawyer126@gmail.com>
2018-03-12 (0001) GAOXIANG4 / <gaoxiang4@kingsoft.com>

Documentation

Overview

Package stompngo implements a STOMP 1.1+ compatible client library. For more STOMP information, see the specification at: http://stomp.github.com/.

Preparation

Network Connect:

You are responsible for first establishing a network connection.

This network connection will be used when you create a stompngo.Connection to interact with the STOMP broker.

h := "localhost"
p := "61613"
n, err := net.Dial(stompngo.NetProtoTCP, net.JoinHostPort(h, p))
if err != nil {
	// Do something sane ...
}

Shutdown

Network Disconnect:

When processing is complete, you MUST close the network connection. If you fail to do this, you will leak goroutines!

err = n.Close() // Could be defered above, think about it!
if err != nil {
	// Do something sane ...
}

STOMP Frames

The STOMP specification defines these physical frames that can be sent from a client to a STOMP broker:

CONNECT		connect to a STOMP broker, any version.
STOMP		connect to a STOMP broker, specification version 1.1+ only.
DISCONNECT	disconnect from a STOMP broker.
SEND		Send a message to a named queue or topic.
SUBSCRIBE	Prepare to read messages from a named queue or topic.
UNSUBSCRIBE	Complete reading messages from a named queue or topic.
ACK		Acknowledge that a message has been received and processed.
NACK		Deny that a message has been received and processed, specification version 1.1+ only.
BEGIN		Begin a transaction.
COMMIT		Commit a transaction.
ABORT		Abort a transaction.

The STOMP specification defines these physical frames that a client can receive from a STOMP broker:

CONNECTED	Broker response upon connection success.
ERROR		Broker emitted upon any error at any time during an active STOMP connection.
MESSAGE		A STOMP message frame, possibly with headers and a data payload.
RECEIPT		A receipt from the broker for a previous frame sent by the client.

Subscribe and MessageData Channels

The Subscribe method returns a channel from which you receive MessageData values.

The channel returned has different characteristics depending on the Stomp Version, and the Headers you pass to Subscribe.

For details on Subscribe requirements and behavior, see: https://github.com/gmallard/stompngo/wiki/subscribe-and-messagedata

RECEIPTs

Receipts are never received on a subscription unique MessageData channel.

They are always queued to the shared connection level stompgo.Connection.MessageData channel.

The reason for this behavior is because RECEIPT frames do not contain a subscription Header (per the STOMP specifications). See the:

https://github.com/gmallard/stompngo_examples

package for several examples.

Index

Constants

View Source
const (

	// Client generated commands.
	CONNECT     = "CONNECT"
	STOMP       = "STOMP"
	DISCONNECT  = "DISCONNECT"
	SEND        = "SEND"
	SUBSCRIBE   = "SUBSCRIBE"
	UNSUBSCRIBE = "UNSUBSCRIBE"
	ACK         = "ACK"
	NACK        = "NACK"
	BEGIN       = "BEGIN"
	COMMIT      = "COMMIT"
	ABORT       = "ABORT"

	// Server generated commands.
	CONNECTED = "CONNECTED"
	MESSAGE   = "MESSAGE"
	RECEIPT   = "RECEIPT"
	ERROR     = "ERROR"

	// Supported STOMP protocol definitions.
	SPL_10 = "1.0"
	SPL_11 = "1.1"
	SPL_12 = "1.2"
)
View Source
const (
	// ERROR Frame returned by broker on connect.
	ECONERR = Error("broker returned ERROR frame, CONNECT")

	// ERRORs for Headers.
	EHDRLEN  = Error("unmatched headers, bad length")
	EHDRUTF8 = Error("header string not UTF8")
	EHDRNIL  = Error("headers can not be nil")
	EUNKHDR  = Error("corrupt frame headers")
	EHDRMTK  = Error("header key can not be empty")
	EHDRMTV  = Error("header value can not be empty")

	// ERRORs for response to CONNECT.
	EUNKFRM = Error("unrecognized frame returned, CONNECT")
	EBADFRM = Error("Malformed frame")

	// No body allowed error
	EBDYDATA = Error("body data not allowed")

	// Not connected.
	ECONBAD = Error("no current connection or DISCONNECT previously completed")

	// Destination required
	EREQDSTSND = Error("destination required, SEND")
	EREQDSTSUB = Error("destination required, SUBSCRIBE")
	EREQDIUNS  = Error("destination required, UNSUBSCRIBE")
	EREQDSTUNS = Error("destination required, UNSUBSCRIBE") // Alternate name

	// id required
	EREQIDUNS = Error("id required, UNSUBSCRIBE")

	// Message ID required.
	EREQMIDACK = Error("message-id required, ACK") // 1.0, 1.1
	EREQIDACK  = Error("id required, ACK")         // 1.2

	// Subscription required.
	EREQSUBACK = Error("subscription required, ACK") // 1.1

	// NACK's.  STOMP 1.1 or greater.
	EREQMIDNAK = Error("message-id required, NACK")   // 1.1
	EREQSUBNAK = Error("subscription required, NACK") // 1.1
	EREQIDNAK  = Error("id required, NACK")           // 1.2

	// Transaction ID required.
	EREQTIDBEG = Error("transaction-id required, BEGIN")
	EREQTIDCOM = Error("transaction-id required, COMMIT")
	EREQTIDABT = Error("transaction-id required, ABORT")

	// Transaction ID present but empty.
	ETIDBEGEMT = Error("transaction-id empty, BEGIN")
	ETIDCOMEMT = Error("transaction-id empty, COMMIT")
	ETIDABTEMT = Error("transaction-id empty, ABORT")

	// Host header required, STOMP 1.1+
	EREQHOST = Error("host header required for STOMP 1.1+")

	// Subscription errors.
	EDUPSID = Error("duplicate subscription-id")
	EBADSID = Error("invalid subscription-id")

	// Subscribe errors.
	ESBADAM = Error("invalid ackmode, SUBSCRIBE")

	// Unsubscribe error.
	EUNOSID  = Error("id required, UNSUBSCRIBE")
	EUNODSID = Error("destination or id required, UNSUBSCRIBE") // 1.0

	// Unsupported version error.
	EBADVERCLI = Error("unsupported protocol version, client")
	EBADVERSVR = Error("unsupported protocol version, server")
	EBADVERNAK = Error("unsupported protocol version, NACK")

	// Unsupported Headers type.
	EBADHDR = Error("unsupported Headers type")

	// Receipt not allowed on connect
	ENORECPT = Error("receipt not allowed on CONNECT")

	// Invalid broker command
	EINVBCMD = Error("invalid broker command")
)

Error constants.

View Source
const (
	HK_ACCEPT_VERSION = "accept-version"
	HK_ACK            = "ack"
	HK_CONTENT_TYPE   = "content-type"
	HK_CONTENT_LENGTH = "content-length"
	HK_DESTINATION    = "destination"
	HK_HEART_BEAT     = "heart-beat"
	HK_HOST           = "host" // HK_VHOST aloas
	HK_ID             = "id"
	HK_LOGIN          = "login"
	HK_MESSAGE        = "message"
	HK_MESSAGE_ID     = "message-id"
	HK_SUPPRESS_CL    = "suppress-content-length" // Not in any spec, but used
	HK_SUPPRESS_CT    = "suppress-content-type"   // Not in any spec, but used
	HK_PASSCODE       = "passcode"
	HK_RECEIPT        = "receipt"
	HK_RECEIPT_ID     = "receipt-id"
	HK_SESSION        = "session"
	HK_SERVER         = "server"
	HK_SUBSCRIPTION   = "subscription"
	HK_TRANSACTION    = "transaction"
	HK_VERSION        = "version"
	HK_VHOST          = "host" // HK_HOST alias
)

Common Header keys

View Source
const (
	AckModeAuto             = "auto"
	AckModeClient           = "client"
	AckModeClientIndividual = "client-individual"
)

ACK Modes

View Source
const (
	DFLT_CONTENT_TYPE = "text/plain; charset=UTF-8"
)

Default content-type.

View Source
const (
	NetProtoTCP = "tcp" // Protocol Name
)
View Source
const (
	StompPlusDrainAfter = "sng_drafter" // SUBSCRIBE Header
)

Extensions to STOMP protocol.

Variables

View Source
var (
	LFB = []byte("\n")
	ZRB = []byte{0}
)
View Source
var NULLBUFF = make([]uint8, 0)

A zero length buffer for convenience.

View Source
var NoDiscReceipt = Headers{"noreceipt", "true"}

A no disconnect receipt Headers value for convenience.

Functions

func HexData added in v1.0.6

func HexData(b []uint8) string

HexData returns a dump formatted value of a byte slice.

func Protocols

func Protocols() []string

Protocols returns a slice of client supported protocol levels.

func Sha1

func Sha1(q string) string

Sha1 returns a SHA1 hash for a specified string.

func Supported

func Supported(v string) bool

Supported checks if a particular STOMP version is supported in the current implementation.

func Uuid

func Uuid() string

Uuid returns a type 4 UUID.

func Version

func Version() string

Types

type Connection

type Connection struct {
	ConnectResponse   *Message           // Broker response (CONNECTED/ERROR) if physical connection successful.
	DisconnectReceipt MessageData        // If receipt requested on DISCONNECT.
	MessageData       <-chan MessageData // Inbound data for the client.

	Hbrf bool // Indicates a heart beat read/receive failure, which is possibly transient.  Valid for 1.1+ only.
	Hbsf bool // Indicates a heart beat send failure, which is possibly transient.  Valid for 1.1+ only.
	// contains filtered or unexported fields
}

Connection is a representation of a STOMP connection.

func Connect

func Connect(n net.Conn, h Headers) (*Connection, error)

Primary STOMP Connect.

For STOMP 1.1+ the Headers parameter MUST contain the headers required by the specification. Those headers are not magically inferred.

Example:

// Obtain a network connection
n, e := net.Dial(NetProtoTCP, "localhost:61613")
if e != nil {
	// Do something sane ...
}
h := stompngo.Headers{} // A STOMP 1.0 connection request
c, e := stompngo.Connect(n, h)
if e != nil {
	// Do something sane ...
}
// Use c

Example:

// Obtain a network connection
n, e := net.Dial(NetProtoTCP, "localhost:61613")
if e != nil {
	// Do something sane ...
}
h := stompngo.Headers{HK_ACCEPT_VERSION, "1.1",
	HK_HOST, "localhost"} // A STOMP 1.1 connection
c, e := stompngo.Connect(n, h)
if e != nil {
	// Do something sane ...
}
// Use c

func (*Connection) Abort

func (c *Connection) Abort(h Headers) error

Abort a STOMP transaction.

Headers MUST contain a "transaction" header key with a value that is not an empty string.

Example:

h := stompngo.Headers{stompngo.HK_TRANSACTION, "transaction-id1"}
e := c.Abort(h)
if e != nil {
	// Do something sane ...
}

func (*Connection) Ack

func (c *Connection) Ack(h Headers) error

Ack a STOMP MESSAGE.

For Stomp 1.0 Headers MUST contain a "message-id" header key.

For Stomp 1.1 Headers must contain a "message-id" key and a "subscription" header key.

For Stomp 1.2 Headers must contain a unique "id" header key.

See the specifications at http://stomp.github.com/ for details.

Example:

h := stompngo.Headers{stompngo.HK_MESSAGE_ID, "message-id1",
	"subscription", "d2cbe608b70a54c8e69d951b246999fbc20df694"}
e := c.Ack(h)
if e != nil {
	// Do something sane ...
}

func (*Connection) Begin

func (c *Connection) Begin(h Headers) error

Begin a STOMP transaction.

Headers MUST contain a "transaction" header key with a value that is not an empty string.

Example:

h := stompngo.Headers{stompngo.HK_TRANSACTION, "transaction-id1"}
e := c.Begin(h)
if e != nil {
	// Do something sane ...
}

func (*Connection) BytesRead

func (c *Connection) BytesRead() int64

BytesRead returns a count of the number of bytes read on the connection.

func (*Connection) BytesWritten

func (c *Connection) BytesWritten() int64

BytesWritten returns a count of the number of bytes written on the connection.

func (*Connection) Commit

func (c *Connection) Commit(h Headers) error

Commit a STOMP transaction.

Headers MUST contain a "transaction" header key with a value that is not an empty string.

Example:

h := stompngo.Headers{stompngo.HK_TRANSACTION, "transaction-id1"}
e := c.Begin(h)
if e != nil {
	// Do something sane ...
}

func (*Connection) Connected

func (c *Connection) Connected() bool

Connected returns the current connection status.

func (*Connection) Disconnect

func (c *Connection) Disconnect(h Headers) error

Disconnect from a STOMP broker.

Shut down heart beats if necessary. Set connection status to false to disable further actions with this connection.

Obtain a receipt unless the client specifically indicates a receipt request should be excluded. If the client actually asks for a receipt, use the supplied receipt id. Otherwise generate a unique receipt id and add that to the DISCONNECT headers.

Example:

h := stompngo.Headers{HK_RECEIPT, "receipt-id1"} // Ask for a receipt
e := c.Disconnect(h)
if e != nil {
	// Do something sane ...
}
fmt.Printf("%q\n", c.DisconnectReceipt)
// Or:
h := stompngo.Headers{"noreceipt", "true"} // Ask for a receipt
e := c.Disconnect(h)
if e != nil {
	// Do something sane ...
}
fmt.Printf("%q\n", c.DisconnectReceipt)

func (*Connection) EnableReadDeadline added in v1.0.8

func (c *Connection) EnableReadDeadline(e bool)

EnableReadDeadline enables/disables the use of read deadlines.

func (*Connection) EnableWriteDeadline added in v1.0.8

func (c *Connection) EnableWriteDeadline(e bool)

EnableWriteDeadline enables/disables the use of write deadlines.

func (*Connection) ExpiredNotification added in v1.0.8

func (c *Connection) ExpiredNotification(enf ExpiredNotification)

ExpiredNotification sets the expired notification callback function.

func (*Connection) FramesRead

func (c *Connection) FramesRead() int64

FramesRead returns a count of the number of frames read on the connection.

func (*Connection) FramesWritten

func (c *Connection) FramesWritten() int64

FramesWritten returns a count of the number of frames written on the connection.

func (*Connection) GetLogger added in v1.0.10

func (c *Connection) GetLogger() *log.Logger

GetLogger - returns the current connection logger.

func (*Connection) IsReadDeadlineEnabled added in v1.0.8

func (c *Connection) IsReadDeadlineEnabled() bool

IsReadDeadlineEnabled returns the current value of write deadline enablement.

func (*Connection) IsWriteDeadlineEnabled added in v1.0.8

func (c *Connection) IsWriteDeadlineEnabled() bool

IsWriteDeadlineEnabled returns the current value of write deadline enablement.

func (*Connection) Nack

func (c *Connection) Nack(h Headers) error

Nack a STOMP 1.1+ message.

For Stomp 1.1 Headers must contain a "message-id" key and a "subscription" header key.

For Stomp 1.2 Headers must contain a unique "id" header key.

See the specifications at http://stomp.github.com/ for details.

Disallowed for an established STOMP 1.0 connection, and EBADVERNAK is returned.

Example:

h := stompngo.Headers{stompngo.HK_MESSAGE_ID, "message-id1",
	stompngo.HK_SUBSCRIPTION, "d2cbe608b70a54c8e69d951b246999fbc20df694"}
e := c.Nack(h)
if e != nil {
	// Do something sane ...
}

func (*Connection) Protocol

func (c *Connection) Protocol() string

Protocol returns the current connection protocol level.

func (*Connection) ReadDeadline added in v1.0.8

func (c *Connection) ReadDeadline(d time.Duration)

ReadDeadline sets the write deadline duration.

func (*Connection) ReceiveTickerCount

func (c *Connection) ReceiveTickerCount() int64

ReceiveTickerCount returns any heartbeat receive ticker count. A return value of zero usually indicates no read heartbeats are enabled.

func (*Connection) ReceiveTickerInterval

func (c *Connection) ReceiveTickerInterval() int64

ReceiveTickerInterval returns any heartbeat receive ticker interval in ms. A return value of zero means no heartbeats are being received.

func (*Connection) Running

func (c *Connection) Running() time.Duration

Running returns a time duration since connection start.

func (*Connection) Send

func (c *Connection) Send(h Headers, b string) error

Send a STOMP MESSAGE.

Headers MUST contain a "destination" header key.

The message body (payload) is a string, which may be empty.

Example:

h := stompngo.Headers{stompngo.HK_DESTINATION, "/queue/mymessages"}
m := "My message"
e := c.Send(h, m)
if e != nil {
	// Do something sane ...
}

func (*Connection) SendBytes

func (c *Connection) SendBytes(h Headers, b []byte) error

Send a STOMP MESSAGE.

Headers MUST contain a "destination" header key.

The message body (payload) is a slice of bytes, which may be empty.

Example:

h := stompngo.Headers{stompngo.HK_DESTINATION, "/queue/mymessages"}
m := []byte("My message")
e := c.Send(h, m)
if e != nil {
	// Do something sane ...
}

func (*Connection) SendTickerCount

func (c *Connection) SendTickerCount() int64

SendTickerCount returns any heartbeat send ticker count. A return value of zero usually indicates no send heartbeats are enabled.

func (*Connection) SendTickerInterval

func (c *Connection) SendTickerInterval() int64

SendTickerInterval returns any heartbeat send ticker interval in ms. A return value of zero means no heartbeats are being sent.

func (*Connection) Session

func (c *Connection) Session() string

Session returns the broker assigned session id.

func (*Connection) SetLogger

func (c *Connection) SetLogger(l *log.Logger)

SetLogger enables a client defined logger for this connection.

Set to "nil" to disable logging.

Example:

// Start logging
l := log.New(os.Stdout, "", log.Ldate|log.Lmicroseconds)
c.SetLogger(l)

func (*Connection) SetSubChanCap

func (c *Connection) SetSubChanCap(nc int)

SetSubChanCap sets a new subscribe channel capacity, to be used during future SUBSCRIBE operations.

func (*Connection) ShortWriteRecovery added in v1.0.8

func (c *Connection) ShortWriteRecovery(ro bool)

ShortWriteRecovery enables / disables short write recovery. enablement.

func (*Connection) SubChanCap

func (c *Connection) SubChanCap() int

SubChanCap returns the current subscribe channel capacity.

func (*Connection) Subscribe

func (c *Connection) Subscribe(h Headers) (<-chan MessageData, error)

Subscribe to a STOMP subscription.

Headers MUST contain a "destination" header key.

All clients are recommended to supply a unique HK_ID header on Subscribe.

For STOMP 1.0 clients: if an "id" header is supplied, attempt to use it. If the "id" header is not unique in the session, return an error. If no "id" header is supplied, attempt to generate a unique subscription id based on the destination name. If a unique subscription id cannot be generated, return an error.

For STOMP 1.1+ clients: If any client does not supply an HK_ID header, attempt to generate a unique "id". In all cases, do not allow duplicate subscription "id"s in this session.

In summary, multiple subscriptions to the same destination are not allowed unless a unique "id" is supplied.

For details about the returned MessageData channel, see: https://github.com/gmallard/stompngo/wiki/subscribe-and-messagedata

Example:

// Possible additional Header keys: "ack", "id".
h := stompngo.Headers{stompngo.HK_DESTINATION, "/queue/myqueue"}
s, e := c.Subscribe(h)
if e != nil {
	// Do something sane ...
}

func (*Connection) Unsubscribe

func (c *Connection) Unsubscribe(h Headers) error

Unsubscribe from a STOMP subscription.

Headers MUST contain a "destination" header key, and for Stomp 1.1+, a "id" header key per the specifications. The subscription MUST currently exist for this session.

Example:

// Possible additional Header keys: "id".
h := stompngo.Headers{stompngo.HK_DESTINATION, "/queue/myqueue"}
e := c.Unsubscribe(h)
if e != nil {
	// Do something sane ...
}

func (*Connection) WriteDeadline added in v1.0.8

func (c *Connection) WriteDeadline(d time.Duration)

WriteDeadline sets the write deadline duration.

type Deadliner added in v1.0.8

type Deadliner interface {
	WriteDeadline(d time.Duration)
	EnableWriteDeadline(e bool)
	ExpiredNotification(enf ExpiredNotification)
	IsWriteDeadlineEnabled() bool
	ReadDeadline(d time.Duration)
	EnableReadDeadline(e bool)
	IsReadDeadlineEnabled() bool
	ShortWriteRecovery(ro bool)
}

Deadliner is an interface that models the optional network deadline functionality implemented by the stompngo package.

type Error

type Error string

Error definition.

func (Error) Error

func (e Error) Error() string

Error returns a string for a particular Error.

type ExpiredNotification added in v1.0.8

type ExpiredNotification func(err error, rw bool)

ExpiredNotification is a callback function, provided by the client and called when a deadline expires. The err parameter will contain the actual expired error. The rw parameter will be true if the notification is for a write, and false otherwise.

type Frame

type Frame Message

Frame is an alternate name for a Message.

func (*Frame) Bytes added in v1.0.8

func (f *Frame) Bytes(sclok bool) []byte

Bytes returns a byte slice of all frame data, ready for the wire

func (*Frame) Size

func (f *Frame) Size(e bool) int64

Size returns the size of Frame on the wire, in bytes.

type HBDataReader added in v1.0.8

type HBDataReader interface {
	SendTickerInterval() int64
	ReceiveTickerInterval() int64
	SendTickerCount() int64
	ReceiveTickerCount() int64
}

HBDataReader is an interface that modela a reader for the heart beat data maintained by the stompngo package.

type Headers

type Headers []string

Headers definition, a slice of string.

STOMP headers are key and value pairs. See the specification for more information about STOMP frame headers.

Key values are found at even numbered indices. Values are found at odd numbered indices. Headers are validated for an even number of slice elements.

func (Headers) Add

func (h Headers) Add(k, v string) Headers

Add appends a key and value pair as a header to a set of Headers.

func (Headers) AddHeaders

func (h Headers) AddHeaders(o Headers) Headers

AddHeaders appends one set of Headers to another.

func (Headers) Bytes added in v1.0.8

func (h Headers) Bytes() []byte

Bytes returns a byte slice of the headers

func (Headers) Clone

func (h Headers) Clone() Headers

Clone copies a set of Headers.

func (Headers) Compare

func (h Headers) Compare(other Headers) bool

Compare compares one set of Headers with another.

func (Headers) Contains

func (h Headers) Contains(k string) (string, bool)

Contains returns true if a set of Headers contains a key.

func (Headers) ContainsKV

func (h Headers) ContainsKV(k string, v string) bool

ContainsKV returns true if a set of Headers contains a key and value pair.

func (Headers) Delete

func (h Headers) Delete(k string) Headers

Delete removes a key and value pair from a set of Headers.

func (Headers) Index

func (h Headers) Index(k string) int

Index returns the index of a keader key in Headers. Return -1 if the key is not present.

func (Headers) Size

func (h Headers) Size(e bool) int64

Size returns the size of Headers on the wire, in bytes.

func (Headers) String added in v1.0.6

func (h Headers) String() string

String makes Headers a Stringer.

func (Headers) Validate

func (h Headers) Validate() error

Validate performs bacic validation of a set of Headers.

func (Headers) ValidateUTF8

func (h Headers) ValidateUTF8() (string, error)

ValidateUTF8 validates that header strings are UTF8.

func (Headers) Value

func (h Headers) Value(k string) string

Value returns a header value for a specified key. If the key is not present an empty string is returned.

type Message

type Message struct {
	Command string
	Headers Headers
	Body    []uint8
}

Message is a STOMP Message, consisting of: a STOMP command; a set of STOMP Headers; and a message body(payload), which is possibly empty.

func (*Message) BodyString

func (m *Message) BodyString() string

BodyString returns a Message body as a string.

func (*Message) Size

func (m *Message) Size(e bool) int64

Size returns the size of Message on the wire, in bytes.

func (*Message) String added in v1.0.6

func (m *Message) String() string

String makes Message a Stringer.

type MessageData

type MessageData struct {
	Message Message
	Error   error
}

MessageData passed to the client, containing: the Message; and an Error value which is possibly nil.

Note that this has no relevance on whether a MessageData.Message.Command value contains an "ERROR" generated by the broker.

type Monitor added in v1.0.8

type Monitor interface {
	Connected() bool
	Session() string
	Protocol() string
	Running() time.Duration
	SubChanCap() int
}

Monitor is an interface that models monitoring a stompngo connection.

type ParmHandler added in v1.0.8

type ParmHandler interface {
	SetLogger(l *log.Logger)
	GetLogger() *log.Logger
	SetSubChanCap(nc int)
}

ParmHandler is an interface that models stompngo client parameter specification.

type STOMPConnector added in v1.0.8

type STOMPConnector interface {
	Stomper
	StatsReader
	HBDataReader
	Deadliner
	Monitor
	ParmHandler
}

STOMPConnector is an interface that encapsulates the Connection struct.

func NewConnector added in v1.0.8

func NewConnector(n net.Conn, h Headers) (STOMPConnector, error)

Wrapper for primary STOMP Connect function that returns an interface.

type StatsReader added in v1.0.8

type StatsReader interface {
	FramesRead() int64
	BytesRead() int64
	FramesWritten() int64
	BytesWritten() int64
}

StatsReader is an interface that modela a reader for the statistics maintained by the stompngo package.

type Stomper added in v1.0.8

type Stomper interface {
	Abort(h Headers) error
	Ack(headers Headers) error
	Begin(h Headers) error
	Commit(h Headers) error
	Disconnect(headers Headers) error
	Nack(headers Headers) error
	Send(Headers, string) error
	Subscribe(headers Headers) (<-chan MessageData, error)
	Unsubscribe(headers Headers) error
	//
	SendBytes(h Headers, b []byte) error
}

Stomper is an interface that models STOMP specification commands.

Directories

Path Synopsis
cmd
Helper package for stompngo users.
Helper package for stompngo users.

Jump to

Keyboard shortcuts

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