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

make timey config options finite durations #499

Merged
merged 4 commits into from
Mar 1, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ object ConnectionResource {
factory.setHost(firstNode.host)
factory.setPort(firstNode.port)
factory.setVirtualHost(conf.virtualHost)
factory.setConnectionTimeout(conf.connectionTimeout)
factory.setRequestedHeartbeat(conf.requestedHeartbeat)
factory.setConnectionTimeout(conf.connectionTimeout.toMillis.toInt)
factory.setRequestedHeartbeat(conf.requestedHeartbeat.toSeconds.toInt)
factory.setAutomaticRecoveryEnabled(conf.automaticRecovery)
if (conf.ssl) sslCtx.fold(factory.useSslProtocol())(factory.useSslProtocol)
factory.setSaslConfig(saslConf)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@

package dev.profunktor.fs2rabbit.config

import java.util.concurrent.TimeUnit

import cats.data.NonEmptyList
import com.rabbitmq.client.ConnectionFactory

import scala.concurrent.duration.FiniteDuration

case class Fs2RabbitNodeConfig(
host: String,
port: Int
Expand All @@ -27,14 +31,14 @@ case class Fs2RabbitNodeConfig(
case class Fs2RabbitConfig(
nodes: NonEmptyList[Fs2RabbitNodeConfig],
virtualHost: String,
connectionTimeout: Int,
connectionTimeout: FiniteDuration,
ssl: Boolean,
username: Option[String],
password: Option[String],
requeueOnNack: Boolean,
requeueOnReject: Boolean,
internalQueueSize: Option[Int],
requestedHeartbeat: Int,
requestedHeartbeat: FiniteDuration,
automaticRecovery: Boolean
)

Expand All @@ -43,14 +47,14 @@ object Fs2RabbitConfig {
host: String,
port: Int,
virtualHost: String,
connectionTimeout: Int,
connectionTimeout: FiniteDuration,
ssl: Boolean,
username: Option[String],
password: Option[String],
requeueOnNack: Boolean,
requeueOnReject: Boolean,
internalQueueSize: Option[Int],
requestedHeartbeat: Int = ConnectionFactory.DEFAULT_HEARTBEAT,
requestedHeartbeat: FiniteDuration = FiniteDuration(ConnectionFactory.DEFAULT_HEARTBEAT, TimeUnit.SECONDS),
automaticRecovery: Boolean = true
): Fs2RabbitConfig = Fs2RabbitConfig(
nodes = NonEmptyList.one(Fs2RabbitNodeConfig(host, port)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ object DropwizardMetricsDemo extends IOApp.Simple {
username = Some("guest"),
password = Some("guest"),
ssl = false,
connectionTimeout = 3,
connectionTimeout = 3.seconds,
requeueOnNack = false,
requeueOnReject = false,
internalQueueSize = Some(500),
requestedHeartbeat = 60,
requestedHeartbeat = 60.seconds,
automaticRecovery = true
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import dev.profunktor.fs2rabbit.config.{Fs2RabbitConfig, Fs2RabbitNodeConfig}
import dev.profunktor.fs2rabbit.interpreter.RabbitClient
import dev.profunktor.fs2rabbit.resiliency.ResilientStream

import scala.concurrent.duration.DurationInt

object IOAckerConsumer extends IOApp.Simple {

private val config: Fs2RabbitConfig = Fs2RabbitConfig(
Expand All @@ -30,11 +32,11 @@ object IOAckerConsumer extends IOApp.Simple {
username = Some("guest"),
password = Some("guest"),
ssl = false,
connectionTimeout = 3,
connectionTimeout = 3.seconds,
requeueOnNack = false,
requeueOnReject = false,
internalQueueSize = Some(500),
requestedHeartbeat = 60,
requestedHeartbeat = 60.seconds,
automaticRecovery = true
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import dev.profunktor.fs2rabbit.interpreter.RabbitClient
import dev.profunktor.fs2rabbit.model._
import fs2.Stream

import scala.concurrent.duration.DurationInt

object RPCDemo extends IOApp.Simple {

private val config: Fs2RabbitConfig = Fs2RabbitConfig(
Expand All @@ -42,11 +44,11 @@ object RPCDemo extends IOApp.Simple {
username = Some("guest"),
password = Some("guest"),
ssl = false,
connectionTimeout = 3,
connectionTimeout = 3.seconds,
requeueOnNack = false,
requeueOnReject = false,
internalQueueSize = Some(500),
requestedHeartbeat = 60,
requestedHeartbeat = 60.seconds,
automaticRecovery = true
)

Expand Down
4 changes: 3 additions & 1 deletion site/docs/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ import cats.syntax.functor._
import dev.profunktor.fs2rabbit.interpreter.RabbitClient
import java.util.concurrent.Executors

import scala.concurrent.duration._

object Program {
def foo[F[_]](client: RabbitClient[F]): F[Unit] = ???
}
Expand All @@ -55,7 +57,7 @@ class Demo extends IOApp {
password = Some("guest"),
port = 5672,
ssl = false,
connectionTimeout = 3,
connectionTimeout = 3.seconds,
requeueOnNack = false,
requeueOnReject = false,
internalQueueSize = Some(500)
Expand Down
6 changes: 4 additions & 2 deletions site/docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ The main `RabbitMQ` configuration should be defined as `Fs2RabbitConfig`. You ch
import cats.data.NonEmptyList
import dev.profunktor.fs2rabbit.config.{Fs2RabbitConfig, Fs2RabbitNodeConfig}

import scala.concurrent.duration._

val config = Fs2RabbitConfig(
virtualHost = "/",
nodes = NonEmptyList.one(
Expand All @@ -23,11 +25,11 @@ val config = Fs2RabbitConfig(
username = Some("guest"),
password = Some("guest"),
ssl = false,
connectionTimeout = 3,
connectionTimeout = 3.seconds,
requeueOnNack = false,
requeueOnReject = false,
internalQueueSize = Some(500),
requestedHeartbeat = 30,
requestedHeartbeat = 30.seconds,
automaticRecovery = true
)
```
Expand Down
4 changes: 2 additions & 2 deletions site/docs/examples/client-metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ object DropwizardMetricsDemo extends IOApp {
username = Some("guest"),
password = Some("guest"),
ssl = false,
connectionTimeout = 3,
connectionTimeout = 3.seconds,
requeueOnNack = false,
requeueOnReject = false,
internalQueueSize = Some(500),
requestedHeartbeat = 60,
requestedHeartbeat = 60.seconds,
automaticRecovery = true
)

Expand Down
6 changes: 4 additions & 2 deletions site/docs/examples/sample-acker.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ import dev.profunktor.fs2rabbit.interpreter.RabbitClient
import dev.profunktor.fs2rabbit.resiliency.ResilientStream
import java.util.concurrent.Executors

import scala.concurrent.duration.DurationInt

object IOAckerConsumer extends IOApp {

private val config: Fs2RabbitConfig = Fs2RabbitConfig(
Expand All @@ -109,11 +111,11 @@ object IOAckerConsumer extends IOApp {
username = Some("guest"),
password = Some("guest"),
ssl = false,
connectionTimeout = 3,
connectionTimeout = 3.seconds,
requeueOnNack = false,
requeueOnReject = false,
internalQueueSize = Some(500),
requestedHeartbeat = 60,
requestedHeartbeat = 60.seconds,
automaticRecovery = true
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,22 @@ import cats.implicits._
import dev.profunktor.fs2rabbit.BaseSpec
import dev.profunktor.fs2rabbit.config.Fs2RabbitConfig

import scala.concurrent.duration.DurationInt

class RabbitSuite extends BaseSpec with Fs2RabbitSpec {

override val config: Fs2RabbitConfig =
Fs2RabbitConfig(
host = "localhost",
port = 5672,
virtualHost = "/",
connectionTimeout = 30,
connectionTimeout = 30.seconds,
ssl = false,
username = "guest".some,
password = "guest".some,
requeueOnNack = false,
requeueOnReject = false,
requestedHeartbeat = 60,
requestedHeartbeat = 60.seconds,
internalQueueSize = 500.some
)

Expand Down