Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dblatcher/sbt aws upgrade #4296

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Global / concurrentRestrictions := Seq(
Tags.limitAll(12)
)

val awsSdkVersion = "1.12.470"
val awsSdkVersion = "1.12.755"
val elastic4sVersion = "8.3.0"
val okHttpVersion = "3.12.1"

Expand Down Expand Up @@ -88,7 +88,7 @@ lazy val commonLib = project("common-lib").settings(
"com.gu" %% "thrift-serializer" % "5.0.2",
"org.scalaz.stream" %% "scalaz-stream" % "0.8.6",
"org.im4java" % "im4java" % "1.4.0",
"com.gu" % "kinesis-logback-appender" % "1.4.2",
"com.gu" % "kinesis-logback-appender" % "1.4.4",
"net.logstash.logback" % "logstash-logback-encoder" % "5.0",
"com.typesafe.play" %% "play-logback" % "2.8.20", // needed when running the scripts
"com.typesafe.scala-logging" %% "scala-logging" % "3.9.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,38 @@ import com.amazonaws.services.sqs.AmazonSQS
import com.amazonaws.services.sqs.AmazonSQSClientBuilder
import com.amazonaws.services.sqs.model.{DeleteMessageRequest, ReceiveMessageRequest, Message => SQSMessage}

import scala.annotation.nowarn
import scala.collection.JavaConverters._

class SimpleSqsMessageConsumer (queueUrl: String, config: CommonConfig) {

lazy val client: AmazonSQS = config.withAWSCredentials(AmazonSQSClientBuilder.standard()).build()

def getNextMessage(attributeNames: String*): Option[SQSMessage] =
client.receiveMessage(
new ReceiveMessageRequest(queueUrl)
def getNextMessage(attributeNames: String*): Option[SQSMessage] = {

// TO DO - try the new methods when the IngestSqsQueue is back, getstatus works and healthcheck passes
@nowarn // withAttributeNames is deprecated, but still supported.
val request = new ReceiveMessageRequest(queueUrl)
.withWaitTimeSeconds(20) // Wait for maximum duration (20s) as per doc recommendation: http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-long-polling.html
.withMaxNumberOfMessages(1) // Pull 1 message at a time to avoid starvation
.withAttributeNames(attributeNames: _*)
).getMessages.asScala.headOption
.withAttributeNames(attributeNames:_*)

client.receiveMessage(request).getMessages.asScala.headOption
}

def deleteMessage(message: SQSMessage): Unit =
client.deleteMessage(new DeleteMessageRequest(queueUrl, message.getReceiptHandle))

def getStatus: Map[String, String] = {

println(queueUrl)

println(client.getQueueAttributes(queueUrl, List(
"ApproximateNumberOfMessagesDelayed",
"ApproximateNumberOfMessages",
"ApproximateNumberOfMessagesNotVisible"
).asJava))

client.getQueueAttributes(queueUrl, List(
"ApproximateNumberOfMessagesDelayed",
"ApproximateNumberOfMessages",
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ services:
ports:
- "9090:9000"
localstack:
image: localstack/localstack:0.12.3
image: localstack/localstack:0.12.20
platform: 'linux/x86_64'
ports:
- "4566:4566" # localstack's service proxy endpoint
Expand Down
Loading