/
AppRFMClient.scala
62 lines (51 loc) · 1.71 KB
/
AppRFMClient.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package scalaexchange
package app
import cats.effect.IO
import freestyle.rpc.protocol.Empty
import freestyle.asyncCatsEffect.implicits._
import freestyle.rpc.client.implicits._
import monix.reactive.Observable
import scala.concurrent.Await
import scala.concurrent.duration._
import scalaexchange.services.protocol._
object AppRFMClient extends Implicits {
def main(args: Array[String]): Unit = {
implicit val rfmClient: RFMAnalysisService.Client[IO] =
RFMAnalysisService.client[IO](channel)
val (segments: IO[SegmentList], stream: Observable[UserEvent], ack: IO[Ack]) =
(
rfmClient.segments(Empty),
rfmClient.userEvents(Empty),
rfmClient.orderStream(ordersStreamObs)
)
println(s"Segments: \n${segments.unsafeRunSync().list.mkString("\n")}\n")
println(s"Client Streaming: \n${ack.unsafeRunSync()}\n")
Await.ready(
stream
.map { u =>
println(u)
u
}
.completedL
.runAsync,
Duration.Inf)
}
private[this] def ordersStreamObs: Observable[Order] = {
val orderList: List[Order] = (1 to 1000).map { customerId =>
import com.fortysevendeg.scalacheck.datetime.GenDateTime
import org.joda.time.{DateTime, Period}
import org.scalacheck._
import com.fortysevendeg.scalacheck.datetime.instances.joda.jodaForPeriod
(for {
date <- GenDateTime.genDateTimeWithinRange(DateTime.parse("2017-12-01"), Period.days(22))
orderId <- Gen.uuid
total <- Gen.choose[Int](5, 200)
} yield
Order(
customerId,
CustomerData(date.toString, orderId.toString, total)
)).sample.get
}.toList
Observable.fromIterable(orderList)
}
}