Coder Social home page Coder Social logo

java-rabbit-concurrency's Introduction

Project README

Introduction

After encountering an error where different queues/messages were processing and changing the same row/table simultaneously or with open transactions, it was suggested by Pavel that this could be the cause. Based on this report and the errors on Sentry, I created an isolated scenario to test the problem.

Solution Base

The solution includes the following components:

  • Docker Compose:
    • RabbitMQ
    • Rabbit queue seeder, creating 500 persons in an H2 database.
  • Controller Endpoint:
    • To replicate the problem, accessible at ("/replicateProblem").

Executing the Application

Follow these steps to execute the project:

  1. Start Docker Compose:

    • Run the following command to build and start the containers in detached mode:
      docker-compose up --build -d
  2. Execute the Application:

    • Start your Spring Boot application.
  3. Replicate the Problem:

    • Access the endpoint to replicate the problem:
      http://localhost:8080/replicateProblem
      
  4. View Row Changes:

    • Check the table in the H2 database. The specific row should have version: 10, indicating 10 saves/updates (Total number of threads executed in the method)

Explanation of the Problem

What is Happening?

Different threads or pods are updating the same rows simultaneously. In a scenario where different queues and messages end up updating a specific row in a table in a multi-pod/thread environment, this can cause an error similar to:

What is the Solution?

The @Retryable annotation in Java, particularly with Spring, indicates that a method should be re-executed if specific exceptions occur. The retryFor property specifies which exceptions trigger retries, such as OptimisticLockException. The maxAttempts property defines the maximum number of retries, enhancing the application's resilience by handling transient failures gracefully.

java-rabbit-concurrency's People

Contributors

jorgermduarte avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.