elasticmq icon indicating copy to clipboard operation
elasticmq copied to clipboard

Unable to acknowledge message in custom error handler

Open sumitsabhnani opened this issue 8 years ago • 4 comments

Hello.

I have created a custom error handler to handle application exceptions and do logging or retrying based on the Exception type. Below is the sample code what m trying to do:

//QueueMessageListener.java `public void onMessage(Message message) { try { TextMessage textMessage = (TextMessage) message;

        Event event = toEvent(textMessage);

        processor.process(event);
    } catch (Exception ex) {
        throw new CustomException(message, ex);
    }

}`

//` public class CustomErrorHandler implements ErrorHandler {

@Override
public void handleError(Throwable throwable) {
    if(throwable instanceof CustomException) {
        CustomException exception = (CustomException) throwable;
        Message message = exception.getSqsMessage();
        message.acknowledge();
    }

} }`

//Configuration DefaultMessageListenerContainer dmlc = new DefaultMessageListenerContainer(); dmlc.setConcurrency("1-5"); dmlc.setConnectionFactory(sqsConnectionFactory); dmlc.setDestinationName(queueProperties.getName()); dmlc.setSessionAcknowledgeMode(Session.CLIENT_ACKNOWLEDGE); dmlc.setMessageListener(messageListener); dmlc.setErrorHandler(customErrorHandler);

Issue here is, when the custom error handler executes handleError it does not acknowledges the message and message stay in the queue forever... I can see below message in logs WARN com.amazon.sqs.javamessaging.acknowledge.RangedAcknowledger - SQSMessageID: 46a04726-8e09-48ce-947f-95cb2e8ae9a0 with SQSMessageReceiptHandle: 46a04726-8e09-48ce-947f-95cb2e8ae9a0#44b60e0f-2e02-42f1-a5c1-1db9a458b022 does not exist.

m I missing some configuration?

Regards, Sumit

sumitsabhnani avatar Oct 25 '17 12:10 sumitsabhnani

I haven't used the JMS interface so hard to say. Maybe you could create a small project which replicates the error?

adamw avatar Nov 03 '17 17:11 adamw

Im currently having a look into this because I am experiencing some problems like this. With a little bit of investigation it uses the batchdelete operations. Is this supported in elasticMq ?

KevinJCross avatar Nov 28 '17 14:11 KevinJCross

@adamw sorry i missed the comment.... will try to build something and share.... @kevlarC i didn't get your question.. if you are talking about custom error handler thn yes it is supported and works fine (except message acknowledgement)... i m not very sure if exception handler should even be aware about message but since i came across this issue so thought of posting it....

sumitsabhnani avatar Nov 28 '17 15:11 sumitsabhnani

hi, It turns out there is something going on but Im not sure exactly what it is. When we are running using the normal java jms from the aws SDK we quite often get

10:23:45.151 [DefaultMessageListenerContainer-3] WARN  c.a.s.j.a.RangedAcknowledger - SQSMessageID: 6a2c160c-03da-40e0-aae1-acb83b911f3b with SQSMessageReceiptHandle: 6a2c160c-03da-40e0-aae1-acb83b911f3b#1cabf4af-65cc-4d6b-95fe-b3c65ac64c87 does not exist.

Output from the sdk ... Since there is very little in the form of introspection for the queues I dont really know if they have or have not been removed from the queue. It uses a batch delete with the last receipt.

None the less I've got a workaround for our tests that we are using although I not sure its this exact problem. I investigated it while trying to find a fix and it seems there is something not quite right here.

I think we could make a test that sends a large amount of messages and links into the aws jms to receive and acknowledges them as quickly as possible then this warning should appear.

It may even be an incorrect log from the SDK.... although you would hope not.

ghost avatar Nov 29 '17 12:11 ghost