Add Sec-WebSocket-Protocol to the HTTP header#79
Conversation
add example Signed-off-by: Gabriele Santomaggio <G.santomaggio@gmail.com>
There was a problem hiding this comment.
Pull request overview
This pull request adds support for the AMQP WebSocket subprotocol by including the Sec-WebSocket-Protocol header in WebSocket connections, and provides a complete example demonstrating AMQP 1.0 over WebSockets.
Changes:
- Added
Sec-WebSocket-Protocol: amqpheader to WebSocket connection initialization - Created a comprehensive WebSocket example with queue declaration, message publishing, and consumption
- Added documentation for setting up and running the WebSocket example
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| pkg/rabbitmqamqp/amqp_connection.go | Adds Sec-WebSocket-Protocol header to specify AMQP subprotocol for WebSocket connections |
| docs/examples/web_sockets/web_sockets.go | New example demonstrating full AMQP workflow over WebSocket protocol |
| docs/examples/web_sockets/README.md | Documentation for WebSocket example including setup requirements and alternatives |
| docs/examples/README.md | Updates examples index to include new WebSocket example |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // The example is demonstrating how to connect to RabbitMQ using AMQP 1.0 over WebSocket protocol, | ||
| // 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 |
There was a problem hiding this comment.
There is an extra forward slash in the example path. It should be "/tree/main/docs/examples/web_sockets/" instead of "/tree/main/docs/examples//web_sockets/".
| // example path: https://github.com/rabbitmq/rabbitmq-amqp-go-client/tree/main/docs/examples//web_sockets/web_sockets.go | |
| // example path: https://github.com/rabbitmq/rabbitmq-amqp-go-client/tree/main/docs/examples/web_sockets/web_sockets.go |
| - A vhost called `ws` configured for WebSocket connections. | ||
| - A user `rabbit` pwd `rabbit` with access to the `ws` vhost. |
There was a problem hiding this comment.
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.
| - A vhost called `ws` configured for WebSocket connections. | |
| - A user `rabbit` pwd `rabbit` with access to the `ws` vhost. | |
| - A vhost (for example the default `/`) configured for WebSocket connections. | |
| - A user `rabbit` pwd `rabbit` with access to that vhost. |
| // add sec-websocket-protocol amqp | ||
| headers.Add("Sec-WebSocket-Protocol", "amqp") |
There was a problem hiding this comment.
The new Sec-WebSocket-Protocol header addition lacks test coverage. Since other connection functionality in amqp_connection_test.go has comprehensive test coverage, this new behavior should also be tested. Consider adding a test case that verifies the header is properly set in the returned http.Header, both with and without authentication credentials.
add example Signed-off-by: Gabriele Santomaggio <G.santomaggio@gmail.com>
This pull request adds support for the AMQP WebSocket subprotocol by including the
Sec-WebSocket-Protocolheader in WebSocket connections, and provides a complete example demonstrating AMQP 1.0 over WebSockets.Changes:
Sec-WebSocket-Protocol: amqpheader to WebSocket connection initializationComplete: #78