Set up Cluster Bootstrap with MongoDB discovery
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-discovery-mongodb-plugin</artifactId>
</dependency>
To find the latest version, you can use this Nexus query.
Step 1: Enable Akka Cluster Bootstrap and Use MongoDB
Add this snippet to your configuration (application.conf):
akka {
extensions = ["akka.management.cluster.bootstrap.ClusterBootstrap"]
discovery {
method = akka-mongodb
akka-mongodb.uri = ${ipf.mongodb.url} # or use an actual MongoDB URI if not using this with IPF
}
management.cluster.bootstrap {
contact-point.filter-on-fallback-port=false
}
}
Step 2: Verify
When starting up your application, you should check that indexes are created and that the service registers itself.
Look for these lines in the log:
[INFO] [04/26/2023 20:43:55.668] Ensured indexes on Akka Discovery MongoDB ([akka-discovery-mongodb-1])
[INFO] [04/26/2023 20:43:55.663] Registered self with service name 8cc4d63b-09c8-4fca-9668-b11e6d00e75a and host:port 127.0.1.1:8558: AcknowledgedUpdateResult{matchedCount=0, modifiedCount=0, upsertedId=BsonObjectId{value=64497efb0b510545dbb89377}}
Note that both of these pieces of functionality can be disabled. See below.
You should now also be able to navigate to the Akka Management HTTP service (the default being 127.0.1.1:8558) and observe that all nodes of the same type and that are using the same discovery method should be in a cluster together.
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 to store discovery data into |
|
|
Should this node register itself in the database? |
|
|
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 Discovery MongoDB. Honours the global IPF |
|
|
Should the Updater run? |
|
|
Initial delay before the Updater starts updating its entry’s |
30 seconds |
|
How often to update the |
30 seconds |
|
The |
30 minutes |
|
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 |
|
Note that there is also general Akka Cluster Bootstrap config that you might wish to tweak. The general Akka Cluster Bootstrap documentation can be found here.