Skip to content

Commit

Permalink
Merge pull request #7 from tomcyr/feature/add-priority-to-amqp-message
Browse files Browse the repository at this point in the history
Add priority to amqp publishing
  • Loading branch information
RiiD authored May 29, 2023
2 parents ac184f2 + fb291a6 commit ef642d5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
9 changes: 7 additions & 2 deletions sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package messenger_amqp
import (
"context"
"errors"
"strconv"
"time"

"github.com/riid/messenger"
"github.com/riid/messenger/envelope"
"github.com/streadway/amqp"
"strconv"
"time"
)

type PublishArgs struct {
Expand Down Expand Up @@ -95,6 +96,9 @@ func createAMQPMessageFromEnvelope(e messenger.Envelope) (amqp.Publishing, error
messageType := envelope.MessageType(e)
e = envelope.WithoutMessageType(e)

priority := uint8(envelope.Priority(e))
e = envelope.WithoutPriority(e)

envelopeHeaders := e.Headers()
headers := make(amqp.Table, len(envelopeHeaders))
for name, hh := range envelopeHeaders {
Expand All @@ -109,6 +113,7 @@ func createAMQPMessageFromEnvelope(e messenger.Envelope) (amqp.Publishing, error
return amqp.Publishing{
Headers: headers,
ContentType: contentType,
Priority: priority,
CorrelationId: correlationID,
ReplyTo: replyTo,
Expiration: expirationStr,
Expand Down
7 changes: 5 additions & 2 deletions sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package messenger_amqp
import (
"context"
"errors"
"testing"
"time"

"github.com/riid/messenger"
"github.com/riid/messenger/envelope"
"github.com/streadway/amqp"
"github.com/stretchr/testify/assert"
"testing"
"time"
)

func TestSender_Send_given_valid_amqp_channel_called_with_envelope_should_serialize_it_and_publish_to_channel(t *testing.T) {
Expand All @@ -24,6 +25,7 @@ func TestSender_Send_given_valid_amqp_channel_called_with_envelope_should_serial
e = envelope.WithMessageType(e, "test-message-type")
e = envelope.WithUserID(e, "test-user-id")
e = envelope.WithAppID(e, "test-app-id")
e = envelope.WithPriority(e, 10)
e = envelope.WithHeader(e, "x-custom-header", "test value")
e = WithRoutingKey(e, "test-routing-key")

Expand All @@ -40,6 +42,7 @@ func TestSender_Send_given_valid_amqp_channel_called_with_envelope_should_serial
Type: "test-message-type",
UserId: "test-user-id",
AppId: "test-app-id",
Priority: uint8(10),
Body: []byte("test message"),
}

Expand Down

0 comments on commit ef642d5

Please sign in to comment.