Skip to content
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

Added Quorum Queue Support #3653

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions bindings/rabbitmq/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ metadata:
description: "RabbitMQ queue name."
type: string
example: '"myqueue"'
- name: queueType
required: false
description: "RabbitMQ queue type."
type: string
example: '"classic", "quorum"'
default: '"classic"'
- name: durable
type: bool
description: |
Expand Down
1 change: 1 addition & 0 deletions bindings/rabbitmq/rabbitmq.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ type rabbitMQMetadata struct {
ClientCert string `mapstructure:"clientCert"`
ClientKey string `mapstructure:"clientKey"`
ExternalSasl bool `mapstructure:"externalSasl"`
QueueType string `mapstructure:"queueType"`
}

// NewRabbitMQ returns a new rabbitmq instance.
Expand Down
42 changes: 42 additions & 0 deletions bindings/rabbitmq/rabbitmq_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,3 +447,45 @@ func TestPublishWithHeaders(t *testing.T) {
// assert.Contains(t, msg.Header, "custom_header1")
// assert.Contains(t, msg.Header, "custom_header2")
}
func TestQuorumQueue(t *testing.T) {
rabbitmqHost := getTestRabbitMQHost()
assert.NotEmpty(t, rabbitmqHost, fmt.Sprintf("RabbitMQ host configuration must be set in environment variable '%s' (example 'amqp://guest:guest@localhost:5672/')", testRabbitMQHostEnvKey))

queueName := uuid.New().String()
durable := true
exclusive := false

metadata := bindings.Metadata{
Base: contribMetadata.Base{
Name: "testQueue",
Properties: map[string]string{
"queueName": queueName,
"host": rabbitmqHost,
"deleteWhenUnused": strconv.FormatBool(exclusive),
"durable": strconv.FormatBool(durable),
"queueType": "quorum",
},
},
}

logger := logger.NewLogger("test")

r := NewRabbitMQ(logger).(*RabbitMQ)
err := r.Init(context.Background(), metadata)
require.NoError(t, err)

// Assert that the queue is created with quorum type
conn, err := amqp.Dial(rabbitmqHost)
require.NoError(t, err)
defer conn.Close()

ch, err := conn.Channel()
require.NoError(t, err)
defer ch.Close()

queue, err := ch.QueueDeclarePassive(queueName, durable, false, exclusive, false, amqp.Table{})
require.NoError(t, err)
assert.Equal(t, "quorum", queue.Arguments["x-queue-type"])

require.NoError(t, r.Close())
}
9 changes: 9 additions & 0 deletions bindings/rabbitmq/rabbitmq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func TestParseMetadata(t *testing.T) {
expectedClientKey string
expectedCACert string
expectedSaslExternal bool
expectedQueueType string
}{
{
name: "Delete / Durable",
Expand Down Expand Up @@ -101,6 +102,13 @@ func TestParseMetadata(t *testing.T) {
expectedDurable: false,
expectedExclusive: true,
},
{
name: "Quorum Queue",
properties: map[string]string{"queueName": queueName, "host": host, "deleteWhenUnused": "false", "durable": "false", "queueType": "quorum"},
expectedDeleteWhenUnused: false,
expectedDurable: false,
expectedQueueType: "quorum",
},
{
name: "With maxPriority",
properties: map[string]string{"queueName": queueName, "host": host, "deleteWhenUnused": "false", "durable": "false", "maxPriority": "1"},
Expand Down Expand Up @@ -158,6 +166,7 @@ func TestParseMetadata(t *testing.T) {
assert.Equal(t, tt.expectedClientKey, r.metadata.ClientKey)
assert.Equal(t, tt.expectedCACert, r.metadata.CaCert)
assert.Equal(t, tt.expectedSaslExternal, r.metadata.ExternalSasl)
assert.Equal(t, tt.expectedQueueType, r.metadata.QueueType)
if tt.expectedReconnectWaitCheck != nil {
assert.True(t, tt.expectedReconnectWaitCheck(r.metadata.ReconnectWait))
}
Expand Down
7 changes: 7 additions & 0 deletions pubsub/rabbitmq/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type rabbitmqMetadata struct {
SaslExternal bool `mapstructure:"saslExternal"`
Concurrency pubsub.ConcurrencyMode `mapstructure:"concurrency"`
DefaultQueueTTL *time.Duration `mapstructure:"ttlInSeconds"`
QueueType string `mapstructure:"queueType"`
}

const (
Expand Down Expand Up @@ -82,6 +83,7 @@ const (
metadataClientNameKey = "clientName"
metadataHeartBeatKey = "heartBeat"
metadataQueueNameKey = "queueName"
metadataQueueType = "queueType"

defaultReconnectWaitSeconds = 3

Expand All @@ -102,6 +104,7 @@ func createMetadata(pubSubMetadata pubsub.Metadata, log logger.Logger) (*rabbitm
PublisherConfirm: false,
SaslExternal: false,
HeartBeat: defaultHeartbeat,
QueueType: amqp.QueueTypeClassic,
}

// upgrade metadata
Expand Down Expand Up @@ -158,6 +161,10 @@ func createMetadata(pubSubMetadata pubsub.Metadata, log logger.Logger) (*rabbitm
return &result, fmt.Errorf("%s can only be set to true, when all these properties are set: %s, %s, %s", metadataSaslExternal, pubsub.CACert, pubsub.ClientCert, pubsub.ClientKey)
}

if result.QueueType != amqp.QueueTypeClassic && result.QueueType != amqp.QueueTypeQuorum {
return &result, fmt.Errorf("%s invalid RabbitMQ queue type %s", errorMessagePrefix, result.QueueType)
}

result.Concurrency, err = pubsub.Concurrency(pubSubMetadata.Properties)
return &result, err
}
Expand Down
Loading