Announcement Announcement Module
No announcement yet.
Messages processed twice Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Messages processed twice


    I'm using Channels with Queues and a default, transactional poller.

    If a message is processed in a service activator after a poll and it happens that the method that is called last very long, it could happen that a second thread polls the same message and the message is processed twice.

    How can this be avoided?

    Transactional behaviour is required in case of errors everthing should be rollbacked.

    The polled message is seen in the queue by the second thread as long as the first transaction is not beeing commited.

    I'm using JdbcChannelMessageStore with MySQL.

    br, Steve

  • #2
    Please show the exact configuration.


    • #3
      For transactions to work in Spring, everything has to happen on the same thread.

      If your poller hands off to another thread (because it has a task executor, or there is a downstream queue channel, or executor channel, for example), the poller is free to run again at the next trigger interval and the same row will be retrieved.

      Using a task executor with a poller is fine from a transaction perspective, but other handoffs are not, ever.

      As long as you don't hand off to another thread, the next poll won't happen until the current poll completes its work.

      However, if you need to use multiple threads, using a task executor, see the javadoc for JdbcChannelMessageStore.setUsingIdCache()


      • #4
        I do use multiple threads, simply because of through put. I have multiple queueing channels so there should be at least one thread per queue.

        You mean using the id cache will prevent concurrent threads from processing the same message again, because of the "not in ()" clause?


        • #5
          Yes, that's correct.