Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Creating a list for the clustered environment  RSS feed

Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my application there is a list publisherPostListenerList which receives the real time user posts from the RabbitMQ queue to be sent to the subscribers/consumers. The list is a property of ApplicationListener class which listens to the events of the pubsub queue. The below controller method fetches the list elements via getter method & based on a logic pushes the posts to the subscribers.

The flow is as follows

User writes a post -> Post gets into DB + Queue -> Message from Queue is added in a list which is publisherPostListenerListto be pushed to the subscribers of the user.

As we can see the publisherPostListenerList is a common list for n concurrent requests due to ApplicationListener being a singleton. For a single instance the setup works fine but will fail in a clustered environment as each node will have its own individual publisherPostListenerList list.

How do I deal with this situation? I can't make ApplicationListener class stateless I need the list to store the post elements received from the queue. Do I put the list in a distributed in memory cache? Or there is any other conventional way?

Controller method for pushing the message to the subscriber

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!