mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2025-12-30 05:09:44 -06:00
feat: max channels for rabbitmq (#2365)
* feat: max conns for rabbitmq * rename conns -> chans
This commit is contained in:
@@ -51,7 +51,7 @@ func (p *channelPool) hasActiveConnection() bool {
|
||||
return p.conn != nil && !p.conn.IsClosed()
|
||||
}
|
||||
|
||||
func newChannelPool(ctx context.Context, l *zerolog.Logger, url string) (*channelPool, error) {
|
||||
func newChannelPool(ctx context.Context, l *zerolog.Logger, url string, maxChannels int32) (*channelPool, error) {
|
||||
p := &channelPool{
|
||||
l: l,
|
||||
url: url,
|
||||
@@ -116,7 +116,7 @@ func newChannelPool(ctx context.Context, l *zerolog.Logger, url string) (*channe
|
||||
}()
|
||||
|
||||
// FIXME: this is probably too many channels
|
||||
maxPoolSize := int32(100)
|
||||
maxPoolSize := maxChannels
|
||||
|
||||
pool, err := puddle.NewPool(&puddle.Config[*amqp.Channel]{
|
||||
Constructor: constructor,
|
||||
|
||||
@@ -59,6 +59,8 @@ type MessageQueueImplOpts struct {
|
||||
qos int
|
||||
disableTenantExchangePubs bool
|
||||
deadLetterBackoff time.Duration
|
||||
maxPubChannels int32
|
||||
maxSubChannels int32
|
||||
}
|
||||
|
||||
func defaultMessageQueueImplOpts() *MessageQueueImplOpts {
|
||||
@@ -83,6 +85,18 @@ func WithURL(url string) MessageQueueImplOpt {
|
||||
}
|
||||
}
|
||||
|
||||
func WithMaxPubChannels(maxConns int32) MessageQueueImplOpt {
|
||||
return func(opts *MessageQueueImplOpts) {
|
||||
opts.maxPubChannels = maxConns
|
||||
}
|
||||
}
|
||||
|
||||
func WithMaxSubChannels(maxConns int32) MessageQueueImplOpt {
|
||||
return func(opts *MessageQueueImplOpts) {
|
||||
opts.maxSubChannels = maxConns
|
||||
}
|
||||
}
|
||||
|
||||
func WithQos(qos int) MessageQueueImplOpt {
|
||||
return func(opts *MessageQueueImplOpts) {
|
||||
opts.qos = qos
|
||||
@@ -114,14 +128,26 @@ func New(fs ...MessageQueueImplOpt) (func() error, *MessageQueueImpl) {
|
||||
newLogger := opts.l.With().Str("service", "rabbitmq").Logger()
|
||||
opts.l = &newLogger
|
||||
|
||||
pubChannelPool, err := newChannelPool(ctx, opts.l, opts.url)
|
||||
pubMaxChans := opts.maxPubChannels
|
||||
|
||||
if pubMaxChans <= 0 {
|
||||
pubMaxChans = 20
|
||||
}
|
||||
|
||||
pubChannelPool, err := newChannelPool(ctx, opts.l, opts.url, pubMaxChans)
|
||||
|
||||
if err != nil {
|
||||
cancel()
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
subChannelPool, err := newChannelPool(ctx, opts.l, opts.url)
|
||||
subMaxChans := opts.maxSubChannels
|
||||
|
||||
if subMaxChans <= 0 {
|
||||
subMaxChans = 100
|
||||
}
|
||||
|
||||
subChannelPool, err := newChannelPool(ctx, opts.l, opts.url, subMaxChans)
|
||||
|
||||
if err != nil {
|
||||
pubChannelPool.Close()
|
||||
|
||||
Reference in New Issue
Block a user