Guillermo Garcia
Guillermo Garcia

Reputation: 77

RabbitMQ + Spring Integration. Queue size 1, only deleted when override

I would like to now if is posible to implement this idea with RabbitMQ and Spring Integration:

  1. One queue, with capatity for 1 message.
  2. The consumers will ask for this message, if it exist in the queue, it will be delivered to them, if not, they get an null or an Error.
  3. This message ( if exist in the queue ) will not be deleted for had been download, only will be deleted when the producer put another new message in the queue.

Best regards!

Upvotes: 1

Views: 148

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121177

Something like this:

@Transactional
public Message getMessageFromQueue(String queue) {
    try {
        return this.rabbitTemplate.receive(queue);
    }
    finally {
        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
    }
}

With the transaction scope we will poll the queue within transaction. With the setRollbackOnly() we rallback TX and, therefore, return the message to the queue back.

Upvotes: 1

Related Questions