WASEEM
WASEEM

Reputation: 217

How to run scheduler in cluster environment using spring

Email is triggering one time in single node server. But it is duplicating multiple Email's in clustering environment because multiple nodes server are running. But need to get single Email in clustering environment. How to handle that in spring application.

@Service
public class MailController {

    @Scheduled(cron = "0 20 20 * * *")
    @Transactional("myTraxManger")
    public void sendmail() {
        System.out.println("Sending maill to User");
    }

}

Upvotes: 0

Views: 1905

Answers (2)

Clive
Clive

Reputation: 55

I suggest using a framework such as Spring Cloud or Hazelcast to manage your cluster state and then you can decide to run scheduled tasks on only one of the nodes such as the leader with Leadership election.

Upvotes: 1

Bassem Reda Zohdy
Bassem Reda Zohdy

Reputation: 12942

I would suggest to have queuing solution like ActiveMQ or kafka and all clusters are going to put messages to queue and async mail sender process to get from that queue and send email.

Upvotes: 0

Related Questions