softwaremill / elasticmq

In-memory message queue with an Amazon SQS-compatible interface. Runs stand-alone or embedded.
https://softwaremill.com/open-source/
Apache License 2.0
2.55k stars 195 forks source link

Publishing messages with delay does not work as expected #882

Closed Zakharen closed 1 year ago

Zakharen commented 1 year ago

I'm using elasticmq image. Here is a part of my docker compose config:

elasticmq:
    image: softwaremill/elasticmq
    container_name: aws_sqs_mock
    ports:
      - ${AWS_SQS_PORT}
      - ${AWS_SQS_UI_PORT}
    volumes:
      - ./elasticmq.conf:/opt/elasticmq.conf
    networks:
      - paynet

here is elasticmq.conf with the following settings:

include classpath("application.conf")

node-address {
    host = aws_sqs_mock
}

queues {
    payslipPublished {
        defaultVisibilityTimeout = 30 seconds
        delay = 10 seconds
        receiveMessageWait = 0 seconds
    }
}

I was expecting to see a 10-second delay between each message I publish, but instead, I don't see any delay.

micossow commented 1 year ago

@Zakharen the delay means that the message you send can be received no sooner than 10 seconds later. See the test below as an example:

  test("should create delayed queue") {
    // Given
    val queueUrl = client
      .createQueue(new CreateQueueRequest("testQueue1").withAttributes(Map(delaySecondsAttribute -> "1").asJava))
      .getQueueUrl

    // When
    client.sendMessage(new SendMessageRequest(queueUrl, "Message 1")).getMessageId

    val m1 = receiveSingleMessage(queueUrl)
    Thread.sleep(1100)
    val m2 = receiveSingleMessage(queueUrl)
    val m3 = receiveSingleMessage(queueUrl)

    // Then
    m1 should be(None)
    m2 should be(Some("Message 1"))
    m3 should be(None)
  }