Documentation ¶
Overview ¶
package stompserver provides functionality for manipulating STOMP frames.
Index ¶
- Constants
- Variables
- func IsClientCommand(command string) (bool, error)
- func IsServerCommand(command string) (bool, error)
- func ParseHeartBeat(heartBeat string) (time.Duration, time.Duration, error)
- type Frame
- func Deserialize(stompText string) (*Frame, error)
- func New(command string, headers ...string) *Frame
- func NewConnectedFrame(connectFrame *Frame, session string) *Frame
- func NewErrorFrame(tips string, detail string, originFrame *Frame) *Frame
- func NewMessageFrame(destination string, messageID string, subscription string) (*Frame, string)
- type Header
- func (h *Header) Add(key, value string)
- func (h *Header) AddFromArray(array []string)
- func (h *Header) AddHeader(header *Header)
- func (h *Header) Clone() *Header
- func (h *Header) Contains(key string) (value string, ok bool)
- func (h *Header) ContainsKey(key string) bool
- func (h *Header) ContentLength() (value int, ok bool, err error)
- func (h *Header) Del(key string)
- func (h *Header) Get(key string) string
- func (h *Header) GetAll(key string) []string
- func (h *Header) GetAt(index int) (key, value string)
- func (h *Header) Len() int
- func (h *Header) Set(key, value string)
- type Reader
- type StompManager
- func (manager *StompManager) AddSubscribeDestination(destinations ...string)
- func (manager *StompManager) LetStompUnitSend(stompMessageFrame *Frame, unitSessionId string)
- func (manager *StompManager) NewMessageId() string
- func (manager *StompManager) Publish(stompMessageFrame *Frame)
- func (manager *StompManager) RegistDestinationToApplication(destinationRoots ...string)
- func (manager *StompManager) RegistDestinationToBroadcastAll(destinationRoots ...string)
- func (manager *StompManager) RegistDestinationToUser(destinationRoots ...string)
- func (manager *StompManager) StompUnitOnClose(stompUnit *StompUnit)
- func (manager *StompManager) SubScribe(subScribeFrame *Frame, stompUnit *StompUnit) *Frame
- func (manager *StompManager) SubscribeFlowDirction(destination string) int
- func (manager *StompManager) UnSubScribe(unSubScribeFrame *Frame, stompUnit *StompUnit)
- type StompUnit
- type Writer
Constants ¶
const ( AckAuto = "auto" // Client does not send ACK AckClient = "client" // Client sends ACK/NACK AckClientIndividual = "client-individual" // Client sends ACK/NACK for individual messages )
Valid values for the "ack" header entry.
const ( // Client commands. CommandAbort = "ABORT" CommandACK = "ACK" CommandBegin = "BEGIN" CommandCommit = "COMMIT" CommandConnect = "CONNECT" CommandDisconnect = "DISCONNECT" CommandNack = "NACK" CommandSend = "SEND" CommandStomp = "STOMP" CommandSubscribe = "SUBSCRIBE" CommandUnsubscribe = "UNSUBSCRIBE" // Server commands. CommandConnected = "CONNECTED" CommandError = "ERROR" CommandMessage = "MESSAGE" CommandHeartbeat = "RECEIPT" )
STOMP frame commands. Used upper case naming convention to avoid clashing with STOMP header names.
const ( AcceptVersion = "accept-version" Ack = "ack" ContentLength = "content-length" ContentType = "content-type" Destination = "destination" HeartBeat = "heart-beat" Host = "host" Id = "id" Login = "login" Message = "message" MessageId = "message-id" Passcode = "passcode" Receipt = "receipt" ReceiptId = "receipt-id" Server = "server" Session = "session" Subscription = "subscription" Transaction = "transaction" Version = "version" )
STOMP header names. Some of the header names have commands with the same name (eg Ack, Message, Receipt). Commands use an upper-case naming convention, header names use pascal-case naming convention.
const ( Plain = "text/plain" Html = "text/html" Xml = "text/xml" RichText = "text/richtext" )
Text
const ( Soap = "application/soap+xml" Octet = "application/octet-stream" Rtf = "application/rtf" Pdf = "application/pdf" Zip = "application/zip" )
Application
const ( Gif = "image/gif" Tiff = "image/tiff" Jpeg = "image/jpeg" )
Image
const ( Unknow = -1 All = iota Application User )
Variables ¶
var ( ErrInvalidCommand = errors.New("invalid command") ErrInvalidFrameFormat = errors.New("invalid frame format") )
var (
ErrInvalidHeartBeat = errors.New("invalid heart-beat")
)
var InstancesStompManager = &StompManager{ rootMux: new(sync.Mutex), rootDestinationSliceToAll: []string{}, rootDestinationSliceToApplication: []string{}, rootDestinationSliceToUser: []string{}, guid: tools.TimeUUID().String(), giudMux: new(sync.Mutex), messageTailId: uint64(0), subscribeSupportTopicSlice: []string{}, stompSubscribeDictionary: make(map[string]map[string]StompUnit), stompSubscribeDictionaryMux: new(sync.Mutex), }
var StompCommand = &command{
Abort: "ABORT",
ACK: "ACK",
Begin: "BEGIN",
Commit: "COMMIT",
Connect: "CONNECT",
Disconnect: "DISCONNECT",
Nack: "NACK",
Send: "SEND",
Stomp: "STOMP",
Subscribe: "SUBSCRIBE",
Unsubscribe: "UNSUBSCRIBE",
Connected: "CONNECTED",
Error: "ERROR",
Message: "MESSAGE",
Heartbeat: "RECEIPT",
}
var StompHeaders = &headerKey{ AcceptVersion: "accept-version", Ack: "ack", ContentLength: "content-length", ContentType: "content-type", Destination: "destination", HeartBeat: "heart-beat", Host: "host", Id: "id", Login: "login", Message: "message", MessageId: "message-id", Passcode: "passcode", Receipt: "receipt", ReceiptId: "receipt-id", Server: "server", Session: "session", Subscription: "subscription", Transaction: "transaction", Version: "version", }
Functions ¶
func IsClientCommand ¶
IsClientCommand 验证是否是客户端的命令
参数: command string 包命令 return bool true 客户端的包 false 异常包(应该发送一个Error包,然后关闭连接) error nil / 无效包错误
func IsServerCommand ¶
IsServerCommand 是否是server的包
参数: command string 包命令 return bool true 服务端的包 false 异常包(应该发送一个Error包,然后关闭连接) error nil / 无效包错误
func ParseHeartBeat ¶
ParseHeartBeat parses the value of a STOMP heart-beat entry and returns two time durations. Returns an error if the heart-beat value is not in the correct format, or if the time durations are too big to be represented by the time.Duration type.
Types ¶
type Frame ¶
A Frame represents a STOMP frame. A frame consists of a command followed by a collection of header entries, and then an optional body.
func Deserialize ¶
func New ¶
New creates a new STOMP frame with the specified command and headers. The headers should contain an even number of entries. Each even index is the header name, and the odd indexes are the assocated header values.
func NewConnectedFrame ¶
STOMP 1.2 servers MUST set the following headers:
version : The version of the STOMP protocol the session will be using. See Protocol Negotiation for more details. STOMP 1.2 servers MAY set the following headers:
heart-beat : The Heart-beating settings.
session : A session identifier that uniquely identifies the session.
server : A field that contains information about the STOMP server. The field MUST contain a server-name field and MAY be followed by optional comment fields delimited by a space character.
The server-name field consists of a name token followed by an optional version number token.
server = name ["/" version] *(comment)
Example:
server:Apache/1.3.9
func NewMessageFrame ¶
type Header ¶
type Header struct {
// contains filtered or unexported fields
}
A Header represents the header part of a STOMP frame. The header in a STOMP frame consists of a list of header entries. Each header entry is a key/value pair of strings.
Normally a STOMP header only has one header entry for a given key, but the STOMP standard does allow for multiple header entries with the same key. In this case, the first header entry contains the value, and any subsequent header entries with the same key are ignored.
Example header containing 6 header entries. Note that the second header entry with the key "comment" would be ignored.
login:scott passcode:tiger host:stompserver accept-version:1.0,1.1,1.2 comment:some comment comment:another comment
func NewHeader ¶
NewHeader creates a new Header and populates it with header entries. This function expects an even number of strings as parameters. The even numbered indices are keys and the odd indices are values. See the example for more information.
func (*Header) AddFromArray ¶
AddFromArray adds all of the key value pairs in header to h.
func (*Header) Contains ¶
Contains gets the first value associated with the given key, and also returns a bool indicating whether the header entry exists.
If there are no values associated with the key, Get returns "" for the value, and ok is false.
func (*Header) ContentLength ¶
ContentLength returns the value of the "content-length" header entry. If the "content-length" header is missing, then ok is false. If the "content-length" entry is present but is not a valid non-negative integer then err is non-nil.
func (*Header) Get ¶
Get gets the first value associated with the given key. If there are no values associated with the key, Get returns "".
func (*Header) GetAll ¶
GetAll returns all of the values associated with a given key. Normally there is only one header entry per key, but it is permitted to have multiple entries according to the STOMP standard.
func (*Header) GetAt ¶
Returns the header name and value at the specified index in the collection. The index should be in the range 0 <= index < Len(), a panic will occur if it is outside this range.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
The Reader type reads STOMP frames from an underlying io.Reader. The reader is buffered, and the size of the buffer is the maximum size permitted for the STOMP frame command and header section. A STOMP frame is rejected if its command and header section exceed the buffer size.
func NewReaderSize ¶
NewReaderSize creates a Reader with an underlying bufferSize of the specified size.
type StompManager ¶
type StompManager struct {
// contains filtered or unexported fields
}
func (*StompManager) AddSubscribeDestination ¶
func (manager *StompManager) AddSubscribeDestination(destinations ...string)
func (*StompManager) LetStompUnitSend ¶
func (manager *StompManager) LetStompUnitSend(stompMessageFrame *Frame, unitSessionId string)
指定StompUnit.SessionId查找StompUnit发送stompFrame
LetStompUnitSend 指定StompUnit.SessionId查找StompUnit发送stompFrame
参数: stompMessageFrame *Frame 指定的Stomp数据包 unitSessionId string 指定的StompUnit的SessionId
func (*StompManager) NewMessageId ¶
func (manager *StompManager) NewMessageId() string
func (*StompManager) Publish ¶
func (manager *StompManager) Publish(stompMessageFrame *Frame)
用来发布订阅的内容.
func (*StompManager) RegistDestinationToApplication ¶
func (manager *StompManager) RegistDestinationToApplication(destinationRoots ...string)
func (*StompManager) RegistDestinationToBroadcastAll ¶
func (manager *StompManager) RegistDestinationToBroadcastAll(destinationRoots ...string)
群发路径注册
func (*StompManager) RegistDestinationToUser ¶
func (manager *StompManager) RegistDestinationToUser(destinationRoots ...string)
func (*StompManager) StompUnitOnClose ¶
func (manager *StompManager) StompUnitOnClose(stompUnit *StompUnit)
when stompBehavior closing,need remove subscribe
func (*StompManager) SubScribe ¶
func (manager *StompManager) SubScribe(subScribeFrame *Frame, stompUnit *StompUnit) *Frame
SubScribe 添加一个新的订阅地址 参数:
subScribeFrame 客户端的订阅数据包 stompUnit 客户端连接对象
return nil:Success, not NULL:ERROR
func (*StompManager) SubscribeFlowDirction ¶
func (manager *StompManager) SubscribeFlowDirction(destination string) int
func (*StompManager) UnSubScribe ¶
func (manager *StompManager) UnSubScribe(unSubScribeFrame *Frame, stompUnit *StompUnit)
/ 客户端取消订阅
type StompUnit ¶
type StompUnit struct { SessionId string // 使用UUID分配id TopicSubidDictionary map[string]string // 按照订阅地址关联Stomp客户端连接,key:Destination Value:Sub-id TopicSubidDictionaryMutex *sync.Mutex // 锁 IsConnected bool // 是否建立stomp连接,更改前,需要建立connect PublishManager *StompManager // 主服务的管理,类似服务的管家 ControllerUnitId string // 登录时使用,用来保持连接的 // contains filtered or unexported fields }
func NewStompUnit ¶
func NewStompUnit(connection *websocket.Conn, publishManager *StompManager, reflexHandle func(sourceStompMessage *Frame, unit *StompUnit)) StompUnit
NestompserverUnit 创建一个Tcp连接单元