-
Notifications
You must be signed in to change notification settings - Fork 8
Add Sec-WebSocket-Protocol to the HTTP header #79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,16 @@ | ||
| AMQP 1.0 over WebSocket Example | ||
| =============================================================== | ||
|
|
||
| This example demonstrates how to use AMQP 1.0 over WebSocket. </br> | ||
| ## RabbitMQ Tanzu | ||
| You need [Tanzu RabbitMQ 4.0](https://www.vmware.com/products/app-platform/tanzu-rabbitmq) or later with the AMQP 1.0 and `rabbitmq_web_amqp` plugins enabled. | ||
|
|
||
| For more info read the blog post: [AMQP 1.0 over WebSocket](https://www.rabbitmq.com/blog/2025/04/16/amqp-websocket) | ||
|
|
||
| To run the example you need to have: | ||
| - Tanzu RabbitMQ 4.0 or later with the AMQP 1.0 and `rabbitmq_web_amqp` plugins enabled. | ||
| - A vhost called `ws` configured for WebSocket connections. | ||
| - A user `rabbit` pwd `rabbit` with access to the `ws` vhost. | ||
|
|
||
| ## Web Sockify | ||
|
Gsantomaggio marked this conversation as resolved.
|
||
| It is possible to run the example with [websockify](https://github.com/novnc/websockify) | ||
This file contains hidden or 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,91 @@ | ||
| // RabbitMQ AMQP 1.0 Go Client: https://github.com/rabbitmq/rabbitmq-amqp-go-client | ||
| // RabbitMQ AMQP 1.0 documentation: https://www.rabbitmq.com/docs/amqp | ||
| // The example is demonstrating how to connect to RabbitMQ using AMQP 1.0 over WebSocket protocol with SASLTypePlain, | ||
| // declare a queue, publish a message to it, and then consume that message. | ||
| // AMQP 1.0 over WebSocket documentation: https://www.rabbitmq.com/blog/2025/04/16/amqp-websocket | ||
| // example path: https://github.com/rabbitmq/rabbitmq-amqp-go-client/tree/main/docs/examples/web_sockets/web_sockets.go | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/Azure/go-amqp" | ||
| rmq "github.com/rabbitmq/rabbitmq-amqp-go-client/pkg/rabbitmqamqp" | ||
| ) | ||
|
|
||
| func main() { | ||
| const amqpConnectionString = "ws://127.0.0.1:15678/ws" | ||
| rmq.Info("[Example]", "Starting web socket connection to", amqpConnectionString) | ||
| // for anonymous connection use: | ||
| // env := rmq.NewEnvironment(amqpConnectionString, &rmq.AmqpConnOptions{ | ||
| // SASLType: amqp.SASLTypeAnonymous(), | ||
| // }) | ||
| env := rmq.NewEnvironment(amqpConnectionString, &rmq.AmqpConnOptions{ | ||
| SASLType: amqp.SASLTypePlain("rabbit", "rabbit"), | ||
| }) | ||
| conn, err := env.NewConnection(context.Background()) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| _, err = conn.Management().DeclareQueue(context.TODO(), &rmq.QuorumQueueSpecification{ | ||
| Name: "test-ws-queue", | ||
| }) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| // declare new producer | ||
| producer, err := conn.NewPublisher(context.TODO(), &rmq.QueueAddress{ | ||
| Queue: "test-ws-queue", | ||
| }, nil) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| msg := rmq.NewMessage([]byte("Hello over WebSockets")) | ||
|
|
||
| publishResult, err := producer.Publish(context.Background(), msg) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| switch publishResult.Outcome.(type) { | ||
| case *rmq.StateAccepted: | ||
| rmq.Info("[Publisher]", "Message accepted", publishResult.Message.Data[0]) | ||
| default: | ||
| rmq.Warn("[Publisher]", "Message not accepted", publishResult.Message.Data[0]) | ||
| } | ||
|
|
||
| // declare new consumer | ||
| consumer, err := conn.NewConsumer(context.TODO(), "test-ws-queue", nil) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| deliveryContext, err := consumer.Receive(context.Background()) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| rmq.Info("[Consumer]", "Message received", string(deliveryContext.Message().GetData())) | ||
| err = deliveryContext.Accept(context.Background()) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| // clean up | ||
| err = consumer.Close(context.TODO()) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| err = producer.Close(context.TODO()) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
| err = conn.Management().DeleteQueue(context.Background(), "test-ws-queue") | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
| err = conn.Close(context.TODO()) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
| } |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation mentions a vhost called 'ws' is required (line 12), but the example code uses the default vhost (no vhost specified in the connection string on line 17 of web_sockets.go). This inconsistency between documentation and code will confuse users. Either update the connection string to include the 'ws' vhost or correct the documentation to match the example.