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.51k stars 194 forks source link

ChangeMessageVisibility should make long-polling return message earlier #81

Closed sindremehus closed 7 years ago

sindremehus commented 7 years ago

First of all - thanks a lot for making elasticmq! We use it extensively for unit testing in my current project.

I have encountered a problem where the behaviour in elasticmq differs from AWS SQS. If the message visibility is changed (by calling changeMessageVisibility()) while another thread is doing a long-poll with receiveMessage(), the receiveMessage() will not return the message when it becomes visible, but rather when the long-polling wait time is expired.

The following Java code illustrates the problem:

        AmazonSQS sqsClient = ...;
        String queueUrl = sqsClient.createQueue("sindre-test").getQueueUrl();

        Runnable runnable = () -> {
            ReceiveMessageResult receiveMessageResult = sqsClient.receiveMessage(new ReceiveMessageRequest(queueUrl).withWaitTimeSeconds(10));
            LOG.info("Got " + receiveMessageResult.getMessages().size() + " message(s).");
            receiptHandle = receiveMessageResult.getMessages().get(0).getReceiptHandle();

            receiveMessageResult = sqsClient.receiveMessage(new ReceiveMessageRequest(queueUrl).withWaitTimeSeconds(10));
            LOG.info("Got " + receiveMessageResult.getMessages().size() + " message(s).");
        };
        new Thread(runnable).start();

        Thread.sleep(3000);
        LOG.info("Sending message");
        sqsClient.sendMessage(queueUrl, "payload");
        Thread.sleep(2000);

        LOG.info("Changing message visibility");
        sqsClient.changeMessageVisibility(queueUrl, receiptHandle, 2);
        Thread.sleep(20000);

When using AWS SQS, the second long poll returns once the message becomes visible, but with elasticmq it returns after 10 seconds.

Hope this is understandable and that you will look into it.

Thanks! Sindre

sindremehus commented 7 years ago

I'm using version 0.10.0, by the way.

adamw commented 7 years ago

Can you try 0.10.1?

adamw commented 7 years ago

Thanks for the report, btw :)

sindremehus commented 7 years ago

Adam, thanks for the quick response. Yes, this works fine in 0.10.1.