finagle-core-effect


License

License

GroupId

GroupId

io.github.felixbr
ArtifactId

ArtifactId

finagle-core-effect_2.13
Last Version

Last Version

0.3.0
Release Date

Release Date

Type

Type

jar
Description

Description

finagle-core-effect
finagle-core-effect
Project URL

Project URL

https://github.com/felixbr/finagle-effect
Project Organization

Project Organization

io.github.felixbr
Source Code Management

Source Code Management

https://github.com/felixbr/finagle-effect

Download finagle-core-effect_2.13

How to add to project

<!-- https://jarcasting.com/artifacts/io.github.felixbr/finagle-core-effect_2.13/ -->
<dependency>
    <groupId>io.github.felixbr</groupId>
    <artifactId>finagle-core-effect_2.13</artifactId>
    <version>0.3.0</version>
</dependency>
// https://jarcasting.com/artifacts/io.github.felixbr/finagle-core-effect_2.13/
implementation 'io.github.felixbr:finagle-core-effect_2.13:0.3.0'
// https://jarcasting.com/artifacts/io.github.felixbr/finagle-core-effect_2.13/
implementation ("io.github.felixbr:finagle-core-effect_2.13:0.3.0")
'io.github.felixbr:finagle-core-effect_2.13:jar:0.3.0'
<dependency org="io.github.felixbr" name="finagle-core-effect_2.13" rev="0.3.0">
  <artifact name="finagle-core-effect_2.13" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.github.felixbr', module='finagle-core-effect_2.13', version='0.3.0')
)
libraryDependencies += "io.github.felixbr" % "finagle-core-effect_2.13" % "0.3.0"
[io.github.felixbr/finagle-core-effect_2.13 "0.3.0"]

Dependencies

compile (4)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.13.1
com.twitter : finagle-core_2.13 jar 20.3.0
io.catbird : catbird-effect_2.13 jar 20.3.0
com.lihaoyi : pprint_2.13 jar 0.5.5

test (5)

Group / Artifact Type Version
org.scalatest : scalatest_2.13 jar 3.0.8
org.scalacheck : scalacheck_2.13 jar 1.14.3
io.chrisdavenport : log4cats-slf4j_2.13 jar 1.0.0
ch.qos.logback : logback-classic jar 1.2.3
org.slf4j : jul-to-slf4j jar 1.7.28

Project Modules

There are no modules declared in this project.

finagle-effect

Scala CI

Wrappers around finagle clients (e.g. finagle-http and finagle-thrift), so they can easily be used in applications written in terms of cats-effect (e.g. cats.effect.IO or monix.eval.Task).

Versions

finagle-effect depends on catbird which pins the versions of finagle libraries and cats-effect.

finagle-effect Twitter OSS cats-effect
0.3.0 20.3.0 2.0.0

finagle-http-effect

libraryDependencies += "io.github.felixbr" %% "finagle-http-effect" % <version>

Usage Example

import cats.effect._
import com.twitter.finagle.http.Request
import io.chrisdavenport.log4cats.Logger
import io.chrisdavenport.log4cats.slf4j.Slf4jLogger
import io.github.felixbr.finagle.core.effect.TwitterDurationConversions
import io.github.felixbr.finagle.http.effect.client._

import scala.concurrent.duration._

object ExampleIOApp extends IOApp with TwitterDurationConversions {
  implicit def log: Logger[IO] = Slf4jLogger.getLogger[IO]

  override def run(args: List[String]): IO[ExitCode] =
    FinagleHttpClientBuilder[IO]
      .withUpdatedConfig(_.withRequestTimeout(5.seconds))
      .serviceResource("google.com:80")
      .use { googleClient =>
        for {
          _   <- log.info(s"Sending request")
          res <- googleClient(Request())
          _   <- log.info(s"Received: ${res.contentString.take(200)}")
          _   <- log.info("Done")
        } yield ExitCode.Success
      }
}

finagle-thrift-effect

libraryDependencies += "io.github.felixbr" %% "finagle-thrift-effect" % <version>

Usage Example

import cats.effect._
import io.chrisdavenport.log4cats.Logger
import io.chrisdavenport.log4cats.slf4j.Slf4jLogger
import io.github.felixbr.finagle.core.effect.{TwitterDurationConversions, TwitterFutureConversionsTo}
import io.github.felixbr.finagle.thrift.effect.client.FinagleThriftClientBuilder
import thrift.EchoService

import scala.concurrent.duration._

/**
  * `TwitterFutureConversionsTo[IO]` will try to convert `Future[A]` implicitly to `IO[A]` but in some cases the
  * type-inference isn't good enough, so you manually have to use `futureToF` to wrap calls that return `Future[A]`.
  *
  * Alternatively you can also help the type-inference by adding a type-annotation like
  * `echoService.echo("Hi"): IO[String]`.
  */
object ExampleThriftIOApp extends IOApp with TwitterDurationConversions with TwitterFutureConversionsTo[IO] {
  implicit def log: Logger[IO] = Slf4jLogger.getLogger[IO]

  override def run(args: List[String]): IO[ExitCode] =
    demoThriftServerResource.use { port => // Just so we have a server to call to in this example

      FinagleThriftClientBuilder[IO]
        .withUpdatedConfig(_.withRequestTimeout(5.seconds))
        .serviceResource[thrift.EchoService.MethodPerEndpoint](s"localhost:$port")
        .use { echoClient =>
          for {
            _   <- log.info(s"Sending request")
            res <- futureToF(echoClient.echo("Hi!")) // Here the type-inference is not clear enough, so you have to use `futureToF` or add `: IO[String]`
            _   <- log.info(s"Received: $res")
            _   <- log.info("Done")
          } yield ExitCode.Success
        }
    }

  /**
    * For demonstration purposes
    */
  private def demoThriftServerResource: Resource[IO, Int] = {
    import com.twitter.finagle.Thrift
    import com.twitter.util.Future

    val port = 12345

    Resource
      .make {
        IO {
          Thrift.server.serveIface(s":$port", new EchoService.MethodPerEndpoint {
            override def echo(input: String): Future[String] = Future.value(input)
          })
        }
      }(server => server.close()) // Here the type-inference works, so you can call `.close()` as if it returned `IO`
      .map(_.boundAddress.asInstanceOf[java.net.InetSocketAddress].getPort)
  }
}

Versions

Version
0.3.0
0.2.1
0.2.0
0.1.0