stomp v1.0.2
Crystal Lang STOMP Protocol
Communicate with devices supporting the STOMP protocol
Installation
-
Add the dependency to your
shard.yml
:dependencies: stomp: github: spider-gazelle/stomp
-
Run
shards install
Usage
require "stomp"
hostname = "stomp.server.com"
port = 1234
socket = TCPSocket.new(hostname, port)
# accepts any object implementing `IO`
client = STOMP::IOClient.new(hostname, socket)
# client is ready
client.on_connected do |frame|
client.send client.subscribe("main", "/some/path", HTTP::Headers{
"receipt" => "confirm-main",
})
end
# process messages here
client.on_message do |frame|
frame.headers["subscription"] # => "main" (as specified in the subscription above)
frame.headers["destination"] # => "/some/path"
# get the data, handles charset automatically
frame.body_text
# or can get the raw bytes
frame.body
end
# if you are interested in receipts
client.on_receipt do |frame|
frame.headers["receipt-id"] # => "confirm-main"
end
# if you are interested in errors
client.on_error do |frame|
message = frame.headers["message"]? || frame.body_text
Log.error { message }
# maybe you want to close on error?
client.close
end
client.on_close do |frame|
received_closed += 1
end
# blocks until the socket is closed or an unhandled error occurs
# client is thread safe
client.run
Repository
stomp
Owner
Statistic
- 1
- 0
- 0
- 1
- 0
- 16 days ago
- March 8, 2021
License
MIT License
Links
Synced at
Sat, 23 Nov 2024 02:48:10 GMT
Languages