Reputation: 1
I use JBoss EAP 7.4 with EJB 3.2. I want to create a method that will be called exactly once (regardless of number of nodes) in a clustered environment on server startup.
I have Startup
class that looks like below. The run()
method internally sends some events on Kafka topic. In current solution this method is executed once per node. So when three nodes are active it gets called three times instead of once.
@Startup
@Singleton
@Clustered
public class Startup {
@Inject
private TaskRunner taskRunner;
@PostConstruct
private void init() {
taskRunner.run();
}
}
I tried to use @ClusteredSingleton but unfortunately according to documentation it can only be used on MDB classes so it's not applicable for this case.
I also found this solution on redhat site: https://access.redhat.com/documentation/en-us/jboss_enterprise_application_platform/6/html/development_guide/implement_an_ha_singleton. However it is for version 6 of JBoss. Also this solution seems way to complex for what I try to achieve and I feel like I'm missing something.
Any help would be greatly appreciated.
Upvotes: 0
Views: 32