Skip to content

Commit 3f5cc3a

Browse files
Rename Consumer Feature to Consumer SettleStrategy (#82)
* Renames the consumer “feature” configuration to a settle-strategy like the same naming used by other AMQP 1.0 clients. Changes: * Replace ConsumerFeature/ConsumerOptions.Feature with ConsumerSettleStrategy/ConsumerOptions.SettleStrategy and rename DefaultSettle to ExplicitSettle. * Replace RequesterOptions.DirectReplyTo bool with RequesterOptions.SettleStrategy ConsumerSettleStrategy. Update tests, examples, AGENTS guidance, and changelog to reflect the new API names. --------- Signed-off-by: Gabriele Santomaggio <G.santomaggio@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent c6a4490 commit 3f5cc3a

9 files changed

Lines changed: 49 additions & 30 deletions

File tree

AGENTS.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ docs/examples/ # Example code demonstrating usage
6666
- `initialCredits()` - Initial credits (defaults to 256)
6767
- `linkFilters()` - Link filters for stream consumers
6868
- `id()` - Consumer ID
69-
- `isDirectReplyToEnable()` - Enable direct reply-to for RPC
69+
- `validate()` - Validates the configured consumer options
70+
- `isDirectReplyToEnable()` - Indicates whether Direct Reply-To is enabled for this consumer
71+
- `preSettled()` - Indicates whether the consumer operates in pre-settled mode
72+
- Settle strategy is configured via `ConsumerOptions.SettleStrategy` or `RequesterOptions.SettleStrategy` using the `ConsumerSettleStrategy` enum: `ExplicitSettle`, `DirectReplyTo`, `PreSettled`
7073

7174
### Queue Specifications
7275

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ All notable changes to this project will be documented in this file.
77
## 0.5.0 - 2026-01-22
88
- [Release 0.5.0](https://github.com/rabbitmq/rabbitmq-amqp-go-client/releases/tag/v0.5.0)
99

10+
### Breaking changes
11+
- **RequesterOptions**: Replaced `DirectReplyTo bool` with `SettleStrategy ConsumerSettleStrategy`. Use `SettleStrategy: rabbitmqamqp.DirectReplyTo` for direct-reply-to, or leave zero value for default (dedicated reply queue). Aligns consumer/requester configuration with other AMQP 1.0 clients.
12+
- **ConsumerOptions / amqp_types**: Renamed `ConsumerFeature` to `ConsumerSettleStrategy`, `DefaultSettle` to `ExplicitSettle`, and `Feature` field to `SettleStrategy`. Aligns with the unified settle strategy API used in other AMQP 1.0 clients.
13+
1014
### Added
1115
- Add WebSocket transport support for AMQP 1.0 connections by @vedanthnyk25 in [#78](https://github.com/rabbitmq/rabbitmq-amqp-go-client/pull/78)
1216
- Add Sec-WebSocket-Protocol to the HTTP header by @Gsantomaggio in [#79](https://github.com/rabbitmq/rabbitmq-amqp-go-client/pull/79)

docs/examples/pre_settled/pre_settled.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func main() {
5555
// create consumer with pre-settled mode enabled
5656

5757
consumer, err := amqpConnection.NewConsumer(context.TODO(), "pre-settled-queue", &rmq.ConsumerOptions{
58-
Feature: rmq.PreSettled,
58+
SettleStrategy: rmq.PreSettled,
5959
})
6060
if err != nil {
6161
rmq.Error("Error creating consumer", err)

docs/examples/rpc_echo_server/main.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
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 RPC echo server and client using RabbitMQ AMQP 1.0 Go Client.
4+
// It uses DirectReplyTo for the client to receive responses without needing to declare a reply queue.
5+
// DirectReplyTo is the recommended way to receive replies for RPC clients.
6+
// The server listens for messages on a request queue and responds with the same message (echo).
7+
// The client sends messages to the request queue and waits for the echoed response.
8+
// The example also includes graceful shutdown handling when the user presses Ctrl+C.
9+
// Example path:https://github.com/rabbitmq/rabbitmq-amqp-go-client/tree/main/docs/examples/rpc_echo_server/main.go
10+
111
package main
212

313
import (
@@ -66,9 +76,11 @@ func main() {
6676

6777
requester, err := clientConn.NewRequester(context.TODO(), &rabbitmqamqp.RequesterOptions{
6878
RequestQueueName: requestQueue,
69-
// Enable Direct Reply To feature
70-
// see: https://www.rabbitmq.com/direct-reply-to.html
71-
DirectReplyTo: true,
79+
// Use DirectReplyTo so replies are received via RabbitMQ direct-reply-to (no reply queue declared).
80+
// See: https://www.rabbitmq.com/docs/direct-reply-to#overview
81+
// That's the recommended way to receive replies for RPC clients,
82+
// as it avoids the overhead of declaring and consuming from a reply queue.
83+
SettleStrategy: rabbitmqamqp.DirectReplyTo,
7284
})
7385
if err != nil {
7486
panic(err)

pkg/rabbitmqamqp/amqp_connection.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ func (a *AmqpConnection) NewRequester(ctx context.Context, options *RequesterOpt
276276

277277
replyQueueName := options.ReplyToQueueName
278278
queueName := ""
279-
if !options.DirectReplyTo {
279+
if options.SettleStrategy != DirectReplyTo {
280280

281281
if len(replyQueueName) == 0 {
282282
replyQueueName = generateNameWithDefaultPrefix()
@@ -333,13 +333,9 @@ func (a *AmqpConnection) NewRequester(ctx context.Context, options *RequesterOpt
333333
done: make(chan struct{}),
334334
}
335335

336-
feature := DefaultSettle
337-
if options.DirectReplyTo {
338-
feature = DirectReplyTo
339-
}
340336
// Create consumer for receiving replies
341337
consumer, err := a.NewConsumer(ctx, queueName, &ConsumerOptions{
342-
Feature: feature,
338+
SettleStrategy: options.SettleStrategy,
343339
})
344340
if err != nil {
345341
_ = publisher.Close(ctx) // cleanup publisher on failure

pkg/rabbitmqamqp/amqp_consumer_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var _ = Describe("NewConsumer tests", func() {
4343
Expect(err).To(BeNil())
4444
Expect(queue).NotTo(BeNil())
4545
publishMessages(qName, 10)
46-
consumer, err := connection.NewConsumer(context.Background(), qName, &ConsumerOptions{Feature: DefaultSettle})
46+
consumer, err := connection.NewConsumer(context.Background(), qName, &ConsumerOptions{SettleStrategy: ExplicitSettle})
4747
Expect(err).To(BeNil())
4848
Expect(consumer).NotTo(BeNil())
4949
Expect(consumer).To(BeAssignableToTypeOf(&Consumer{}))
@@ -247,7 +247,7 @@ var _ = Describe("Consumer direct reply to", func() {
247247
Expect(err).To(BeNil())
248248

249249
consumer, err := connection.NewConsumer(context.Background(), "", &ConsumerOptions{
250-
Feature: DirectReplyTo,
250+
SettleStrategy: DirectReplyTo,
251251
})
252252
Expect(err).To(BeNil())
253253
Expect(consumer).NotTo(BeNil())
@@ -331,7 +331,7 @@ var _ = Describe("Consumer pre-settled", func() {
331331
// Create consumer with pre-settled enabled
332332
consumer, err := connection.NewConsumer(context.Background(), qName, &ConsumerOptions{
333333
InitialCredits: initialCredits,
334-
Feature: PreSettled,
334+
SettleStrategy: PreSettled,
335335
})
336336
Expect(err).To(BeNil())
337337
Expect(consumer).NotTo(BeNil())

pkg/rabbitmqamqp/amqp_exchange_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var _ = Describe("AMQP Exchange test ", func() {
2222
})
2323

2424
It("AMQP Exchange Declare with Default and Delete should succeed", func() {
25-
const exchangeName = "AMQP Exchange Declare and Delete with DefaultSettle should succeed"
25+
const exchangeName = "AMQP Exchange Declare and Delete with ExplicitSettle should succeed"
2626
exchangeInfo, err := management.DeclareExchange(context.TODO(), &DirectExchangeSpecification{
2727
Name: exchangeName,
2828
})

pkg/rabbitmqamqp/amqp_types.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,17 @@ func (mo *managementOptions) preSettled() bool {
111111
return false
112112
}
113113

114-
type ConsumerFeature byte
114+
// ConsumerSettleStrategy configures how the consumer receives and settles messages.
115+
// Aligns with the settle strategy concept used across AMQP 1.0 clients.
116+
type ConsumerSettleStrategy byte
115117

116118
const (
117-
// DefaultSettle means that the consumer will be created with the default settings.
118-
// message settle mode will be the default one (explicit settle) via IDeliveryContext
119-
DefaultSettle ConsumerFeature = iota
119+
// ExplicitSettle means that the consumer will be created with the default settings.
120+
// Message settle mode will be explicit via IDeliveryContext (accept, discard, requeue).
121+
ExplicitSettle ConsumerSettleStrategy = iota
120122
// DirectReplyTo means that the consumer will be created with the direct reply to feature enabled.
121-
// see https://www.rabbitmq.com/docs/direct-reply-to#overview message settle mode will be auto-settled
122-
//for direct reply to consumers.
123+
// See https://www.rabbitmq.com/docs/direct-reply-to#overview. Message settle mode will be auto-settled
124+
// for direct reply to consumers.
123125
DirectReplyTo
124126
// PreSettled means that the consumer will be created with the pre-settled delivery mode.
125127
// The server settles the deliveries as soon as they are sent to the consumer,
@@ -136,9 +138,9 @@ type ConsumerOptions struct {
136138
// The id of the consumer
137139
Id string
138140

139-
// Feature represents the feature that should be enabled for the consumer.
140-
// see ConsumerFeature for more details.
141-
Feature ConsumerFeature
141+
// SettleStrategy configures how messages are received and settled.
142+
// See ConsumerSettleStrategy for more details.
143+
SettleStrategy ConsumerSettleStrategy
142144
}
143145

144146
func (aco *ConsumerOptions) linkName() string {
@@ -159,19 +161,19 @@ func (aco *ConsumerOptions) id() string {
159161

160162
func (aco *ConsumerOptions) validate(available *featuresAvailable) error {
161163
// direct reply to is supported since RabbitMQ 4.2.0
162-
if aco.Feature == DirectReplyTo && !available.is42rMore {
164+
if aco.SettleStrategy == DirectReplyTo && !available.is42rMore {
163165
return fmt.Errorf("direct reply to feature is not supported. You need RabbitMQ 4.2 or later")
164166
}
165167

166168
return nil
167169
}
168170

169171
func (aco *ConsumerOptions) isDirectReplyToEnable() bool {
170-
return aco.Feature == DirectReplyTo
172+
return aco.SettleStrategy == DirectReplyTo
171173
}
172174

173175
func (aco *ConsumerOptions) preSettled() bool {
174-
return aco.Feature == PreSettled
176+
return aco.SettleStrategy == PreSettled
175177
}
176178

177179
type IOffsetSpecification interface {

pkg/rabbitmqamqp/requester.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,11 @@ type RequesterOptions struct {
123123
// Optional. If not set, a default timeout of 30 seconds will be used.
124124
RequestTimeout time.Duration
125125

126-
// If true, the requester will set the 'Direct-Reply-To' feature for RabbitMQ.
127-
// see: https://www.rabbitmq.com/direct-reply-to.html
128-
DirectReplyTo bool
126+
// SettleStrategy configures how the reply consumer receives messages.
127+
// Use ExplicitSettle for a dedicated reply queue (default).
128+
// Use DirectReplyTo to enable RabbitMQ direct-reply-to (no reply queue declared).
129+
// See: https://www.rabbitmq.com/docs/direct-reply-to#overview
130+
SettleStrategy ConsumerSettleStrategy
129131
}
130132

131133
type outstandingRequest struct {

0 commit comments

Comments
 (0)