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

Splits core into Server and Client submodules #113

Merged
merged 4 commits into from
Jan 10, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 23 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,41 @@ Also known as [frees-rpc], it brings the ability to combine [RPC] protocols, ser

`frees-rpc` is cross-built for Scala `2.11.x` and `2.12.x`:

Add the following dependency to your project's build file.

[comment]: # (Start Replace)

```scala
libraryDependencies += "io.frees" %% "frees-rpc-core" % "0.6.1"
// required for the RPC Server:
libraryDependencies += "io.frees" %% "frees-rpc-server" % "0.6.1"

// required for the RPC Client/s, using either Netty or OkHttp as transport layer:
libraryDependencies += "io.frees" %% "frees-rpc-client-netty" % "0.6.1"
// or:
libraryDependencies += "io.frees" %% "frees-rpc-client-okhttp" % "0.6.1"

// optional - for both server and client configuration.
libraryDependencies += "io.frees" %% "frees-rpc-config" % "0.6.1"
```

[comment]: # (End Replace)

Optionally, [frees-rpc] provides some configuration helpers using [frees-config] to load the application configuration values.
Note: `frees-rpc-config` provides some configuration helpers using [frees-config] to load the application configuration values.

[comment]: # (Start Replace)
## Documentation

```scala
libraryDependencies += "io.frees" %% "frees-rpc-config" % "0.6.1"
```
The full documentation is available at [frees-rpc](http://frees.io/docs/rpc) site.

[comment]: # (End Replace)
## Sbt Modules

`frees-rpc` code is placed in different sbt modules:

The full documentation is available at [frees-rpc](http://frees.io/docs/rpc) site.
* `frees-rpc-common`: contains the protocol types, with the minimum set of dependencies.
* `frees-rpc-async`: contains just the async implicit instances (NTs between effect/async types).
* `frees-rpc-internal` where the macros are placed.
* `frees-rpc-client-core`: algebra and code related to the RPC clients.
* `frees-rpc-client-netty`: it doesn't add any additional code, just a transport layer provider based on `grpc-netty`.
* `frees-rpc-client-okhttp`: similar to the `Netty` one, it doesn't add any additional code, just a transport layer provider based on `grpc-okhttp`.
* `frees-rpc-server`: algebra and code related to the RPC server.
* `frees-rpc-config`: helpers to be able to load the client and the server configuration.

## Demo

Expand Down
56 changes: 49 additions & 7 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,52 @@ lazy val common = project
.settings(moduleName := "frees-rpc-common")
.settings(commonSettings)

lazy val core = project
.in(file("modules/core"))
.dependsOn(common)
.settings(moduleName := "frees-rpc-core")
.settings(coreSettings)
lazy val async = project
.in(file("modules/async"))
.dependsOn(common % "test->test")
.settings(moduleName := "frees-rpc-async")
.settings(asyncSettings)

lazy val internal = project
.in(file("modules/internal"))
.dependsOn(common % "compile->compile;test->test")
.settings(moduleName := "frees-rpc-internal")
.settings(internalSettings)

lazy val client = project
.in(file("modules/client"))
.dependsOn(common % "compile->compile;test->test")
.dependsOn(internal)
.dependsOn(async)
.settings(moduleName := "frees-rpc-client-core")
.settings(clientCoreSettings)

lazy val `client-netty` = project
.in(file("modules/client-netty"))
.dependsOn(client % "compile->compile;test->test")
.settings(moduleName := "frees-rpc-client-netty")
.settings(clientNettySettings)

lazy val `client-okhttp` = project
.in(file("modules/client-okhttp"))
.dependsOn(client % "compile->compile;test->test")
.settings(moduleName := "frees-rpc-client-okhttp")
.settings(clientOkHttpSettings)

lazy val server = project
.in(file("modules/server"))
.dependsOn(common % "compile->compile;test->test")
.dependsOn(client % "test->test")
.dependsOn(internal)
.dependsOn(async)
.settings(moduleName := "frees-rpc-server")
.settings(serverSettings)

lazy val config = project
.in(file("modules/config"))
.dependsOn(core % "compile->compile;test->test")
.dependsOn(common % "test->test")
.dependsOn(client % "compile->compile;test->test")
.dependsOn(server % "compile->compile;test->test")
.settings(moduleName := "frees-rpc-config")
.settings(configSettings)

Expand All @@ -25,7 +62,12 @@ lazy val config = project

lazy val allModules: Seq[ProjectReference] = Seq(
common,
core,
async,
internal,
client,
`client-netty`,
`client-okhttp`,
server,
config
)

Expand Down
25 changes: 14 additions & 11 deletions docs/src/main/tut/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,25 @@ Freestyle RPC is a purely functional library for building RPC endpoint based ser

`frees-rpc` is cross-built for Scala `2.11.x` and `2.12.x`:

Add the following dependency to your project's build file.

[comment]: # (Start Replace)

```scala
libraryDependencies += "io.frees" %% "frees-rpc-core" % "0.6.1"
```

[comment]: # (End Replace)

Optionally, [frees-rpc] provides some configuration helpers using [frees-config] to load the application configuration values.
// required for the RPC Server:
libraryDependencies += "io.frees" %% "frees-rpc-server" % "0.6.1"

[comment]: # (Start Replace)
// required for the RPC Client/s, using either Netty or OkHttp as transport layer:
libraryDependencies += "io.frees" %% "frees-rpc-client-netty" % "0.6.1"
// or:
libraryDependencies += "io.frees" %% "frees-rpc-client-okhttp" % "0.6.1"

```scala
libraryDependencies += "io.frees" %% "frees-rpc-config" % "0.6.1"
// optional - for both server and client configuration.
libraryDependencies += "io.frees" %% "frees-rpc-config" % "0.6.1"
```

[comment]: # (End Replace)

Note: `frees-rpc-config` provides some configuration helpers using [frees-config] to load the application configuration values.

## About gRPC

> [gRPC](https://grpc.io/about/) is a modern, open source, and high-performance RPC framework that can run in any environment. It can efficiently connect services in and across data centers with pluggable support for load balancing, tracing, health checking, and authentication. It's also applicable in the last mile of distributed computing to connect devices, mobile applications, and browsers to backend services.
Expand Down Expand Up @@ -491,6 +490,8 @@ As a side note, `CommonRuntime` will also be used later on for the client progra

#### Runtime Implicits

For the server bootstrapping, remember adding `frees-rpc-server` dependency to your build.

Now, we need to implicitly provide two things:

* A runtime interpreter of our `ServiceHandler` tied to a specific type. In our case, we'll use `cats.effects.IO`.
Expand Down Expand Up @@ -560,6 +561,8 @@ Fortunately, once all the runtime requirements are in place (**`import gserver.i

[frees-rpc] derives a client automatically based on the protocol. This is especially useful because you can distribute it depending on the protocol/service definitions. If you change something in your protocol definition, you will get a new client for free without having to write anything.

You will need to add either `frees-rpc-client-netty` or `frees-rpc-client-okhttp` to your build.

### Client Runtime

Similarly in this section, as we saw for the server case, we are defining all the client runtime configurations needed for communication with the server.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,18 @@
* limitations under the License.
*/

package freestyle
package rpc
package freestyle.rpc
package async

import cats.~>
import cats.arrow.FunctionK
import cats.effect.{IO, Sync}
import freestyle.free.Capture
import cats.effect.IO
import monix.eval.Task
import monix.execution.Scheduler

import scala.concurrent.Future

trait IOCapture {

implicit def syncCapture[F[_]](implicit F: Sync[F]): Capture[F] =
new Capture[F] { def capture[A](a: => A): F[A] = F.delay(a) }
}

trait AsyncInstances {
trait RPCAsyncImplicits {

implicit val future2Task: Future ~> Task =
λ[Future ~> Task] { fa =>
Expand All @@ -47,5 +40,3 @@ trait AsyncInstances {

implicit val io2Task: IO ~> Task = λ[IO ~> Task](_.to[Task])
}

trait RPCAsyncImplicits extends AsyncInstances
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
*/

package freestyle.rpc
package client
package async

import freestyle.free.FSHandler
import freestyle.rpc.common.RpcBaseTestSuite
import monix.eval.Task

import scala.concurrent.Future

class ImplicitTests extends RpcClientTestSuite {
class RPCAsyncImplicitsTests extends RpcBaseTestSuite with RPCAsyncImplicits {

type FSHandlerTask2Future = FSHandler[Task, Future]

Expand All @@ -32,13 +33,13 @@ class ImplicitTests extends RpcClientTestSuite {

implicit val S: monix.execution.Scheduler = monix.execution.Scheduler.Implicits.global

freestyle.rpc.client.implicits.task2Future shouldBe a[FSHandlerTask2Future]
task2Future shouldBe a[FSHandlerTask2Future]
}

"fail compiling when the monix.execution.Scheduler implicit evidence is not present" in {

shapeless.test.illTyped(
"""freestyle.rpc.client.implicits.task2Future""",
"""task2Future""",
".*Cannot find an implicit Scheduler, either import monix.execution.Scheduler.Implicits.global or use a custom one.*"
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,4 @@
package freestyle.rpc
package client

import freestyle.free._
import io.grpc.{CallOptions, ClientCall, MethodDescriptor}

@free
trait ChannelM {

def newCall[I, O](
methodDescriptor: MethodDescriptor[I, O],
callOptions: CallOptions): FS[ClientCall[I, O]]

def authority: FS[String]

}
class ManagedChannelInterpreterNettyTests extends ManagedChannelInterpreterTests
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,6 @@
*/

package freestyle.rpc
package client.handlers
package client

import cats.data.Kleisli
import freestyle.free.Capture
import freestyle.rpc.client.{ChannelM, ManagedChannelOps}
import io.grpc.{CallOptions, ClientCall, MethodDescriptor}

class ChannelMHandler[M[_]](implicit C: Capture[M])
extends ChannelM.Handler[ManagedChannelOps[M, ?]] {

def newCall[I, O](
methodDescriptor: MethodDescriptor[I, O],
callOptions: CallOptions): ManagedChannelOps[M, ClientCall[I, O]] =
Kleisli(ch => C.capture(ch.newCall(methodDescriptor, callOptions)))

def authority: ManagedChannelOps[M, String] =
Kleisli(ch => C.capture(ch.authority()))
}
class ManagedChannelInterpreterOkHttpTests extends ManagedChannelInterpreterTests
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package freestyle
package rpc

import freestyle.rpc.internal.service.serviceImpl
import freestyle.rpc.internal.serviceImpl

import scala.annotation.{compileTimeOnly, StaticAnnotation}

Expand All @@ -29,17 +29,6 @@ package object protocol {

inline def apply(defn: Any): Any = meta { serviceImpl.service(defn) }
}

class rpc(val serializationType: SerializationType) extends StaticAnnotation

class stream[S <: StreamingType] extends StaticAnnotation

class message extends StaticAnnotation

class option(val name: String, val value: String, val quote: Boolean) extends StaticAnnotation

@message
object Empty
}

// $COVERAGE-ON$
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
* limitations under the License.
*/

package freestyle
package rpc
package freestyle.rpc
package client

import freestyle.free._
import freestyle.rpc.async.RPCAsyncImplicits

object implicits
extends CaptureInstances
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ package freestyle.rpc
package client

import cats.data.Kleisli
import freestyle.rpc.common.SC
import io.grpc.ManagedChannel

import scala.concurrent.duration.Duration
import scala.concurrent.{Await, Future}

class ManagedChannelInterpreterTests extends RpcClientTestSuite {
abstract class ManagedChannelInterpreterTests extends RpcClientTestSuite {

import implicits._

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import java.util.concurrent.{Callable, Executors}

import com.google.common.util.concurrent.{ListenableFuture, ListeningExecutorService, MoreExecutors}
import freestyle.rpc.client.utils.StringMarshaller
import freestyle.rpc.common.{RpcBaseTestSuite, SC}
import io.grpc.{ClientCall, ManagedChannel, MethodDescriptor}

trait RpcClientTestSuite extends RpcBaseTestSuite {
Expand Down
13 changes: 11 additions & 2 deletions modules/common/src/main/scala/protocol.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
* limitations under the License.
*/

package freestyle
package rpc
package freestyle.rpc
package protocol

import scala.annotation.StaticAnnotation

sealed trait StreamingType extends Product with Serializable
case object RequestStreaming extends StreamingType
case object ResponseStreaming extends StreamingType
Expand All @@ -26,3 +27,11 @@ case object BidirectionalStreaming extends StreamingType
sealed trait SerializationType extends Product with Serializable
case object Protobuf extends SerializationType
case object Avro extends SerializationType

class rpc(val serializationType: SerializationType) extends StaticAnnotation
class stream[S <: StreamingType] extends StaticAnnotation
class message extends StaticAnnotation
class option(val name: String, val value: String, val quote: Boolean) extends StaticAnnotation

@message
object Empty
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

package freestyle.rpc
package common

import cats.data.Kleisli
import org.scalamock.scalatest.MockFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

package freestyle.rpc
package common

object SC {

Expand Down