Skip to content

Commit 7b12c34

Browse files
committed
This is to implement queue args for RabbitMQ shovels
1 parent 62f01be commit 7b12c34

File tree

6 files changed

+56
-10
lines changed

6 files changed

+56
-10
lines changed

api/v1beta1/shovel_types.go

+6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ type ShovelSpec struct {
3636
SourcePrefetchCount int `json:"srcPrefetchCount,omitempty"`
3737
DestinationAddForwardHeaders bool `json:"destAddForwardHeaders,omitempty"`
3838
DestinationAddTimestampHeader bool `json:"destAddTimestampHeader,omitempty"`
39+
// +kubebuilder:validation:Type=object
40+
// +kubebuilder:pruning:PreserveUnknownFields
41+
SourceQueueArgs *runtime.RawExtension `json:"srcQueueArgs,omitempty"`
42+
// +kubebuilder:validation:Type=object
43+
// +kubebuilder:pruning:PreserveUnknownFields
44+
DestinationQueueArgs *runtime.RawExtension `json:"destQueueArgs,omitempty"`
3945

4046
// +kubebuilder:validation:Enum=amqp091;amqp10
4147
DestinationProtocol string `json:"destProtocol,omitempty"`

api/v1beta1/shovel_types_test.go

+18-10
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,22 @@ var _ = Describe("Shovel spec", func() {
7272
DestinationProtocol: "amqp091",
7373
DestinationPublishProperties: &runtime.RawExtension{Raw: []byte(`{"delivery_mode": 1}`)},
7474
DestinationQueue: "a-queue",
75-
PrefetchCount: 10,
76-
ReconnectDelay: 10,
77-
SourceAddress: "myQueue",
78-
SourceDeleteAfter: "never",
79-
SourceExchange: "an-exchange",
80-
SourceExchangeKey: "a-key",
81-
SourcePrefetchCount: 10,
82-
SourceProtocol: "amqp091",
83-
SourceQueue: "a-queue",
84-
SourceConsumerArgs: &runtime.RawExtension{Raw: []byte(`{"arg": "arg-value"}`)},
75+
DestinationQueueArgs: &runtime.RawExtension{
76+
Raw: []byte(`{"x-queue-type": "quorum"}`),
77+
},
78+
PrefetchCount: 10,
79+
ReconnectDelay: 10,
80+
SourceAddress: "myQueue",
81+
SourceDeleteAfter: "never",
82+
SourceExchange: "an-exchange",
83+
SourceExchangeKey: "a-key",
84+
SourcePrefetchCount: 10,
85+
SourceProtocol: "amqp091",
86+
SourceQueue: "a-queue",
87+
SourceQueueArgs: &runtime.RawExtension{
88+
Raw: []byte(`{"x-queue-type": "quorum"}`),
89+
},
90+
SourceConsumerArgs: &runtime.RawExtension{Raw: []byte(`{"arg": "arg-value"}`)},
8591
}}
8692
Expect(k8sClient.Create(ctx, &shovel)).To(Succeed())
8793
fetched := &Shovel{}
@@ -107,6 +113,7 @@ var _ = Describe("Shovel spec", func() {
107113
Expect(fetched.Spec.DestinationProperties.Raw).To(Equal([]byte(`{"key":"a-property"}`)))
108114
Expect(fetched.Spec.DestinationMessageAnnotations.Raw).To(Equal([]byte(`{"key":"a-property"}`)))
109115
Expect(fetched.Spec.DestinationQueue).To(Equal("a-queue"))
116+
Expect(fetched.Spec.DestinationQueueArgs.Raw).To(Equal([]byte(`{"x-queue-type":"quorum"}`)))
110117
Expect(fetched.Spec.PrefetchCount).To(Equal(10))
111118
Expect(fetched.Spec.ReconnectDelay).To(Equal(10))
112119

@@ -117,6 +124,7 @@ var _ = Describe("Shovel spec", func() {
117124
Expect(fetched.Spec.SourcePrefetchCount).To(Equal(10))
118125
Expect(fetched.Spec.SourceProtocol).To(Equal("amqp091"))
119126
Expect(fetched.Spec.SourceQueue).To(Equal("a-queue"))
127+
Expect(fetched.Spec.SourceQueueArgs.Raw).To(Equal([]byte(`{"x-queue-type":"quorum"}`)))
120128
Expect(fetched.Spec.SourceConsumerArgs.Raw).To(Equal([]byte(`{"arg":"arg-value"}`)))
121129
})
122130

api/v1beta1/zz_generated.deepcopy.go

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/rabbitmq.com_shovels.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ spec:
9090
destQueue:
9191
description: amqp091 configuration
9292
type: string
93+
destQueueArgs:
94+
type: object
95+
x-kubernetes-preserve-unknown-fields: true
9396
name:
9497
description: Required property; cannot be updated
9598
type: string
@@ -155,6 +158,9 @@ spec:
155158
srcQueue:
156159
description: amqp091 configuration
157160
type: string
161+
srcQueueArgs:
162+
type: object
163+
x-kubernetes-preserve-unknown-fields: true
158164
uriSecret:
159165
description: |-
160166
Secret contains the AMQP URI(s) to configure Shovel destination and source.

docs/api/rabbitmq.com.ref.asciidoc

+2
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,8 @@ Required property.
11761176
| *`srcPrefetchCount`* __integer__ |
11771177
| *`destAddForwardHeaders`* __boolean__ |
11781178
| *`destAddTimestampHeader`* __boolean__ |
1179+
| *`srcQueueArgs`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#rawextension-runtime-pkg[$$RawExtension$$]__ |
1180+
| *`destQueueArgs`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#rawextension-runtime-pkg[$$RawExtension$$]__ |
11791181
| *`destProtocol`* __string__ |
11801182
| *`destQueue`* __string__ | amqp091 configuration
11811183
| *`destExchange`* __string__ | amqp091 configuration

internal/shovel_definition.go

+14
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ func GenerateShovelDefinition(s *topology.Shovel, srcUri, destUri string) (*rabb
3939
return nil, fmt.Errorf("failed to unmarshall destination message annotations: %v", err)
4040
}
4141
}
42+
srcQueueArgs := make(map[string]interface{})
43+
if s.Spec.SourceQueueArgs != nil {
44+
if err := json.Unmarshal(s.Spec.SourceQueueArgs.Raw, &srcQueueArgs); err != nil {
45+
return nil, fmt.Errorf("failed to unmarshall source queue args: %v", err)
46+
}
47+
}
48+
destQueueArgs := make(map[string]interface{})
49+
if s.Spec.DestinationQueueArgs != nil {
50+
if err := json.Unmarshal(s.Spec.DestinationQueueArgs.Raw, &destQueueArgs); err != nil {
51+
return nil, fmt.Errorf("failed to unmarshall destination queue args: %v", err)
52+
}
53+
}
4254

4355
return &rabbithole.ShovelDefinition{
4456
SourceURI: strings.Split(srcUri, ","),
@@ -56,6 +68,7 @@ func GenerateShovelDefinition(s *topology.Shovel, srcUri, destUri string) (*rabb
5668
DestinationProtocol: s.Spec.DestinationProtocol,
5769
DestinationPublishProperties: destPubProperties,
5870
DestinationQueue: s.Spec.DestinationQueue,
71+
DestinationQueueArgs: destQueueArgs,
5972
DestinationMessageAnnotations: destMsgAnnotations,
6073
PrefetchCount: s.Spec.PrefetchCount,
6174
ReconnectDelay: s.Spec.ReconnectDelay,
@@ -66,6 +79,7 @@ func GenerateShovelDefinition(s *topology.Shovel, srcUri, destUri string) (*rabb
6679
SourcePrefetchCount: s.Spec.SourcePrefetchCount,
6780
SourceProtocol: s.Spec.SourceProtocol,
6881
SourceQueue: s.Spec.SourceQueue,
82+
SourceQueueArgs: srcQueueArgs,
6983
SourceConsumerArgs: srcConArgs,
7084
}, nil
7185
}

0 commit comments

Comments
 (0)