Skip to content

Commit eaca068

Browse files
retrikujbwheatley
authored andcommitted
Put back old methods with deprecated annotation
1 parent 13c017d commit eaca068

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

core/src/main/scala/dev/profunktor/fs2rabbit/algebra/Connection.scala

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import dev.profunktor.fs2rabbit.model.RabbitConnection
3636
import java.util.Collections
3737
import java.util.concurrent.AbstractExecutorService
3838
import java.util.concurrent.ExecutorService
39+
import java.util.concurrent.Executors
3940
import java.util.concurrent.ThreadFactory
4041
import java.util.concurrent.TimeUnit
4142
import javax.net.ssl.SSLContext
@@ -45,6 +46,39 @@ import scala.jdk.CollectionConverters._
4546
object ConnectionResource {
4647
type ConnectionResource[F[_]] = Connection[Resource[F, *]]
4748

49+
@deprecated(message = "Use `make` with explicit ExecutionContext", since = "5.0.0")
50+
def make[F[_]: Sync: Log](
51+
conf: Fs2RabbitConfig,
52+
sslCtx: Option[SSLContext] = None,
53+
// Unlike SSLContext, SaslConfig is not optional because it is always set
54+
// by the underlying Java library, even if the user doesn't set it.
55+
saslConf: SaslConfig = DefaultSaslConfig.PLAIN,
56+
metricsCollector: Option[MetricsCollector] = None,
57+
threadFactory: Option[F[ThreadFactory]] = None
58+
): F[Connection[Resource[F, *]]] = {
59+
val addThreadFactory: F[ConnectionFactory => Unit] =
60+
threadFactory.fold(Sync[F].pure((_: ConnectionFactory) => ())) { threadFact =>
61+
threadFact.map { tf => (cf: ConnectionFactory) =>
62+
cf.setThreadFactory(tf)
63+
}
64+
}
65+
66+
val numOfThreads = Runtime.getRuntime().availableProcessors() * 2
67+
val es = Executors.newFixedThreadPool(numOfThreads)
68+
sys.addShutdownHook(es.shutdown())
69+
70+
addThreadFactory.flatMap { fn =>
71+
_make(
72+
conf,
73+
Some(ExecutionContext.fromExecutorService(es)),
74+
sslCtx,
75+
saslConf,
76+
metricsCollector,
77+
fn
78+
)
79+
}
80+
}
81+
4882
def make[F[_]: Sync: Log](
4983
conf: Fs2RabbitConfig,
5084
executionContext: ExecutionContext,

core/src/main/scala/dev/profunktor/fs2rabbit/interpreter/RabbitClient.scala

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,50 @@ import javax.net.ssl.SSLContext
4040
import scala.concurrent.ExecutionContext
4141

4242
object RabbitClient {
43+
@deprecated(message = "Use `default` to create Builder instead", since = "5.0.0")
44+
def apply[F[_]: Async](
45+
config: Fs2RabbitConfig,
46+
dispatcher: Dispatcher[F],
47+
sslContext: Option[SSLContext] = None,
48+
// Unlike SSLContext, SaslConfig is not optional because it is always set
49+
// by the underlying Java library, even if the user doesn't set it.
50+
saslConfig: SaslConfig = DefaultSaslConfig.PLAIN,
51+
metricsCollector: Option[MetricsCollector] = None,
52+
threadFactory: Option[F[ThreadFactory]] = None
53+
): F[RabbitClient[F]] = {
54+
val internalQ = new LiveInternalQueue[F](config.internalQueueSize.getOrElse(500))
55+
val connection = ConnectionResource.make(config, sslContext, saslConfig, metricsCollector, threadFactory)
56+
val consumingProgram = AckConsumingProgram.make[F](config, internalQ, dispatcher)
57+
val publishingProgram = PublishingProgram.make[F](dispatcher)
58+
val bindingClient = Binding.make[F]
59+
val declarationClient = Declaration.make[F]
60+
val deletionClient = Deletion.make[F]
61+
62+
connection.map { conn =>
63+
new RabbitClient[F](
64+
conn,
65+
bindingClient,
66+
declarationClient,
67+
deletionClient,
68+
consumingProgram,
69+
publishingProgram
70+
)
71+
}
72+
}
73+
74+
@deprecated(message = "Use `default` to create Builder instead", since = "5.0.0")
75+
def resource[F[_]: Async](
76+
config: Fs2RabbitConfig,
77+
sslContext: Option[SSLContext] = None,
78+
// Unlike SSLContext, SaslConfig is not optional because it is always set
79+
// by the underlying Java library, even if the user doesn't set it.
80+
saslConfig: SaslConfig = DefaultSaslConfig.PLAIN,
81+
metricsCollector: Option[MetricsCollector] = None,
82+
threadFactory: Option[F[ThreadFactory]] = None
83+
): Resource[F, RabbitClient[F]] = Dispatcher[F].evalMap { dispatcher =>
84+
apply[F](config, dispatcher, sslContext, saslConfig, metricsCollector, threadFactory)
85+
}
86+
4387
sealed abstract class Builder[F[_]: Async] private[RabbitClient] (
4488
config: Fs2RabbitConfig,
4589
sslContext: Option[SSLContext],

0 commit comments

Comments
 (0)