-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
581ff18
commit a768771
Showing
5 changed files
with
116 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
ws-stomp is a simple wrapper over a websocket connection that allows it to play nice with [go-stomp/stomp](https://github.com/go-stomp/stomp). | ||
|
||
|
||
## Example usage: | ||
|
||
```golang | ||
package main | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"time" | ||
|
||
wsstomp "github.com/SoMuchForSubtlety/ws-stomp" | ||
"github.com/go-stomp/stomp/v3" | ||
) | ||
|
||
func main() { | ||
// timeout if the connection isn't established after ten seconds | ||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) | ||
// connect to websocket | ||
conn, err := wsstomp.Connect(ctx, "wss://test.com/ws", nil) | ||
cancel() | ||
if err != nil { | ||
log.Printf("error during WS connect: %v", err) | ||
return | ||
} | ||
|
||
// init STOMP connection using the websocket connections | ||
stompConn, err := stomp.Connect(conn) | ||
if err != nil { | ||
conn.Close() | ||
log.Printf("error during STOMP connect: %v", err) | ||
return | ||
} | ||
defer func() { | ||
err = stompConn.Disconnect() | ||
if err != nil { | ||
log.Printf("error during STOMP disconnect: %v", err) | ||
} | ||
}() | ||
|
||
// send a message | ||
err = stompConn.Send("/queue/a", "text/plain", []byte("hello world!")) | ||
if err != nil { | ||
log.Println(err) | ||
return | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package wsstomp_test | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"time" | ||
|
||
wsstomp "github.com/SoMuchForSubtlety/ws-stomp" | ||
"github.com/go-stomp/stomp/v3" | ||
) | ||
|
||
// ExampleEstablishConnection demonstrates how to use this library to talk STOMP over a websocket connection | ||
func Example_establishConnection() { | ||
// timeout if the connection isn't established after ten seconds | ||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) | ||
// connect to websocket | ||
conn, err := wsstomp.Connect(ctx, "wss://test.com/ws", nil) | ||
cancel() | ||
if err != nil { | ||
log.Printf("error during WS connect: %v", err) | ||
return | ||
} | ||
|
||
// init STOMP connection using the websocket connections | ||
stompConn, err := stomp.Connect(conn) | ||
if err != nil { | ||
conn.Close() | ||
log.Printf("error during STOMP connect: %v", err) | ||
return | ||
} | ||
defer func() { | ||
err = stompConn.Disconnect() | ||
if err != nil { | ||
log.Printf("error during STOMP disconnect: %v", err) | ||
} | ||
}() | ||
|
||
// send a message | ||
err = stompConn.Send("/queue/a", "text/plain", []byte("hello world!")) | ||
if err != nil { | ||
log.Println(err) | ||
return | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters