# README
stomp-ws-go - STOMP 协议 golang 客户端,支持 WebSocket 连接
说明
本项目在 stompngo 项目的基础上改造而来,增加了对基于 WebSocket 实现的 STOMP 协议支持。
特性
- 支持 STOMP 1.0,1.1 和 1.2,相关规范请参考 [STOMP] (http://stomp.github.io/) 官方说明。
- 已针对 ActiveMQ、Apache Apollo、RabbitMQ 最近发布的版本测试通过(基于 TCP 连接),参见 stompngo
- 已针对 Spring STOMP 框架测试通过(基于 WebSocket 连接)
安装
go get github.com/drawdy/stomp-ws-go
示例
- 基于 TCP 连接的示例参见 stompngo_examples at github
- 基于 Websocket 连接的简单示例如下,完整内容参见 example-stomp-ws-go
func main() {
u := url.URL{
Scheme: "ws",
Host: "localhost:8080",
Path: "/stomp-ws",
}
conn, resp, err := websocket.DefaultDialer.Dial(u.String(), nil)
if err != nil {
log.Fatalf("couldn't connect to %v: %v", u.String(), err)
}
log.Printf("response status: %v\n", resp.Status)
log.Print("Websocket connection succeeded.")
h := stomp.Headers{
stomp.HK_ACCEPT_VERSION, "1.2,1.1,1.0",
stomp.HK_HEART_BEAT, "3000,3000",
stomp.HK_HOST, u.Host,
}
sc, err := stomp.ConnectOverWS(conn, h)
if err != nil {
log.Fatalf("couldn't create stomp connection: %v", err)
}
mdCh, err := sc.Subscribe(stomp.Headers{
stomp.HK_DESTINATION, "/topic/greeting.back",
stomp.HK_ID, stomp.Uuid(),
})
if err != nil {
log.Fatalf("failed to suscribe greeting message: %v", err)
}
err = sc.Send(stomp.Headers{
stomp.HK_DESTINATION, "/app/greeting",
stomp.HK_ID, stomp.Uuid(),
}, "hello STOMP!")
if err != nil {
log.Fatalf("failed to send greeting message: %v", err)
}
md := <-mdCh
if md.Error != nil {
log.Fatalf("receive greeting message caught error: %v", md.Error)
}
fmt.Printf("----> receive new message: %v\n", md.Message.BodyString())
err = sc.Disconnect(stomp.NoDiscReceipt)
if err != nil {
log.Fatalf("failed to disconnect: %v", err)
}
log.Print("Disconnected.")
}
# Functions
Primary STOMP Connect.
No description provided by the author
HexData returns a dump formatted value of a byte slice.
Wrapper for primary STOMP Connect function that returns an interface.
No description provided by the author
Protocols returns a slice of client supported protocol levels.
Sha1 returns a SHA1 hash for a specified string.
Supported checks if a particular STOMP version is supported in the current
implementation.
Uuid returns a type 4 UUID.
No description provided by the author
# Constants
No description provided by the author
No description provided by the author
ACK Modes
*/.
ACK Modes
*/.
ACK Modes
*/.
No description provided by the author
No description provided by the author
Client generated commands.
Server generated commands.
Default content-type.
No description provided by the author
Error constants.
Unsupported Headers type.
Invalid receipt-id string.
Error constants.
Error constants.
Unsupported version error.
Error constants.
Error constants.
No body allowed error.
Not connected.
ERROR Frame returned by broker on connect.
DISCONNECT timeout.
Subscription errors.
ERRORs for Headers.
Error constants.
Error constants.
Error constants.
Error constants.
Invalid broker command.
Receipt not allowed on connect.
Error constants.
Destination required.
Error constants.
Alternate name.
Host header required, STOMP 1.1+.
1.2.
1.2.
id required.
1.0, 1.1.
1.1.
1.1.
1.1.
Error constants.
Transaction ID required.
Error constants.
No description provided by the author
Subscribe errors.
Error constants.
Transaction ID present but empty.
Error constants.
ERRORs for response to CONNECT.
Error constants.
1.0.
Unsubscribe error.
Common Header keys
*/.
Common Header keys
*/.
Common Header keys
*/.
Common Header keys
*/.
Common Header keys
*/.
Common Header keys
*/.
HK_VHOST aloas.
Common Header keys
*/.
Common Header keys
*/.
Common Header keys
*/.
Common Header keys
*/.
Common Header keys
*/.
Common Header keys
*/.
Common Header keys
*/.
Common Header keys
*/.
Common Header keys
*/.
Common Header keys
*/.
Not in any spec, but used.
Not in any spec, but used.
Common Header keys
*/.
Common Header keys
*/.
HK_HOST alias.
No description provided by the author
No description provided by the author
Protocol Name.
No description provided by the author
No description provided by the author
Supported STOMP protocol definitions.
No description provided by the author
No description provided by the author
No description provided by the author
SUBSCRIBE Header.
UNSUBSCRIBE Header.
No description provided by the author
No description provided by the author
# Variables
No description provided by the author
No description provided by the author
A no disconnect receipt Headers value for convenience.
A zero length buffer for convenience.
No description provided by the author
# Structs
Connection is a representation of a STOMP connection.
No description provided by the author
Message is a STOMP Message, consisting of: a STOMP command; a set of STOMP
Headers; and a message body(payload), which is possibly empty.
MessageData passed to the client, containing: the Message; and an Error
value which is possibly nil.
# Interfaces
Deadliner is an interface that models the optional network deadline
functionality implemented by the stompngo package.
HBDataReader is an interface that models a reader for the heart beat
data maintained by the stompngo package.
Monitor is an interface that models monitoring a stompngo connection.
ParmHandler is an interface that models stompngo client parameter
specification.
StatsReader is an interface that modela a reader for the statistics
maintained by the stompngo package.
STOMPConnector is an interface that encapsulates the Connection struct.
Stomper is an interface that models STOMP specification commands.
# Type aliases
Error definition.
ExpiredNotification is a callback function, provided by the client
and called when a deadline expires.
Frame is an alternate name for a Message.
Headers definition, a slice of string.