Disable and enable Cassandra, Kafka and CQRS

akka
scala

(Ashan Iroshan) #1

hi,
I’m working on microservice projects, for some projects, there is a no need for Cassandra and Kafka integration, Is there is a way Customize or build tool for generating lagom project without embedded Cassandra & Kafka.

I tried with appending below configuration to build.sbt. it gives below error.

All host(s) tried for query failed (tried: /127.0.0.1:4000 (com.datastax.driver.core.exceptions.TransportException: [/127.0.0.1:4000] Cannot connect))

com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: /127.0.0.1:4000 (com.datastax.driver.core.exceptions.TransportException: [/127.0.0.1:4000] Cannot connect

lagomCassandraEnabled in ThisBuild := false
lagomKafkaEnabled in ThisBuild := false

any suggestion to customize the project as I need ?
thanks .


(Renato) #2

Hi @Ashan,

This is probably happening because you are adding the Cassandra dependency and wiring it in your loader.

For instance, this is an extract of the hello world sample:

// in build.sbt
lazy val `hello-impl` = (project in file("hello-impl"))
  .enablePlugins(LagomScala)
  .settings(
    libraryDependencies ++= Seq(
      lagomScaladslPersistenceCassandra, // <- remove this 
      lagomScaladslKafkaBroker,  // <- remove this 
      lagomScaladslTestKit,
      macwire,
      scalaTest
    )
  )
  .settings(lagomForkedTestSettings: _*)
  .dependsOn(`hello-api`)

and this is the Application Loader

// in HelloLoader.scala
abstract class HelloApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
    with CassandraPersistenceComponents // <- remove this 
    with LagomKafkaComponents // <- remove this 
    with AhcWSComponents {

The sbt settings lagomCassandraEnabled and lagomKafkaEnabled are indeed for the internal servers and you should disable it. But you should also remove Cassandra and Kafka usage from the code, otherwise, it will we wired them and they will try to connect to the servers.

Cheers,

Renato


(Ashan Iroshan) #3

hi @renato ,
i remove the part as below.
abstract class HelloworldApplication(context: LagomApplicationContext)
extends LagomApplication(context)

with AhcWSComponents {

// Bind the service that this server provides
override lazy val lagomServer = serverForHelloworldService

// Register the JSON serializer registry
override lazy val jsonSerializerRegistry = HelloworldSerializerRegistry

// Register the hello-world persistent entity
persistentEntityRegistry.register(wire[HelloworldEntity])
}
it gives this error->
: not found: value persistentEntityRegistry
reson persistentEntityRegistry & create by ```
CassandraPersistenceComponents so removing that gives more errors .



Does `**sbt new lagom/lagom-scala.g8**` have any option to customize that ?? build the project with required component ?? 

Cheers,
Ashan

(Tim Moore) #4

@Ashan do these projects need to use the Lagom persistent entity API?

If not, you’ll need to remove all references to it:

abstract class HelloworldApplication(context: LagomApplicationContext)
  extends LagomApplication(context)
  with AhcWSComponents {

  // Bind the service that this server provides
  override lazy val lagomServer = serverForHelloworldService

  // Register the JSON serializer registry
  override lazy val jsonSerializerRegistry = HelloworldSerializerRegistry // <- remove this

  // Register the hello-world persistent entity
  persistentEntityRegistry.register(wire[HelloworldEntity]) // <- remove this
}

Plus all of the classes that use the persistence API elsewhere in the project.

If you do need the persistence API, you’ll need to decide whether to use Cassandra or a relational database as the underlying data store, and then follow all of the instructions in the documentation for configuring your choice.