Set up Akka Lease MongoDB
This guide will help you use MongoDB as a discovery mechanism for bootstrapping an Akka cluster
Step 0: Add dependency
You will need to add this to pom.xml:
<dependency>
<groupId>com.iconsolutions.ipf.core.discovery</groupId>
<artifactId>akka-lease-mongodb-plugin</artifactId>
<version>${akka-lease-mongodb-plugin.version}</version>
</dependency>
To find the latest version, you can use this Nexus query.
Step 1: Use the Lease
Creating a Lease programmatically
See the official Akka docs for more details.
LeaseProvider provider = LeaseProvider.get(system);
Lease lease = provider.getLease("<name of the lease>",
"akka.coordination.lease.mongodb",
"<owner name>");
CompletionStage<Boolean> acquired = lease.acquire();
boolean stillAcquired = lease.checkLease();
CompletionStage<Boolean> released = lease.release();
Using the lease with Akka Split Brain Resolver
To use the MongoDB lease with the Split Brain Resolver, simply add the snippet below your configuration file (application.conf).
For more information, see the official Akka docs.
akka {
cluster {
downing-provider-class = "akka.cluster.sbr.SplitBrainResolverProvider"
split-brain-resolver {
active-strategy = "lease-majority"
lease-majority {
lease-implementation = "akka.coordination.lease.mongodb"
}
}
}
}
Using the Lease with Akka Cluster Singleton
To use the MongoDB lease with the Akka Cluster Singleton, simply add the snippet below your configuration file (application.conf).
For more information, see the official Akka docs.
akka.cluster.singleton.use-lease = "akka.coordination.lease.mongodb"
Using the Lease with Akka Cluster Sharding
To use the MongoDB lease with the Akka Cluster Sharding, simply add the snippet below your configuration file (application.conf).
For more information, see the official Akka docs.
akka.cluster.sharding.use-lease = "akka.coordination.lease.mongodb"
Appendix A: Default Configuration
The table below describes the default configuration that ships with the library:
| Config key | Description | Default value |
|---|---|---|
|
The MongoDB URI to use to connect to the database. Set the value of this field if not using the plugin from within IPF or if not intending to use the same database as IPF. Honours the global |
|
|
The name of the collection that will hold lease data. |
|
|
Should Disable this if the database user is not granted the Honours the global IPF |
|
|
The commit quorum to use when creating the index for Akka Lease MongoDB. Honours the global IPF |
|
|
The grace duration to allow acquired leases before another owner can acquire them. |
|
|
The interval that a lease owner will use to refresh ownership of the lease. |
|
|
The duration after which a lease operation (acquire, release) is considered a timeout. |
|
|
Whether to enable SSL support. Setting this to Honours the global |
|
|
Type of the key store. Honours the global |
|
|
Path to the key store that holds the SSL certificate (typically a jks file). Honours the global |
|
|
Password used to access the key store. Honours the global |
|
|
Password used to access the key in the key store. Honours the global |
|
|
Type of the trust store. Honours the global |
|
|
Path to the trust store that holds the SSL certificate. Honours the global |
|
|
Password used to access the trust store. Honours the global |
|