-
Notifications
You must be signed in to change notification settings - Fork 68
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
Add support for concurrent dispatch and configurable prefetch #418
Changes from all commits
8da53db
710985a
003c692
2541dec
f4b42cd
a919722
021f11e
753c41c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,15 +41,15 @@ type envConfig struct { | |
// Should failed deliveries be requeued in the RabbitMQ? | ||
Requeue bool `envconfig:"REQUEUE" default:"false" required:"true"` | ||
|
||
// Number of concurrent messages in flight | ||
PrefetchCount int `envconfig:"PREFETCH_COUNT" default:"10" required:"false"` | ||
Retry int `envconfig:"RETRY" required:"false"` | ||
BackoffPolicy string `envconfig:"BACKOFF_POLICY" required:"false"` | ||
BackoffDelay time.Duration `envconfig:"BACKOFF_DELAY" required:"false"` | ||
} | ||
|
||
const ( | ||
defaultBackoffDelay = 50 * time.Millisecond | ||
defaultPrefetch = 1 | ||
defaultPrefetchSize = 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's safe to drop this since we force no-ack "The prefetch-size is ignored if the no-ack option is set" https://www.rabbitmq.com/amqp-0-9-1-reference.html#basic.qos.prefetch-size There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where do you see that we force no-ack? https://www.rabbitmq.com/amqp-0-9-1-reference.html#domain.no-ack That would imply we don't use acknowledgements, which is not true There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is how I'm reading go-amqp and the Rabbit docs:
https://www.rabbitmq.com/amqp-0-9-1-reference.html#basic.qos.prefetch-size We set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I think this is bad documentation on rabbit's part. I think they mean
Since we set it to false, we are not using autoAck/noAck, and therefore prefetch size/prefetch count is still relevant There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gerhard can you back me up on this interpretation? |
||
) | ||
|
||
func main() { | ||
|
@@ -99,15 +99,23 @@ func main() { | |
}() | ||
|
||
err = channel.Qos( | ||
defaultPrefetch, // prefetch count | ||
defaultPrefetchSize, // prefetch size | ||
false, // global | ||
env.PrefetchCount, // prefetch count | ||
0, // prefetch size | ||
false, // global | ||
) | ||
if err != nil { | ||
logging.FromContext(ctx).Fatal("Failed to create QoS: ", err) | ||
} | ||
|
||
d := dispatcher.NewDispatcher(env.BrokerIngressURL, env.SubscriberURL, env.Requeue, env.Retry, backoffDelay, backoffPolicy) | ||
d := &dispatcher.Dispatcher{ | ||
BrokerIngressURL: env.BrokerIngressURL, | ||
SubscriberURL: env.SubscriberURL, | ||
Requeue: env.Requeue, | ||
MaxRetries: env.Retry, | ||
BackoffDelay: backoffDelay, | ||
BackoffPolicy: backoffPolicy, | ||
WorkerCount: env.PrefetchCount, | ||
} | ||
if err := d.ConsumeFromQueue(ctx, channel, env.QueueName); err != nil { | ||
// ignore ctx cancelled and channel closed errors | ||
if errors.Is(err, context.Canceled) || errors.Is(err, amqperr.ErrClosed) { | ||
|
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.
I would set this as a
BackoffDelay
default.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.
Not sure what you mean. The prefetch count in milliseconds should be the backoff delay?
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.
#441