ASB: Add support for ApplicationProperties in subscriptions (#3436)

Signed-off-by: Bernd Verst <github@bernd.dev>
This commit is contained in:
Bernd Verst 2024-06-05 10:26:28 -07:00 committed by GitHub
parent f0be1a2d28
commit f23794f69b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 0 deletions

View File

@ -15,6 +15,7 @@ package servicebus
import (
"encoding/base64"
"github.com/spf13/cast"
"net/http"
"strconv"
@ -58,6 +59,12 @@ func addMessageAttributesToMetadata(metadata map[string]string, asbMsg *azservic
metadata = map[string]string{}
}
for key, val := range asbMsg.ApplicationProperties {
metadata["metadata."+key] = cast.ToString(val)
}
// We are not concerned about key conflicts here as we do not allow custom properties that match well-known property names
if asbMsg.MessageID != "" {
metadata["metadata."+MessageKeyMessageID] = asbMsg.MessageID
}

View File

@ -44,6 +44,10 @@ func TestAddMessageAttributesToMetadata(t *testing.T) {
ScheduledEnqueueTime: &testSampleTime,
PartitionKey: &testPartitionKey,
LockedUntil: &testSampleTime,
ApplicationProperties: map[string]interface{}{
"hello": "world",
"numeric": 1,
},
},
expectedMetadata: map[string]string{
"metadata." + MessageKeyMessageID: testMessageID,
@ -60,6 +64,8 @@ func TestAddMessageAttributesToMetadata(t *testing.T) {
"metadata." + MessageKeyScheduledEnqueueTimeUtc: testSampleTimeHTTPFormat,
"metadata." + MessageKeyPartitionKey: testPartitionKey,
"metadata." + MessageKeyLockedUntilUtc: testSampleTimeHTTPFormat,
"metadata.hello": "world",
"metadata.numeric": "1",
},
},
}