All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.elasticmq.rest.sqs.SendMessageBatchDirectives.scala Maven / Gradle / Ivy

The newest version!
package org.elasticmq.rest.sqs

import Constants._
import akka.http.scaladsl.server.Route
import org.elasticmq.rest.sqs.directives.ElasticMQDirectives

trait SendMessageBatchDirectives {
  this: ElasticMQDirectives with SendMessageDirectives with BatchRequestsModule =>
  val SendMessageBatchPrefix = "SendMessageBatchRequestEntry"

  def sendMessageBatch(p: AnyParams): Route = {
    p.action("SendMessageBatch") {
      queueActorAndDataFromRequest(p) { (queueActor, queueData) =>
        verifyMessagesNotTooLong(p)

        val resultsFuture = batchRequest(SendMessageBatchPrefix, p) { (messageData, id, index) =>
          val message = createMessage(messageData, queueData, index)

          doSendMessage(queueActor, message).map {
            case (message, digest, messageAttributeDigest) =>
              
                {id}
                {messageAttributeDigest.map(d => {d}).getOrElse(())}
                {digest}
                {message.id.id}
              
          }
        }

        resultsFuture.map { results =>
          respondWith {
            
              
                {results}
              
              
                {EmptyRequestId}
              
            
          }
        }
      }
    }
  }

  def verifyMessagesNotTooLong(parameters: Map[String, String]): Unit = {
    val messageLengths = for {
      parameterMap <- batchParametersMap(SendMessageBatchPrefix, parameters)
    } yield {
      parameterMap(MessageBodyParameter).length
    }

    verifyMessageNotTooLong(messageLengths.sum)
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy