I am new to Spring AMQP. I am having an application which is a producer sending messages to the other application which is a consumer.
Once the consumer receives the message, we will do validation of the data.
If the data is proper we have to ACK and message should be removed from the Queue. If the data is improper we have to NACK(Negative Acknowledge) the data so that it will be re-queued in RabbitMQ.
I came across
**factory.setDefaultRequeueRejected(false);**
( It will not requeue the message at all)
**factory.setDefaultRequeueRejected(true);**
( It will requeue the message when exception occurs)
But my case i will acknowledge the message based on validation. Then it should remove the message. If NACK then requeue the message.
I have read in RabbitMQ website
The AMQP specification defines the basic.reject method that allows clients to reject individual, delivered messages, instructing the broker to either discard them or requeue them
How to achieve the above scenario? Please provide me some examples.
I tried a small Program
logger.info("Job Queue Handler::::::::::" + new Date());
try {
}catch(Exception e){
logger.info("Activity Object Not Found Exception so message should be Re-queued the Message::::::::::::::");
}
factory.setErrorHandler(new ConditionalRejectingErrorHandler(cause ->{
return cause instanceof XMLException;
}));
Message is not re queuing for different exception factory.setDefaultRequeueRejected(true)
09:46:38,854 ERROR [stderr] (SimpleAsyncTaskExecutor-1) org.activiti.engine.ActivitiObjectNotFoundException: no processes deployed with key 'WF89012'
09:46:39,102 INFO [com.example.bip.rabbitmq.handler.ErrorQueueHandler] (SimpleAsyncTaskExecutor-1) Received from Error Queue: {ERROR=Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction marked as rollbackOnly}