Skip to content

Commit 850965c

Browse files
authored
Add code documentation (#86)
* Add code documentation Signed-off-by: Gabriele Santomaggio <G.santomaggio@gmail.com> * Fix Agents.md Signed-off-by: Gabriele Santomaggio <G.santomaggio@gmail.com> --------- Signed-off-by: Gabriele Santomaggio <G.santomaggio@gmail.com>
1 parent acfc8d3 commit 850965c

13 files changed

Lines changed: 134 additions & 87 deletions

File tree

AGENTS.md

Lines changed: 5 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ docs/examples/ # Example code demonstrating usage
7777
- **`QuorumQueueSpecification`** - Specification for quorum queues
7878
- **`ClassicQueueSpecification`** - Specification for classic queues
7979
- **`StreamQueueSpecification`** - Specification for stream queues
80+
- **`AutoGeneratedQueueSpecification`** - It is a classic queue with auto-generated name
81+
- **`DefaultQueueSpecification`** - Default queue specification. Server will decide the queue type based on the virtual host configuration.
8082

8183
## Code Conventions
8284

@@ -105,67 +107,9 @@ docs/examples/ # Example code demonstrating usage
105107
- `Info()`, `Error()`, `Debug()`, `Warn()`
106108
- Logging follows structured logging patterns with key-value pairs
107109

108-
## Common Patterns
109-
110-
### Creating a Connection
111-
112-
```go
113-
env, err := rabbitmqamqp.NewAmqpEnvironment(ctx, rabbitmqamqp.NewAmqpEnvironmentOptions().
114-
SetHost("localhost").
115-
SetUser("guest").
116-
SetPassword("guest"))
117-
```
118-
119-
### Publishing Messages
120-
121-
```go
122-
publisher, err := connection.NewAmqpPublisher(ctx, rabbitmqamqp.NewAmqpPublisherOptions().
123-
SetTarget("my-queue"))
124-
125-
msg := &amqp.Message{
126-
Body: []byte("Hello, RabbitMQ!"),
127-
}
128-
err = publisher.Publish(ctx, msg)
129-
```
130-
131-
### Consuming Messages
132-
133-
```go
134-
consumer, err := connection.NewAmqpConsumer(ctx, rabbitmqamqp.NewAmqpConsumerOptions().
135-
SetSource("my-queue").
136-
SetInitialCredits(100))
137-
138-
msgChan := consumer.Receive(ctx)
139-
for msg := range msgChan {
140-
// Process message
141-
msg.Accept(ctx)
142-
}
143-
```
144-
145-
### RPC Pattern
146-
147-
**Requester (Client):**
148-
```go
149-
requester, err := connection.NewRequester(ctx, rabbitmqamqp.NewRequesterOptions().
150-
SetRequestQueue("rpc-queue"))
151-
152-
msg := requester.Message([]byte("request"))
153-
replyChan, err := requester.Publish(ctx, msg)
154-
reply := <-replyChan
155-
```
156-
157-
**Responder (Server):**
158-
```go
159-
responder, err := connection.NewResponder(ctx, rabbitmqamqp.NewResponderOptions().
160-
SetRequestQueue("rpc-queue"))
161-
162-
msgChan := responder.Receive(ctx)
163-
for msg := range msgChan {
164-
// Process request and send reply
165-
responder.Send(ctx, msg, replyMsg)
166-
}
167-
```
168-
110+
### Examples
111+
- Example code is provided in the `docs/examples/` directory
112+
- Examples cover common use cases like publishing, consuming, RPC patterns, and management operations
169113
## Testing
170114

171115
- Tests use Ginkgo/Gomega framework
@@ -174,13 +118,6 @@ for msg := range msgChan {
174118
- Integration tests may require a running RabbitMQ instance
175119
- Use `make test` to run all tests
176120

177-
## Important Constants
178-
179-
- `AMQPS` - Protocol constant for AMQPS
180-
- `StreamFilterValue` - Header key for stream filtering
181-
- `commandReplyTo` - Direct reply-to address (`"$me"`)
182-
- `managementNodeAddress` - Management API address (`"/management"`)
183-
- `linkPairName` - Default management link name
184121

185122
## Breaking Changes
186123

docs/examples/advanced_settings/advanced_settings.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ package main
33
import (
44
"context"
55
"fmt"
6+
"time"
7+
68
"github.com/Azure/go-amqp"
79
rmq "github.com/rabbitmq/rabbitmq-amqp-go-client/pkg/rabbitmqamqp"
8-
"time"
910
)
1011

1112
func main() {

docs/examples/broadcast/broadcast.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1+
// RabbitMQ AMQP 1.0 Go Client: https://github.com/rabbitmq/rabbitmq-amqp-go-client
2+
// RabbitMQ AMQP 1.0 documentation: https://www.rabbitmq.com/docs/amqp
3+
// The example is demonstrating how to implement a simple broadcast scenario using RabbitMQ AMQP 1.0 Go Client.
4+
// In this example, a publisher sends messages to a fanout exchange, and multiple consumers receive the same messages from that exchange.
5+
// The example includes error handling and logging for each step of the process,
6+
// and it uses temporary queues for the consumers to receive messages from the fanout exchange.
7+
// Example path: / example path: https://github.com/rabbitmq/rabbitmq-amqp-go-client/tree/main/docs/examples/broadcast/broadcast.go
18
package main
29

310
import (
411
"context"
512
"fmt"
6-
rmq "github.com/rabbitmq/rabbitmq-amqp-go-client/pkg/rabbitmqamqp"
713
"time"
14+
15+
rmq "github.com/rabbitmq/rabbitmq-amqp-go-client/pkg/rabbitmqamqp"
816
)
917

1018
func main() {

docs/examples/getting_started/main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
// RabbitMQ AMQP 1.0 Go Client: https://github.com/rabbitmq/rabbitmq-amqp-go-client
2+
// RabbitMQ AMQP 1.0 documentation: https://www.rabbitmq.com/docs/amqp
3+
// The example is demonstrating how to use the RabbitMQ AMQP 1.0 Go Client to connect to a RabbitMQ server,
4+
// declare an exchange and a queue, bind them together, publish messages, consume messages, and then clean up resources before closing the connection.
5+
// It includes error handling and logging for each step of the process.
6+
// example path: https://github.com/rabbitmq/rabbitmq-amqp-go-client/tree/main/docs/examples/getting_started/main.go
7+
18
package main
29

310
import (

docs/examples/publisher_msg_targets/publisher_msg_targets.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1+
// RabbitMQ AMQP 1.0 Go Client: https://github.com/rabbitmq/rabbitmq-amqp-go-client
2+
// RabbitMQ AMQP 1.0 documentation: https://www.rabbitmq.com/docs/amqp
3+
// The example is demonstrating how to publish messages with specific targets (queues) using RabbitMQ AMQP 1.0 Go Client.
4+
// In this example, we define multiple queues and publish messages to them using the 'To' property of the message.
5+
// The publisher does not have a predefined target, allowing it to specify the destination for each message individually.
6+
// The example includes error handling and logging for each step of the process.
7+
// example path: https://github.com/rabbitmq/rabbitmq-amqp-go-client/tree/main/docs/examples/publisher_msg_targets/publisher_msg_targets.go
8+
19
package main
210

311
import (
412
"context"
13+
514
"github.com/Azure/go-amqp"
615
rmq "github.com/rabbitmq/rabbitmq-amqp-go-client/pkg/rabbitmqamqp"
716
)

docs/examples/reliable/reliable.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
1+
// RabbitMQ AMQP 1.0 Go Client: https://github.com/rabbitmq/rabbitmq-amqp-go-client
2+
// RabbitMQ AMQP 1.0 documentation: https://www.rabbitmq.com/docs/amqp
3+
// The example is demonstrating how to implement a reliable message publishing and consuming scenario using RabbitMQ AMQP 1.0 Go Client.
4+
// The example includes handling network disconnections, message acknowledgments, and tracking message states (accepted, released, rejected).
5+
// It simulates a publisher sending messages to a queue and a consumer receiving those messages while dealing with potential network issues.
6+
// The example also includes logging and statistics to monitor the message flow and connection status.
7+
// example path: https://github.com/rabbitmq/rabbitmq-amqp-go-client/tree/main/docs/examples/reliable/reliable.go
8+
19
package main
210

311
import (
412
"context"
513
"errors"
614
"fmt"
7-
"github.com/Azure/go-amqp"
8-
rmq "github.com/rabbitmq/rabbitmq-amqp-go-client/pkg/rabbitmqamqp"
915
"sync"
1016
"sync/atomic"
1117
"time"
18+
19+
"github.com/Azure/go-amqp"
20+
rmq "github.com/rabbitmq/rabbitmq-amqp-go-client/pkg/rabbitmqamqp"
1221
)
1322

1423
func main() {

docs/examples/sql_stream_filter/sql_stream_filter.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1+
// RabbitMQ AMQP 1.0 Go Client: https://github.com/rabbitmq/rabbitmq-amqp-go-client
2+
// RabbitMQ AMQP 1.0 documentation: https://www.rabbitmq.com/docs/amqp
3+
// RabbitMQ AMQP 1.0 SQL Stream Filter documentation: https://www.rabbitmq.com/blog/2024/12/13/amqp-filter-expressions
4+
// The example is demonstrating how to use SQL stream filters with RabbitMQ AMQP 1.0 Go Client.
5+
// In this example, we declare a stream queue and publish two messages to it: one that matches the SQL filter and one that does not.
6+
// We then create a consumer with a SQL stream filter that only accepts messages matching specific criteria.
7+
// The consumer should only receive the message that matches the filter, demonstrating how to use SQL stream filters effectively.
8+
9+
// example path: https://github.com/rabbitmq/rabbitmq-amqp-go-client/tree/main/docs/examples/sql_stream_filter/sql_stream_filter.go
110
package main
211

312
import (
413
"context"
514
"fmt"
15+
616
"github.com/Azure/go-amqp"
717
rmq "github.com/rabbitmq/rabbitmq-amqp-go-client/pkg/rabbitmqamqp"
818
)

docs/examples/streams/streams.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1+
// RabbitMQ AMQP 1.0 Go Client: https://github.com/rabbitmq/rabbitmq-amqp-go-client
2+
// RabbitMQ AMQP 1.0 documentation: https://www.rabbitmq.com/docs/amqp
3+
// RabbitMQ Streams documentation: https://www.rabbitmq.com/docs/streams
4+
// The example is demonstrating how to use RabbitMQ AMQP 1.0 Go Client to work with RabbitMQ Streams.
5+
// In this example, we declare a stream queue, publish messages to it, and then consume those messages from the stream.
6+
// The example includes error handling and logging for each step of the process, and it demonstrates how to work with RabbitMQ Streams using the AMQP 1.0 protocol.
7+
// example path: https://github.com/rabbitmq/rabbitmq-amqp-go-client/tree/main/docs/examples/streams/streams.go
8+
19
package main
210

311
import (
412
"context"
5-
rmq "github.com/rabbitmq/rabbitmq-amqp-go-client/pkg/rabbitmqamqp"
613
"time"
14+
15+
rmq "github.com/rabbitmq/rabbitmq-amqp-go-client/pkg/rabbitmqamqp"
716
)
817

918
func checkError(err error) {

docs/examples/streams_filtering/streams_filtering.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
1+
// RabbitMQ AMQP 1.0 Go Client: https://github.com/rabbitmq/rabbitmq-amqp-go-client
2+
// RabbitMQ AMQP 1.0 documentation: https://www.rabbitmq.com/docs/amqp
3+
// RabbitMQ Streams documentation: https://www.rabbitmq.com/docs/streams
4+
// RabbitMQ AMQP 1.0 SQL Stream Filter documentation: https://www.rabbitmq.com/blog/2024/12/13/amqp-filter-expressions
5+
// The example is demonstrating how to use RabbitMQ AMQP 1.0 Go Client to work with RabbitMQ Streams and SQL stream filters.
6+
// In this example, we declare a stream queue, publish messages to it, and then consume those messages from the stream using a SQL filter.
7+
// The example includes error handling and logging for each step of the process, and it demonstrates how to work with RabbitMQ Streams and apply SQL filters using the AMQP 1.0 protocol.
8+
// example path: https://github.com/rabbitmq/rabbitmq-amqp-go-client/tree/main/docs/examples/streams_filtering/streams_filtering.go
9+
110
package main
211

312
import (
413
"context"
5-
rmq "github.com/rabbitmq/rabbitmq-amqp-go-client/pkg/rabbitmqamqp"
614
"time"
15+
16+
rmq "github.com/rabbitmq/rabbitmq-amqp-go-client/pkg/rabbitmqamqp"
717
)
818

919
func checkError(err error) {

docs/examples/tls/tls.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import (
44
"context"
55
"crypto/tls"
66
"crypto/x509"
7+
"os"
8+
79
"github.com/Azure/go-amqp"
810
rmq "github.com/rabbitmq/rabbitmq-amqp-go-client/pkg/rabbitmqamqp"
9-
"os"
1011
)
1112

1213
func check(err error) {

0 commit comments

Comments
 (0)