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

Drop deprecated ways to build connection and client #1008

Merged
merged 1 commit into from
Oct 31, 2024
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 @@ -33,6 +33,7 @@ import dev.profunktor.fs2rabbit.model.AMQPConnection
import dev.profunktor.fs2rabbit.model.RabbitChannel
import dev.profunktor.fs2rabbit.model.RabbitConnection

import java.util
import java.util.Collections
import java.util.concurrent.AbstractExecutorService
import java.util.concurrent.ExecutorService
Expand All @@ -46,47 +47,6 @@ import java.util.concurrent.Executors
object ConnectionResource {
type ConnectionResource[F[_]] = Connection[Resource[F, *]]

@deprecated(message = "Use `make` with explicit ExecutionContext", since = "5.0.0")
def make[F[_]: Sync: Log](
conf: Fs2RabbitConfig,
sslCtx: Option[SSLContext] = None,
// Unlike SSLContext, SaslConfig is not optional because it is always set
// by the underlying Java library, even if the user doesn't set it.
saslConf: SaslConfig = DefaultSaslConfig.PLAIN,
metricsCollector: Option[MetricsCollector] = None,
threadFactory: Option[F[ThreadFactory]] = None
): F[Connection[Resource[F, *]]] = {
val addThreadFactory: F[ConnectionFactory => Unit] =
threadFactory.fold(Sync[F].pure((_: ConnectionFactory) => ())) { threadFact =>
threadFact.map { tf => (cf: ConnectionFactory) =>
cf.setThreadFactory(tf)
}
}

val numOfThreads = Runtime.getRuntime().availableProcessors() * 2
val esF: F[ExecutorService] = threadFactory
.fold(Executors.newFixedThreadPool(numOfThreads).pure[F]) {
_.map(Executors.newFixedThreadPool(numOfThreads, _))
}
.map { es =>
val _ = sys.addShutdownHook(es.shutdown())
es
}

for {
es <- esF
fn <- addThreadFactory
conn <- _make(
conf,
Some(ExecutionContext.fromExecutorService(es)),
sslCtx,
saslConf,
metricsCollector,
fn
)
} yield conn
}

def make[F[_]: Sync: Log](
conf: Fs2RabbitConfig,
executionContext: ExecutionContext,
Expand Down Expand Up @@ -185,10 +145,10 @@ object ConnectionResource {
case es: ExecutorService => es
case _ =>
new AbstractExecutorService {
override def isShutdown = false
override def isTerminated = false
override def shutdown() = ()
override def shutdownNow() = Collections.emptyList[Runnable]
override def isShutdown: Boolean = false
override def isTerminated: Boolean = false
override def shutdown(): Unit = ()
override def shutdownNow(): util.List[Runnable] = Collections.emptyList[Runnable]
override def execute(runnable: Runnable): Unit = ec execute runnable
override def awaitTermination(length: Long, unit: TimeUnit): Boolean = false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,49 +40,6 @@ import javax.net.ssl.SSLContext
import scala.concurrent.ExecutionContext

object RabbitClient {
@deprecated(message = "Use `default` to create Builder instead", since = "5.0.0")
def apply[F[_]: Async](
config: Fs2RabbitConfig,
dispatcher: Dispatcher[F],
sslContext: Option[SSLContext] = None,
// Unlike SSLContext, SaslConfig is not optional because it is always set
// by the underlying Java library, even if the user doesn't set it.
saslConfig: SaslConfig = DefaultSaslConfig.PLAIN,
metricsCollector: Option[MetricsCollector] = None,
threadFactory: Option[F[ThreadFactory]] = None
): F[RabbitClient[F]] = {
val internalQ = new LiveInternalQueue[F](config.internalQueueSize.getOrElse(500))
val connection = ConnectionResource.make(config, sslContext, saslConfig, metricsCollector, threadFactory)
val consumingProgram = AckConsumingProgram.make[F](config, internalQ, dispatcher)
val publishingProgram = PublishingProgram.make[F](dispatcher)
val bindingClient = Binding.make[F]
val declarationClient = Declaration.make[F]
val deletionClient = Deletion.make[F]

connection.map { conn =>
new RabbitClient[F](
conn,
bindingClient,
declarationClient,
deletionClient,
consumingProgram,
publishingProgram
)
}
}

@deprecated(message = "Use `default` to create Builder instead", since = "5.0.0")
def resource[F[_]: Async](
config: Fs2RabbitConfig,
sslContext: Option[SSLContext] = None,
// Unlike SSLContext, SaslConfig is not optional because it is always set
// by the underlying Java library, even if the user doesn't set it.
saslConfig: SaslConfig = DefaultSaslConfig.PLAIN,
metricsCollector: Option[MetricsCollector] = None,
threadFactory: Option[F[ThreadFactory]] = None
): Resource[F, RabbitClient[F]] = Dispatcher.parallel[F](await = false).evalMap { dispatcher =>
apply[F](config, dispatcher, sslContext, saslConfig, metricsCollector, threadFactory)
}

sealed abstract class Builder[F[_]: Async] private[RabbitClient] (
config: Fs2RabbitConfig,
Expand Down