diff --git a/sender.go b/sender.go index 1f9080e..f5cc845 100644 --- a/sender.go +++ b/sender.go @@ -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 { @@ -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 { @@ -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, diff --git a/sender_test.go b/sender_test.go index 21f5e37..ad06324 100644 --- a/sender_test.go +++ b/sender_test.go @@ -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) { @@ -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") @@ -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"), }