Skip to content

Commit d0c75f6

Browse files
author
Andre Bossard
committed
Add support for messageId, correlationId, and type in RabbitMQ bindings
Signed-off-by: Andre Bossard <[email protected]>
1 parent 1132db5 commit d0c75f6

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

bindings/rabbitmq/rabbitmq.go

+15
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,21 @@ func (r *RabbitMQ) Invoke(ctx context.Context, req *bindings.InvokeRequest) (*bi
252252
pub.Priority = priority
253253
}
254254

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+
}
269+
255270
err = ch.PublishWithContext(ctx, "", r.metadata.QueueName, false, false, pub)
256271
if err != nil {
257272
return nil, fmt.Errorf("failed to publish message: %w", err)

metadata/utils.go

+23
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,21 @@ func IsRawPayload(props map[string]string) (bool, error) {
113113

114114
return false, nil
115115
}
116+
func TryGetMessageId(props map[string]string) (string, bool) {
117+
if val, ok := props["messageId"]; ok && val != "" {
118+
return val, true
119+
}
120+
121+
return "", false
122+
}
123+
124+
func TryGetCorrelationId(props map[string]string) (string, bool) {
125+
if val, ok := props["correlationId"]; ok && val != "" {
126+
return val, true
127+
}
128+
129+
return "", false
130+
}
116131

117132
func TryGetContentType(props map[string]string) (string, bool) {
118133
if val, ok := props[ContentType]; ok && val != "" {
@@ -122,6 +137,14 @@ func TryGetContentType(props map[string]string) (string, bool) {
122137
return "", false
123138
}
124139

140+
func TryGetType(props map[string]string) (string, bool) {
141+
if val, ok := props["type"]; ok && val != "" {
142+
return val, true
143+
}
144+
145+
return "", false
146+
}
147+
125148
func TryGetQueryIndexName(props map[string]string) (string, bool) {
126149
if val, ok := props[QueryIndexName]; ok && val != "" {
127150
return val, true

pubsub/rabbitmq/rabbitmq.go

+20
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,26 @@ func (r *rabbitMQ) publishSync(ctx context.Context, req *pubsub.PublishRequest)
259259
p.Priority = priority
260260
}
261261

262+
contentType, ok := metadata.TryGetContentType(req.Metadata)
263+
if ok {
264+
p.ContentType = contentType
265+
}
266+
267+
messageId, ok := metadata.TryGetMessageId(req.Metadata)
268+
if ok {
269+
p.MessageId = messageId
270+
}
271+
272+
correlationId, ok := metadata.TryGetCorrelationId(req.Metadata)
273+
if ok {
274+
p.CorrelationId = correlationId
275+
}
276+
277+
aType, ok := metadata.TryGetType(req.Metadata)
278+
if ok {
279+
p.Type = aType
280+
}
281+
262282
confirm, err := r.channel.PublishWithDeferredConfirmWithContext(ctx, req.Topic, routingKey, false, false, p)
263283
if err != nil {
264284
r.logger.Errorf("%s publishing to %s failed in channel.Publish: %v", logMessagePrefix, req.Topic, err)

0 commit comments

Comments
 (0)