jeudi 3 novembre 2016

JMS transactional message processing pattern with async listener

I will shorty describe our system infrastructure and messages flow:

  1. There are multiple producers that enqueue messages to QUEUE

  2. There is one asynchronous listener (AUTO_ACKNOWLEDGE) that collects messages and puts them on a list.

Simplified code:

private List<Message> messages;
public void onMessage(Message message) {
      messages.add(messages)
}

  1. There is one poller that wakes up every interval, grabs all the messages so far dequeued and processes them.

Simplified code (from the listener):

   public List<Message> retrieveAndClearMessages() {
      synchronized (messages) {
         List<Message> returnList = new ArrayList<Message>(messages);
         messages.clear();
         return returnList;
      }
   }

The problem is that for the duration of the poller are the memory - which means if encounter an outage all the currently processes messages are lost. Are there any enterprise pattern that solves such problems? Maybe some backup queue or other workaround.

Aucun commentaire:

Enregistrer un commentaire