Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.concurrent.Executors
- import cats.effect.{Blocker, ExitCode, IO, IOApp, Resource, Sync}
- import dev.profunktor.fs2rabbit.config.Fs2RabbitConfig
- import dev.profunktor.fs2rabbit.interpreter.RabbitClient
- import dev.profunktor.fs2rabbit.model.{ExchangeName, RoutingKey}
- object Demo extends IOApp {
- val config: Fs2RabbitConfig = Fs2RabbitConfig(
- virtualHost = "/",
- host = "127.0.0.1",
- username = Some("guest"),
- password = Some("guest"),
- port = 5672,
- ssl = false,
- connectionTimeout = 3,
- requeueOnNack = false,
- internalQueueSize = Some(500)
- )
- val blockerResource: Resource[IO, Blocker] =
- Resource
- .make(IO(Executors.newCachedThreadPool()))(es => IO(es.shutdown()))
- .map(Blocker.liftExecutorService)
- override def run(args: List[String]): IO[ExitCode] = {
- import cats.syntax.functor.toFunctorOps
- blockerResource.use { blocker =>
- RabbitClient[IO](config, blocker).flatMap { client =>
- Program.foo[IO](client).as(ExitCode.Success)
- }
- }
- }
- }
- object Program {
- import cats.syntax.flatMap.toFlatMapOps
- def foo[F[_]: Sync](client: RabbitClient[F]): F[Unit] = {
- client.createConnectionChannel.use { implicit channel =>
- client.createPublisher(ExchangeName("test"), RoutingKey("")).flatMap { publish =>
- publish("Hello")
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment