Skip to content

Commit 76ad9bb

Browse files
author
Andre Bossard
committed
Squashed commit of the following:
commit 3549843 Author: Josh van Leeuwen <[email protected]> Date: Mon Mar 24 17:50:50 2025 -0300 go.mod: CVE updates (dapr#3713) Signed-off-by: joshvanl <[email protected]> Signed-off-by: Andre Bossard <[email protected]> commit 9a11502 Author: Cassie Coyle <[email protected]> Date: Wed Apr 23 07:33:24 2025 -0500 Add baggage header support to http binding (dapr#3723) Signed-off-by: Cassandra Coyle <[email protected]> Signed-off-by: Andre Bossard <[email protected]> commit 8014a1d Author: Josh van Leeuwen <[email protected]> Date: Wed Mar 26 19:55:55 2025 -0300 CVE go mod dep update (dapr#3716) Signed-off-by: joshvanl <[email protected]> Signed-off-by: Andre Bossard <[email protected]> commit 72ffcd1 Author: Josh van Leeuwen <[email protected]> Date: Mon Mar 24 17:50:50 2025 -0300 go.mod: CVE updates (dapr#3713) Signed-off-by: joshvanl <[email protected]> Signed-off-by: Andre Bossard <[email protected]> commit 12be96f Author: Yaron Schneider <[email protected]> Date: Wed Jan 29 13:41:28 2025 -0800 Add deepseek support, update Go to 1.23.5 (dapr#3659) Signed-off-by: yaron2 <[email protected]> Signed-off-by: Andre Bossard <[email protected]> commit a00c8f3 Merge: a395f74 397766a Author: Andre Bossard <[email protected]> Date: Tue Apr 29 11:41:27 2025 +0200 Merge branch 'dapr:main' into supporting_more_properties_for_rabbitmq_on_main commit a395f74 Author: Andre Bossard <[email protected]> Date: Mon Apr 28 10:33:59 2025 +0200 Refactor tryGetProperty to use strings.EqualFold for case-insensitive key matching Signed-off-by: Andre Bossard <[email protected]> commit 1d4f3a1 Author: Anton Troshin <[email protected]> Date: Thu Apr 24 15:19:04 2025 -0500 Support Oracle Connect Descriptors (dapr#3800) Signed-off-by: Anton Troshin <[email protected]> Signed-off-by: Andre Bossard <[email protected]> commit 4630f5c Author: Anton Troshin <[email protected]> Date: Wed Apr 23 07:34:59 2025 -0500 Solace pubsub conformance test fix (dapr#3802) Signed-off-by: Anton Troshin <[email protected]> Co-authored-by: Yaron Schneider <[email protected]> Signed-off-by: Andre Bossard <[email protected]> commit ed3f7a8 Author: Cassie Coyle <[email protected]> Date: Wed Apr 23 07:33:24 2025 -0500 Add baggage header support to http binding (dapr#3723) Signed-off-by: Cassandra Coyle <[email protected]> Signed-off-by: Andre Bossard <[email protected]> commit af31fae Author: MikelRev <[email protected]> Date: Thu Apr 17 11:54:52 2025 -0400 Updated sqlserver auth to utilize default scope. (dapr#3698) Co-authored-by: Yaron Schneider <[email protected]> Signed-off-by: Andre Bossard <[email protected]> commit c5a0407 Author: Andre Bossard <[email protected]> Date: Wed Apr 16 13:39:26 2025 +0200 Fix metadata handling by removing unnecessary value escaping in RabbitMQ message processing Signed-off-by: Andre Bossard <[email protected]> commit 5bcb186 Author: Andre Bossard <[email protected]> Date: Wed Apr 16 13:13:24 2025 +0200 Refactor RabbitMQ metadata handling to use case-insensitive key retrieval Signed-off-by: Andre Bossard <[email protected]> commit 4f17a7f Author: Emmanuel Auffray <[email protected]> Date: Thu Apr 10 10:06:37 2025 +1200 Adding GoogleAI models too (dapr#3689) Signed-off-by: Emmanuel Auffray <[email protected]> Co-authored-by: Josh van Leeuwen <[email protected]> Co-authored-by: Yaron Schneider <[email protected]> Co-authored-by: Cassie Coyle <[email protected]> Signed-off-by: Andre Bossard <[email protected]> commit 652c733 Author: Josh van Leeuwen <[email protected]> Date: Wed Mar 26 19:55:55 2025 -0300 CVE go mod dep update (dapr#3716) Signed-off-by: joshvanl <[email protected]> Signed-off-by: Andre Bossard <[email protected]> commit 71e9a4b Author: Josh van Leeuwen <[email protected]> Date: Mon Mar 24 17:50:50 2025 -0300 go.mod: CVE updates (dapr#3713) Signed-off-by: joshvanl <[email protected]> Signed-off-by: Andre Bossard <[email protected]> commit 621f7ef Author: Emmanuel Auffray <[email protected]> Date: Mon Mar 24 05:38:17 2025 +1300 Adding Ollama as a conversation component for local dev/running of LLMs (dapr#3688) Signed-off-by: Emmanuel Auffray <[email protected]> Co-authored-by: Mike Nguyen <[email protected]> Co-authored-by: Yaron Schneider <[email protected]> Signed-off-by: Andre Bossard <[email protected]> commit 229524f Author: Emmanuel Auffray <[email protected]> Date: Sat Mar 22 00:52:15 2025 +1300 Fix reference links of conversation components (dapr#3690) Signed-off-by: Emmanuel Auffray <[email protected]> Signed-off-by: Andre Bossard <[email protected]> commit 9dbe6e3 Author: Andre Bossard <[email protected]> Date: Wed Apr 16 12:19:53 2025 +0200 Add metadata handling for RabbitMQ messages and corresponding test Signed-off-by: Andre Bossard <[email protected]> commit 3f0ec0b Author: Andre Bossard <[email protected]> Date: Thu Mar 20 03:25:29 2025 +0100 Add RabbitMQ metadata properties test and configuration Signed-off-by: Andre Bossard <[email protected]> commit b6acda8 Author: Andre Bossard <[email protected]> Date: Tue Mar 18 12:25:31 2025 +0100 Add integration test for publishing metadata properties to RabbitMQ Signed-off-by: Andre Bossard <[email protected]> commit f726110 Author: Andre Bossard <[email protected]> Date: Tue Mar 18 09:26:49 2025 +0100 Refactor RabbitMQ publishing: consolidate metadata application into a single function Signed-off-by: Andre Bossard <[email protected]> commit 4cb5600 Author: Andre Bossard <[email protected]> Date: Tue Mar 18 09:16:14 2025 +0100 Refactor RabbitMQ metadata handling: consolidate metadata retrieval into common package Signed-off-by: Andre Bossard <[email protected]> commit 069b12f Author: Andre Bossard <[email protected]> Date: Tue Mar 18 08:12:25 2025 +0100 Refactor metadata function names for consistency: update messageId and correlationId to messageID and correlationID commit d508479 Merge: af3fca0 d8ac01b Author: Andre Bossard <[email protected]> Date: Tue Mar 18 07:58:36 2025 +0100 Merge branch 'dapr:main' into supporting_more_properties_for_rabbitmq_on_main commit af3fca0 Merge: 57ae111 637d18d Author: Andre Bossard <[email protected]> Date: Wed Mar 12 03:28:26 2025 -0700 Merge branch 'main' into supporting_more_properties_for_rabbitmq_on_main commit 57ae111 Merge: d0c75f6 2997e47 Author: Andre Bossard <[email protected]> Date: Tue Mar 4 08:49:52 2025 +0100 Merge branch 'dapr:main' into supporting_more_properties_for_rabbitmq_on_main commit d0c75f6 Author: Andre Bossard <[email protected]> Date: Wed Feb 5 11:43:03 2025 +0100 Add support for messageId, correlationId, and type in RabbitMQ bindings Signed-off-by: Andre Bossard <[email protected]> Signed-off-by: Andre Bossard <[email protected]>
1 parent ed37e34 commit 76ad9bb

File tree

16 files changed

+661
-122
lines changed

16 files changed

+661
-122
lines changed

bindings/rabbitmq/rabbitmq.go

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
amqp "github.com/rabbitmq/amqp091-go"
3232

3333
"github.com/dapr/components-contrib/bindings"
34+
common "github.com/dapr/components-contrib/common/component/rabbitmq"
3435
"github.com/dapr/components-contrib/metadata"
3536
"github.com/dapr/kit/logger"
3637
kitmd "github.com/dapr/kit/metadata"
@@ -228,11 +229,6 @@ func (r *RabbitMQ) Invoke(ctx context.Context, req *bindings.InvokeRequest) (*bi
228229
pub.Headers[k] = v
229230
}
230231

231-
contentType, ok := metadata.TryGetContentType(req.Metadata)
232-
if ok {
233-
pub.ContentType = contentType
234-
}
235-
236232
// The default time to live has been set in the queue
237233
// We allow overriding on each call, by setting a value in request metadata
238234
ttl, ok, err := metadata.TryGetTTL(req.Metadata)
@@ -252,20 +248,7 @@ func (r *RabbitMQ) Invoke(ctx context.Context, req *bindings.InvokeRequest) (*bi
252248
pub.Priority = priority
253249
}
254250

255-
messageId, ok := metadata.TryGetMessageId(req.Metadata)
256-
if ok {
257-
pub.MessageId = messageId
258-
}
259-
260-
correlationId, ok := metadata.TryGetCorrelationId(req.Metadata)
261-
if ok {
262-
pub.CorrelationId = correlationId
263-
}
264-
265-
aType, ok := metadata.TryGetType(req.Metadata)
266-
if ok {
267-
pub.Type = aType
268-
}
251+
common.ApplyMetadataToPublishing(req.Metadata, &pub)
269252

270253
err = ch.PublishWithContext(ctx, "", r.metadata.QueueName, false, false, pub)
271254
if err != nil {
@@ -488,9 +471,9 @@ func (r *RabbitMQ) handleMessage(ctx context.Context, handler bindings.Handler,
488471
// Passthrough any custom metadata to the handler.
489472
for k, v := range d.Headers {
490473
if s, ok := v.(string); ok {
491-
// Escape the key and value to ensure they are valid URL query parameters.
474+
// Escape the key to ensure they are valid URL query parameters.
492475
// This is necessary for them to be sent as HTTP Metadata.
493-
metadata[url.QueryEscape(k)] = url.QueryEscape(s)
476+
metadata[url.QueryEscape(k)] = s
494477
}
495478
}
496479

bindings/rabbitmq/rabbitmq_integration_test.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,3 +447,67 @@ func TestPublishWithHeaders(t *testing.T) {
447447
// assert.Contains(t, msg.Header, "custom_header1")
448448
// assert.Contains(t, msg.Header, "custom_header2")
449449
}
450+
451+
func TestPublishMetadataProperties(t *testing.T) {
452+
rabbitmqHost := getTestRabbitMQHost()
453+
require.NotEmpty(t, rabbitmqHost, fmt.Sprintf("RabbitMQ host configuration must be set in environment variable '%s'", testRabbitMQHostEnvKey))
454+
455+
queueName := uuid.New().String()
456+
durable := true
457+
exclusive := false
458+
459+
metadata := bindings.Metadata{
460+
Base: contribMetadata.Base{
461+
Name: "testQueue",
462+
Properties: map[string]string{
463+
"queueName": queueName,
464+
"host": rabbitmqHost,
465+
"deleteWhenUnused": strconv.FormatBool(exclusive),
466+
"durable": strconv.FormatBool(durable),
467+
},
468+
},
469+
}
470+
471+
logger := logger.NewLogger("test")
472+
r := NewRabbitMQ(logger).(*RabbitMQ)
473+
err := r.Init(t.Context(), metadata)
474+
require.NoError(t, err)
475+
476+
conn, err := amqp.Dial(rabbitmqHost)
477+
require.NoError(t, err)
478+
defer conn.Close()
479+
480+
ch, err := conn.Channel()
481+
require.NoError(t, err)
482+
defer ch.Close()
483+
484+
const messageData = "test message"
485+
const msgID = "msg-123"
486+
const corrID = "corr-456"
487+
const msgType = "testType"
488+
const contentType = "application/json"
489+
490+
writeRequest := bindings.InvokeRequest{
491+
Data: []byte(messageData),
492+
Metadata: map[string]string{
493+
"messageID": msgID,
494+
"correlationID": corrID,
495+
"type": msgType,
496+
"contentType": contentType,
497+
},
498+
}
499+
_, err = r.Invoke(t.Context(), &writeRequest)
500+
require.NoError(t, err)
501+
502+
// Retrieve the message.
503+
msg, ok, err := getMessageWithRetries(ch, queueName, 2*time.Second)
504+
require.NoError(t, err)
505+
assert.True(t, ok)
506+
assert.Equal(t, messageData, string(msg.Body))
507+
assert.Equal(t, msgID, msg.MessageId)
508+
assert.Equal(t, corrID, msg.CorrelationId)
509+
assert.Equal(t, msgType, msg.Type)
510+
assert.Equal(t, contentType, msg.ContentType)
511+
512+
require.NoError(t, r.Close())
513+
}

common/component/rabbitmq/rabbitmq.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package rabbitmq
2+
3+
import (
4+
"strings"
5+
6+
amqp "github.com/rabbitmq/amqp091-go"
7+
)
8+
9+
// tryGetProperty checks for a property value using various key formats: original, camelCase, and case-insensitive
10+
func tryGetProperty(props map[string]string, keys ...string) (string, bool) {
11+
// First try exact match for all provided keys
12+
for _, key := range keys {
13+
if val, ok := props[key]; ok && val != "" {
14+
return val, true
15+
}
16+
}
17+
18+
// Then try case-insensitive match if no exact matches were found
19+
for k, v := range props {
20+
if v != "" {
21+
for _, key := range keys {
22+
if strings.EqualFold(key, k) {
23+
return v, true
24+
}
25+
}
26+
}
27+
}
28+
29+
return "", false
30+
}
31+
32+
func TryGetMessageID(props map[string]string) (string, bool) {
33+
return tryGetProperty(props, "messageId", "messageID", "MessageId", "MessageID")
34+
}
35+
36+
func TryGetCorrelationID(props map[string]string) (string, bool) {
37+
return tryGetProperty(props, "correlationId", "correlationID", "CorrelationId", "CorrelationID")
38+
}
39+
40+
func TryGetContentType(props map[string]string) (string, bool) {
41+
return tryGetProperty(props, "contentType", "ContentType")
42+
}
43+
44+
func TryGetType(props map[string]string) (string, bool) {
45+
return tryGetProperty(props, "type", "Type")
46+
}
47+
48+
// ApplyMetadataToPublishing applies common metadata fields to an AMQP publishing
49+
func ApplyMetadataToPublishing(metadata map[string]string, publishing *amqp.Publishing) {
50+
contentType, ok := TryGetContentType(metadata)
51+
if ok {
52+
publishing.ContentType = contentType
53+
}
54+
55+
messageID, ok := TryGetMessageID(metadata)
56+
if ok {
57+
publishing.MessageId = messageID
58+
}
59+
60+
correlationID, ok := TryGetCorrelationID(metadata)
61+
if ok {
62+
publishing.CorrelationId = correlationID
63+
}
64+
65+
aType, ok := TryGetType(metadata)
66+
if ok {
67+
publishing.Type = aType
68+
}
69+
}

conversation/deepseek/metadata.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ status: alpha
77
title: "Deepseek"
88
urls:
99
- title: Reference
10-
url: https://docs.dapr.io/reference/components-reference/supported-conversation/deepseek/
10+
url: https://docs.dapr.io/reference/components-reference/supported-conversation/setup-deepseek/
1111
authenticationProfiles:
1212
- title: "API Key"
1313
description: "Authenticate using an API key"

go.mod

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ require (
126126
go.uber.org/multierr v1.11.0
127127
go.uber.org/ratelimit v0.3.0
128128
golang.org/x/crypto v0.35.0
129-
golang.org/x/mod v0.23.0
129+
golang.org/x/mod v0.17.0
130130
golang.org/x/net v0.36.0
131-
golang.org/x/oauth2 v0.27.0
131+
golang.org/x/oauth2 v0.21.0
132132
google.golang.org/api v0.180.0
133133
google.golang.org/grpc v1.66.0
134134
google.golang.org/protobuf v1.34.2
@@ -164,6 +164,7 @@ require (
164164
github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2 // indirect
165165
github.com/Code-Hex/go-generics-cache v1.3.1 // indirect
166166
github.com/DataDog/zstd v1.5.2 // indirect
167+
github.com/Microsoft/go-winio v0.6.2 // indirect
167168
github.com/OneOfOne/xxhash v1.2.8 // indirect
168169
github.com/RoaringBitmap/roaring v1.1.0 // indirect
169170
github.com/Workiva/go-datastructures v1.0.53 // indirect
@@ -404,7 +405,7 @@ require (
404405
golang.org/x/term v0.29.0 // indirect
405406
golang.org/x/text v0.22.0 // indirect
406407
golang.org/x/time v0.6.0 // indirect
407-
golang.org/x/tools v0.30.0 // indirect
408+
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
408409
google.golang.org/genproto v0.0.0-20240401170217-c3f982113cda // indirect
409410
google.golang.org/genproto/googleapis/api v0.0.0-20240701130421-f6361c86f094 // indirect
410411
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 // indirect

0 commit comments

Comments
 (0)