Skip to content

Commit

Permalink
use rabbitmq message's header values as metadata values in the binding
Browse files Browse the repository at this point in the history
…dapr#3030

Signed-off-by: Ohlicher Robert <[email protected]>
  • Loading branch information
Ohlicher Robert committed Aug 2, 2023
1 parent 25656c1 commit fbc55b6
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion bindings/rabbitmq/rabbitmq.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"errors"
"fmt"
"math"
"net/url"
"reflect"
"strconv"
"sync"
Expand Down Expand Up @@ -464,8 +465,20 @@ func (r *RabbitMQ) handleMessage(ctx context.Context, handler bindings.Handler,
r.logger.Info("Input binding channel closed")
return
}

metadata := make(map[string]string)
// Passthrough any custom metadata to the handler.
for k, v := range d.Headers {
if s, ok := v.(string); ok {
// Escape the key and value to ensure they are valid URL query parameters.
// This is necessary for them to be sent as HTTP Metadata.
metadata[url.QueryEscape(k)] = url.QueryEscape(s)
}
}

_, err := handler(ctx, &bindings.ReadResponse{
Data: d.Body,
Data: d.Body,
Metadata: metadata,
})
if err != nil {
ch.Nack(d.DeliveryTag, false, true)
Expand Down

0 comments on commit fbc55b6

Please sign in to comment.