I am using lagom for publishing to kafka. I am using JDBC for for persistence. I have deployed two instances for availability. My issue now is that every time a request comes both instances are publishing to kafka. Is there any configuration that i can set in application.conf which will prevents this.
Below is my loader and application.conf file
class TweedLoader extends LagomApplicationLoader {
override def load(context: LagomApplicationContext): LagomApplication =
new TweedApplication(context) with ConfigurationServiceLocatorComponents
override def describeService = Some(readDescriptor[TweedService])
}
abstract class TweedApplication(context: LagomApplicationContext)
extends LagomApplication(context)
with JdbcPersistenceComponents
with HikariCPComponents
with LagomKafkaComponents
with AhcWSComponents {
override lazy val lagomServer: LagomServer = serverFor[TweedService](wire[TweedServiceImpl])
lazy val appsImpl: AppsImpl = wire[AppsImpl]
override def jsonSerializerRegistry: JsonSerializerRegistry = NotificationSerializerRegistry
val cs = clusterSharding.init(
Entity(NotificationState.typeKey)(
entityContext => NotificationBehavior.create(entityContext)
)
)
}
the problem is you are deploying two isolated processes. You should tune your processes so they connected to each other and created an Akka Cluster. Since each process doesn’t’ know the other one exists each process will run all the workers necessary for each projection (e.g. a TopicProducer) causing duplicates. The first thing you must fix is this setting:
lagom.cluster.join-self should only be used in local environments (development) where you are running a single-node cluster.
Note that running multiple, single-node clusters in production also has the potential to corrupt your Persistent Entities as you may end up with multiple copies of the same data in memory.
I strongly suggest you fix the cluster as soon as possible.
I have changed my config to form akka cluster using akka-dns. i am facing a problem in bringing up my application. can you please have a look. Here is my updated loader and conf file