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

Fifo delay queue is delivering messages immediately instead of delaying them #890

Closed
jcelmeta14 opened this issue Oct 26, 2023 · 3 comments · Fixed by #1009
Closed

Fifo delay queue is delivering messages immediately instead of delaying them #890

jcelmeta14 opened this issue Oct 26, 2023 · 3 comments · Fixed by #1009

Comments

@jcelmeta14
Copy link

jcelmeta14 commented Oct 26, 2023

Hello!

I have a queue configured in the .conf file as follows:

  MyQueue {
    fifo = true
    delay = 60 seconds
    defaultVisibilityTimeout = 60 seconds
    deadLettersQueue {
      name = "MyDLQueue"
      maxReceiveCount = 3
    }
  }

As you may see, the queue has a delay of 60 seconds. The queue seems to have been created correctly. I checked using the CLI:

image

The problem is that regardless of the configuration, the messages get delivered immediately. I am using serverless-framework and I have configured a function to have the queue as an event source. As soon as a message is sent to the queue, the function get triggered immediately without the delay of 60 seconds.

Am I doing something wrong?

Thank you!

@micossow
Copy link
Contributor

micossow commented Nov 2, 2023

@jcelmeta14 I can't reproduce the issue.
I'm using softwaremill/elasticmq-native:1.4.7 and the following configuration:

include classpath("application.conf")

queues {
  main {
    defaultVisibilityTimeout = 10 seconds
    delay = 2 seconds
    receiveMessageWait = 0 seconds
    deadLettersQueue {
      name = "retry"
      maxReceiveCount = 1
    }
  }
  retry {
    defaultVisibilityTimeout = 10 seconds
    delay = 2 seconds
    receiveMessageWait = 0 seconds
  }
  delayed {
    fifo = true
    delay = 10 seconds
    defaultVisibilityTimeout = 10 seconds
    deadLettersQueue {
      name = "retry"
      maxReceiveCount = 3
    }
  }
}

and this is my test code:

queue = self.sqs.get_queue_by_name(QueueName='delayed.fifo')
queue.send_message(MessageBody='some test message to be delayed', MessageGroupId='group123', MessageDeduplicationId='dedup123')
messages = queue.receive_messages()
print(messages)
time.sleep(5)
messages = queue.receive_messages()
print(messages)
time.sleep(5)
messages = queue.receive_messages()
print(messages)

and this is the output:

[]
[]
[sqs.Message(queue_url='http://localhost:9324/000000000000/delayed.fifo', receipt_handle='b5edfb66-0106-43b7-beb4-e7ab211a82f0#c732fdcd-aa1c-4d78-af5c-00a7b2878ce1')]

If you still observe the issue with the latest version, please provide an application or test reproducing it.

@jcelmeta14
Copy link
Author

Thank your for your reply! I will try to create a repo in the following days, and I will post another comment here.

@tmnsur
Copy link
Contributor

tmnsur commented Jun 5, 2024

The issue happens when the "DelaySeconds" is set to 0 within the message. If you modify your test code like this:

queue.send_message(MessageBody='some test message to be delayed', MessageGroupId='group123', MessageDeduplicationId='dedup123',DelaySeconds=0)

You would observe in src/main/scala/org/elasticmq/rest/sqs/SendMessageDirectives.scala line 131:

val delaySecondsOption = parameters.DelaySeconds match {
      case Some(v) if v < 0 || v > 900 =>
        // Messages can at most be delayed for 15 minutes
        throw SQSException.invalidParameter("DelaySeconds must be >= 0 and <= 900")
      case Some(v) if v > 0 && queueData.isFifo =>
        // FIFO queues don't support delays
        throw SQSException.invalidQueueTypeParameter(DelaySecondsParameter)
      case d => d
}

that delaySecondsOption is set as 0, and this causes nextDelivery in line 142 to be assigned to AfterMillisNextDelivery(0), and that will cause the sender to send the message immediately instead of waiting for the queue-wide DelaySeconds configuration.

I prepared this PR to fix this: #1009

micossow added a commit that referenced this issue Jun 13, 2024
micossow added a commit that referenced this issue Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants