Skip to content

Instantly share code, notes, and snippets.

View lforite's full-sized avatar
💯
TTT, types types types

Louis Forite lforite

💯
TTT, types types types
View GitHub Profile
package dynamo.ast.write
import dynamo.ast.DynamoType
trait DynamoWrite[A] { self =>
def write(a: A): DynamoWriteResult[DynamoType]
def map[B](f: (A => B)): DynamoWrite[B] //not yet coded, not sure if necessary
}
@lforite
lforite / rio-talk-thread-mdc.scala
Created December 10, 2019 14:39
And example of thread MDCs usage
//storing a correlation id in thread local variables
MDC.put("correlationId", Random.alphanumeric.take(8).mkString)
//retrieving the correlation id
val correlationId = MDC.get("correlationId")
trait Logger {
def error(msg: String, t: Throwable): Unit
def info(msg: String): Unit = {
underlyingLogger.info(s"[${MDC.get("correlationId")}] $msg")
INFO [2019-05-29T08:11:18.256Z] [3jyECXXN] - Request successfully processed for client zzz
ERROR [2019-05-29T08:11:20.064Z] [1EgBpH1p] - Request failed for client aaa
ERROR [2019-05-29T08:11:20.065Z] [1EgBpH1p] - java.lang.HttpRequestException: Something went wrong ! 💥😱
at org.lforite.service-a.HttpClient.getB(HttpClient.scala:12)
at org.lforite.service-a.UnderlyingHttpClient.get(HttpClient.scala)
INFO [2019-05-29T09:45:17.964Z] [yWaQPoG7] - Request OK
ERROR [2019-05-29T13:11:19.064Z] [1EgBpH1p] - Unexpected request response: got 500
ERROR [2019-05-29T13:11:19.064Z] [1EgBpH1p] - java.lang.HttpRequestException: Unexpected request response
at org.lforite.service-b.HttpClient.getD(HttpClient.scala:29)
at org.lforite.service-b.UnderlyingHttpClient.get(UnderlyingHttpClient.scala)
WARN [2019-05-29T08:10:09.673Z] [2eHNKpmf] - Maximum thread pool size reached
ERROR [2019-05-29T08:11:07.815Z] [1EgBpH1p] - Request KO for client 4
ERROR [2019-05-29T08:11:07.815Z] [1EgBpH1p] - java.lang.JDBCConnectionException: JDBC exception: Connection to database lost
at org.lforite.service-d.SQLClient.getEntityD(SQLClient.scala:57)
at org.lforite.service d.UnderlyingSQLClient.executeQuery(UnderlyingSQLClient.scala)
INFO [2019-05-29T08:11:16.436Z] - Request OK for client xxx
INFO [2019-05-29T08:11:17.964Z] - Request OK for client yyy gf
INFO [2019-05-29T08:11:18.256Z] - Request successfully processed for client zzz
ERROR [2019-05-29T08:11:20.064Z] - Request failed for client aaa
ERROR [2019-05-29T08:11:20.064Z] - java.lang.HttpRequestException: Something went wrong ! 💥😱
at org.lforite.servicea.HttpClient.getB(HttpClient.scala:12)
at org.lforite.servicea.UnderlyingHttpClient.get(HttpClient.scala)
INFO [2019-05-29T08:11:21.415Z] - Request OK for client bbb
INFO [2019-05-29T08:11:21.473Z] - Request OK for client ccc
INFO [2019-05-29T06:10:10.436Z] - Request OK
INFO [2019-05-29T07:10:33.576Z] - Request OK
INFO [2019-05-29T08:55:17.948Z] - Request OK
INFO [2019-05-29T09:56:17.287Z] - Request OK
ERROR [2019-05-29T10:11:19.064Z] - Unexpected request response: got 500
ERROR [2019-05-29T10:11:19.064Z] - java.lang.HttpRequestException: Unexpected request response
at org.lforite.serviceb.HttpClient.getD(HttpClient.scala:29)
at org.lforite.serviceb.UnderlyingHttpClient.get(HttpClient.scala)
INFO [2019-05-29T11:11:21.415Z] - Request OK
INFO [2019-05-29T12:11:21.473Z] - Request OK
INFO [2019-05-29T08:10:07.815Z] - Received request to fetch entity D with id xyz
ERROR [2019-05-29T08:10:07.816Z] - Request ok
INFO [2019-05-29T08:10:07.817Z] - Received request to fetch entity D with id aaa
WARN [2019-05-29T08:10:09.673Z] - Maximum txO for client 4
ERROR [2019-05-29T08:11:07.815Z] - java.lang.JDBCConnectionException: JDBC exception: Connection to database lost
at org.lforite.serviced.SQLClient.getEntityD(SQLClient.scala:57)
at org.lforite.serviced.UnderlyingSQLClient.executeQuery(UnderlyingSQLClient.scala)
WARN [2019-05-29T08:10:07.816Z] - Maximum thread pool size reached
INFO [2019-05-29T08:10:08.817Z] - Start processing for entity dfe
WARN [2019-05-29T08:12:14.328Z] - Maximum thread pool size reached
trait ServiceA {
def createA(a: EntityA, cid: CorrelationId): IO[_]
}
trait ClientB {
def getB(bId: EntityBID, cid: CorrelationId): IO[_]
}
case class ServiceAImpl(clientB: ClientB) extends ServiceA {
override def createA(a: EntityA, cid: CorrelationId): IO[_] = {
trait ServiceA {
def createA(a: EntityA)(implicit cid: CorrelationId): IO[_]
}
trait ClientB {
def getB(bId: EntityBID)(implicit cid: CorrelationId): IO[_]
}
case class ServiceAImpl(clientB: ClientB) extends ServiceA {
override def createA(a: EntityA)(implicit cid: CorrelationId): IO[_] = {