1

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!

1 Answers1

1

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.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • Give me an exception: **org.springframework.transaction.NoTransactionException: No transaction aspect-managed TransactionStatus in scope** – Guillermo Garcia Dec 14 '17 at 16:56
  • Right, you have to `@EnableTransactionManagement` in your application context, first of all: https://docs.spring.io/spring/docs/5.0.2.RELEASE/spring-framework-reference/data-access.html#transaction – Artem Bilan Dec 14 '17 at 17:00
  • Yeah next time. Thk – Guillermo Garcia Dec 18 '17 at 15:32
  • I've upvoted to your question: maybe you have already a permission to accept answers. The general problem that people with similar problem will take a look into the solution if they see an accepted answer. – Artem Bilan Dec 18 '17 at 15:50
  • Looks now at least allow me to participate in meta. I will continue participating to win more permissions. Thanks for the advice and for the upvote – Guillermo Garcia Dec 18 '17 at 16:45