Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/spider-gazelle/stomp
crystal lang implementation of the STOMP protocol
https://github.com/spider-gazelle/stomp
Last synced: about 1 month ago
JSON representation
crystal lang implementation of the STOMP protocol
- Host: GitHub
- URL: https://github.com/spider-gazelle/stomp
- Owner: spider-gazelle
- License: mit
- Created: 2021-03-08T06:37:04.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2024-11-07T19:35:03.000Z (2 months ago)
- Last Synced: 2024-11-18T23:52:39.786Z (about 2 months ago)
- Language: Crystal
- Size: 15.6 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-crystal - stomp - STOMP protocol (Network Protocols)
README
# Crystal Lang STOMP Protocol
[![CI](https://github.com/spider-gazelle/stomp/actions/workflows/ci.yml/badge.svg)](https://github.com/spider-gazelle/stomp/actions/workflows/ci.yml)
Communicate with devices supporting the STOMP protocol
## Installation
1. Add the dependency to your `shard.yml`:
```yaml
dependencies:
stomp:
github: spider-gazelle/stomp
```2. Run `shards install`
## Usage
```crystal
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
endclient.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```