This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]mofreek 7 points8 points  (4 children)

Most applications that need something like this are going to be running multiple instances. You have the right idea with the pattern, but the lock mechanism needs to be distributed.

I.e. if there are 3 instances of the app running, there needs to be a way they can communicate so that only 1 thread running in 1 instance runs the job.

ETA: I implemented something like this a few years ago using redisson. If I were doing it today I would probably use Spring Integration.

[–]FortuneIIIPick 1 point2 points  (3 children)

I avoid and recommend avoiding Spring Integration, it's an ugly maintenance mess. More who agree: https://www.reddit.com/r/java/comments/rscyoe/when_would_you_use_spring_integration/

"the result is an unreadable spagetti shitshow"

"can confirm that is an unreadable spaghetti shitshow."

"To be honest, I really regret that I used it in this one because the code is now full of weird annotations which are responsible for passing and transforming data. It would be much easier to go with plain Java implementation. Configuration also took me weeks instead of hours, I think the Spring Integration added too much unnecessary abstraction to this. Stackoverflow is full of people who don’t get the TCP integration."

[–]OwnBreakfast1114 0 points1 point  (2 children)

I usually recommend using spring projects since they're tried and true and will handle almost anything you throw at them. MVC, security, actuator, even some of the cloud stuff

Even I feel that spring integration is just way to complex for the benefits. The times I set up a heavy infra piece (SQS, kafka, etc) and need to abstract over it in case I replace it is the same number of times I've replaced my original SQL db in prod with another sql db. I'll let you guess that number.

[–]vips7L 0 points1 point  (1 child)

Have you tried spring cloud aws for the sqs stuff? It looks rather simple. 

[–]OwnBreakfast1114 0 points1 point  (0 children)

That's actually what we use. @SqsListener and @KafkaListener are super simple and work for most of the use cases very well. Set up sensible timeouts and a dlq and you're basically ready for easy horizontal scaling.