Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove redundant modules #10

Merged
merged 3 commits into from
Dec 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@


# Aecor
### Scalable, type safe CQRS DDD framework
### Typeful runtime for eventsourced behaviors

Aecor is an opinionated framework for building scalable, distributed CQRS DDD services written in Scala. It uses [Akka](https://github.com/akka/akka) as a runtime for pure functional behaviors (`Any => Unit`, not even once) and clustering.
Aecor is an opinionated library to help building scalable, distributed eventsourced services written in Scala. It uses [Akka](https://github.com/akka/akka) for distribution and fault tolerance.
With the help of [Cats](https://github.com/typelevel/cats/) and [Shapeless](https://github.com/milessabin/shapeless) to reach type safety.

Aecor works on Scala 2.11 with Java 8.
Aecor works on Scala 2.11 and 2.12 with Java 8.

The name `Aecor` (_lat. ocean_) is inspired by a vision of modern distributed applications, as an ocean of messages with pure behaviors floating in it.



Main goals:
1. Type safety
2. Pure behaviors
3. Easy to implement Aggregate Root behaviors
4. A simple DSL to describe Business Processes
36 changes: 0 additions & 36 deletions api/src/main/scala/aecor/api/Router.scala

This file was deleted.

31 changes: 3 additions & 28 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ lazy val scalaTestVersion = "3.0.1"
lazy val scalaCheckShapelessVersion = "1.1.4"
lazy val shapelessVersion = "2.3.2"
lazy val kindProjectorVersion = "0.9.3"
lazy val simulacrumVersion = "0.10.0"
lazy val paradiseVersion = "2.1.0"

lazy val commonSettings = Seq(
Expand All @@ -32,7 +31,6 @@ lazy val commonSettings = Seq(
Resolver.bintrayRepo("projectseptemberinc", "maven")
),
libraryDependencies ++= Seq(
"com.github.mpilquist" %% "simulacrum" % simulacrumVersion,
compilerPlugin(
"org.spire-math" %% "kind-projector" % kindProjectorVersion),
compilerPlugin(
Expand All @@ -50,39 +48,22 @@ lazy val aecor = project
.settings(moduleName := "aecor")
.settings(aecorSettings)
.settings(noPublishSettings)
.aggregate(core, api, example, schedule, tests, bench)
.aggregate(core, example, schedule, tests)
.dependsOn(core,
api,
example % "compile-internal",
tests % "test-internal -> test",
bench % "compile-internal;test-internal -> test")
tests % "test-internal -> test")

lazy val core = project
.settings(moduleName := "aecor-core")
.settings(aecorSettings)
.settings(coreSettings)
.settings(
libraryDependencies += "org.scalacheck" %% "scalacheck" % scalaCheckVersion % "test")

lazy val api = project
.dependsOn(core)
.settings(moduleName := "aecor-api")
.settings(aecorSettings)
.settings(apiSettings)

lazy val schedule = project
.dependsOn(core)
.settings(moduleName := "aecor-schedule")
.settings(aecorSettings)
.settings(scheduleSettings)

lazy val bench = project
.dependsOn(core, example)
.settings(moduleName := "aecor-bench")
.settings(aecorSettings)
.settings(noPublishSettings)
.enablePlugins(JmhPlugin)

lazy val tests = project
.dependsOn(core, example, schedule)
.settings(moduleName := "aecor-tests")
Expand All @@ -91,7 +72,7 @@ lazy val tests = project
.settings(testingSettings)

lazy val example = project
.dependsOn(core, api, schedule)
.dependsOn(core, schedule)
.settings(moduleName := "aecor-example")
.settings(aecorSettings)
.settings(noPublishSettings)
Expand All @@ -111,12 +92,6 @@ lazy val coreSettings = Seq(
)
)

lazy val apiSettings = Seq(
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-http" % akkaHttpVersion
)
)

lazy val scheduleSettings = commonProtobufSettings

lazy val exampleSettings = Seq(
Expand Down
5 changes: 3 additions & 2 deletions example/src/main/scala/aecor/example/AccountAPI.scala
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package aecor.example

import aecor.api.Router
import aecor.core.aggregate.AggregateRegionRef
import aecor.example.domain._
import akka.Done
import akka.http.scaladsl.model.StatusCodes
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server.Route
import de.heikoseeberger.akkahttpcirce.CirceSupport._
import io.circe.generic.JsonCodec
import cats.implicits._

import scala.concurrent.{ExecutionContext, Future}

class AccountAPI(account: AggregateRegionRef[AccountAggregateOp]) {
Expand Down Expand Up @@ -47,7 +48,7 @@ object AccountAPI {
case class OpenAccount(accountId: String) extends DTO
}

implicit val router: Router[AccountAPI] = Router.instance { api =>
val route: AccountAPI => Route = { api =>
path("accounts") {
extractExecutionContext { implicit ec =>
post {
Expand Down
74 changes: 46 additions & 28 deletions example/src/main/scala/aecor/example/AppActor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package aecor.example

import java.time.Clock

import aecor.api.Router.ops._
import aecor.core.aggregate._
import aecor.core.streaming._
import aecor.example.domain.CardAuthorization.CardAuthorizationCreated
Expand Down Expand Up @@ -37,61 +36,80 @@ class AppActor extends Actor with ActorLogging {

val queries = new CassandraOffsetStore.Queries(system)

val sessionWrapper = DefaultJournalCassandraSession(system, "app-session", queries.init)
val sessionWrapper =
DefaultJournalCassandraSession(system, "app-session", queries.init)

val offsetStore = new CassandraOffsetStore(sessionWrapper, queries)

val journal = AggregateJournal(system, offsetStore)

val authorizationRegion =
AggregateSharding(system).start[CardAuthorization.Command](CardAuthorization())
AggregateSharding(system)
.start[CardAuthorization.Command](CardAuthorization())

val accountRegion =
AggregateSharding(system).start[AccountAggregateOp](AccountAggregate(Clock.systemUTC()))
AggregateSharding(system)
.start[AccountAggregateOp](AccountAggregate(Clock.systemUTC()))

val scheduleEntityName = "Schedule3"

val schedule: Schedule = Schedule(system, scheduleEntityName, 1.day, 10.seconds, offsetStore)

val schedule: Schedule =
Schedule(system, scheduleEntityName, 1.day, 10.seconds, offsetStore)

val cardAuthorizationEventStream =
new DefaultEventStream(system, journal.committableEventSourceFor[CardAuthorization]("CardAuthorization-API").map(_.value))


val authorizePaymentAPI = new AuthorizePaymentAPI(authorizationRegion, cardAuthorizationEventStream, Logging(system, classOf[AuthorizePaymentAPI]))
new DefaultEventStream(
system,
journal
.committableEventSourceFor[CardAuthorization]("CardAuthorization-API")
.map(_.value))

val authorizePaymentAPI = new AuthorizePaymentAPI(
authorizationRegion,
cardAuthorizationEventStream,
Logging(system, classOf[AuthorizePaymentAPI]))
val accountApi = new AccountAPI(accountRegion)

val accountInterpreter = new (AccountAggregateOp ~> Future) {
override def apply[A](fa: AccountAggregateOp[A]): Future[A] = accountRegion.ask(fa)
}
val cardAuthorizationInterpreter = new (CardAuthorization.Command ~> Future) {
override def apply[A](fa: CardAuthorization.Command[A]): Future[A] = authorizationRegion.ask(fa)
override def apply[A](fa: AccountAggregateOp[A]): Future[A] =
accountRegion.ask(fa)
}
val cardAuthorizationInterpreter =
new (CardAuthorization.Command ~> Future) {
override def apply[A](fa: CardAuthorization.Command[A]): Future[A] =
authorizationRegion.ask(fa)
}

import freek._

val interpreter = accountInterpreter :&: cardAuthorizationInterpreter

journal
.committableEventSourceFor[CardAuthorization]("processing")
.collect {
case CommittableJournalEntry(offset, _, _, e: CardAuthorizationCreated) =>
(e, offset)
}
.via(AuthorizationProcess.flow(8, interpreter))
.mapAsync(1)(_.commitScaladsl())
.runWith(Sink.ignore)

.committableEventSourceFor[CardAuthorization]("processing")
.collect {
case CommittableJournalEntry(offset,
_,
_,
e: CardAuthorizationCreated) =>
(e, offset)
}
.via(AuthorizationProcess.flow(8, interpreter))
.mapAsync(1)(_.commitScaladsl())
.runWith(Sink.ignore)

val route = path("check") {
get {
complete(StatusCodes.OK)
}
} ~
authorizePaymentAPI.route ~
accountApi.route

Http().bindAndHandle(route, config.getString("http.interface"), config.getInt("http.port"))
.onComplete { result => log.info("Bind result [{}]", result) }
AuthorizePaymentAPI.route(authorizePaymentAPI) ~
AccountAPI.route(accountApi)

Http()
.bindAndHandle(route,
config.getString("http.interface"),
config.getInt("http.port"))
.onComplete { result =>
log.info("Bind result [{}]", result)
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package aecor.example

import aecor.api.Router
import aecor.core.aggregate.AggregateRegionRef
import aecor.example.AuthorizePaymentAPI._
import aecor.example.domain.CardAuthorization.{
Expand All @@ -12,7 +11,7 @@ import aecor.example.domain._
import akka.event.LoggingAdapter
import akka.http.scaladsl.model.StatusCodes
import akka.http.scaladsl.server.Directives._

import akka.http.scaladsl.server.Route
import de.heikoseeberger.akkahttpcirce.CirceSupport._
import io.circe.generic.JsonCodec

Expand Down Expand Up @@ -92,7 +91,7 @@ object AuthorizePaymentAPI {

}

implicit val router: Router[AuthorizePaymentAPI] = Router.instance { api =>
val route: AuthorizePaymentAPI => Route = { api =>
path("authorization") {
extractExecutionContext { implicit ec =>
post {
Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ addSbtPlugin("com.thesamet" % "sbt-protoc" % "0.99.1")
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.2.0-M7")
addSbtPlugin("com.eed3si9n" % "sbt-unidoc" % "0.3.2")
addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.3")
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.2.6")

addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "0.8.5")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "1.1")
Expand Down