1

I successfully compiled the code example from http://www.lagomframework.com/documentation/1.0.x/ReadSide.html

It's about the read-side of the CQRS schema.

There is only problem: it doesn't run.

Looks like configuration problem... and the official documentation of Lagom at this point is very incomplete.

The error says:

java.util.concurrent.CompletionException: java.util.concurrent.ExecutionException: com.datastax.driver.core.exceptions.InvalidQueryException: unconfigured table postsummary

Alright, there's a line in the code that does cassandra query, selecting & inserting from & to a table named postsummary.

I thought the tables are auto-created by default. Anyway, in doubt, I simply added this line to my application.conf:

cassandra-journal.keyspace-autocreate = true
cassandra-journal.tables-autocreate = true

Still..., no luck, same error after restarting.

Maybe it has something to do with another error during startup, that says:

[warn] a.p.c.j.CassandraJournal - Failed to connect to Cassandra and initialize. It will be retried on demand. Caused by: ServiceLocator is not bound

I thought... alright, maybe it's trying to contact 9042 (default cassandra port), while lagom by default starts embedded cassandra at 4000.

So I tried adding these lines in application.conf:

cassandra-journal.contact-points = ["127.0.0.1"]
cassandra-journal.port = 4000
lagom.persistence.read-side.cassandra.contact-points = ["127.0.0.1"]
lagom.persistence.read-side.cassandra.port = 4000

Still..., no luck, same error.

Can anyone help me solve it. I need to get this example running, crucial part of CQRS study using lagom.

Some ref.: https://github.com/lagom/lagom/blob/master/persistence/src/main/resources/reference.conf

Here are some screenshots:

enter image description here

enter image description here


Btw, I solved it by creating the tables inside the code, calling this method from the prepare method of the event processor:

private CompletionStage<Done> prepareTables(CassandraSession session) {
  CompletionStage<Done> preparePostSummary = session.executeCreateTable(
    "CREATE TABLE IF NOT EXISTS postsummary ("
    + "partition bigint, id text, title text, "
    + "PRIMARY KEY (id))"
  ).whenComplete((ok, err) -> {
    if (err != null) {
      System.out.println("Failed to create postsummary table, due to: " + err.getMessage());
    }
  });

  CompletionStage<Done> prepareBlogEventOffset = session.executeCreateTable(
    "CREATE TABLE IF NOT EXISTS blogevent_offset ("
    + "partition bigint, offset uuid, "
    + "PRIMARY KEY (offset))"
  ).whenComplete((ok, err) -> {
    if (err != null) {
      System.out.println("Failed to create blogevent_offset table, due to: " + err.getMessage());
    }
  });

  return preparePostSummary.thenCompose(a -> prepareBlogEventOffset);
}

Thanks!, Raka

Cokorda Raka
  • 4,375
  • 6
  • 36
  • 54

1 Answers1

1

I have a working example here. Even if it does not use auto created tables : https://github.com/lagom/activator-lagom-cargotracker/blob/master/registration-impl/src/main/java/sample/cargotracker/registration/impl/CargoEventProcessor.java

Markus Eisele
  • 712
  • 4
  • 9
  • HI Marcus, thanks for pointing out. But like the two other examples (lagom-java & lagom-chirper) it's still using M1 version of lagom. And since M2 the ServiceCall definition has been changed (2 type parameters instead of 3). The lagom doc website is referring to M2... I hope you guys have a chance to sync the examples to M2 not to confuse readers. – Cokorda Raka May 15 '16 at 16:59
  • Hi Markus: I have another question about Lagom, please help. Thanks a heap! : http://stackoverflow.com/questions/37241401/lagom-framework-streamed-response-pathcall-descriptor-creator-instead-of – Cokorda Raka May 15 '16 at 17:25