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

Rabbitmq connection setup callback #190

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
16 changes: 14 additions & 2 deletions core/src/main/scala/com/spingo/op_rabbit/ConnectionParams.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import com.rabbitmq.client.SaslConfig
import com.rabbitmq.client.impl.DefaultExceptionHandler
import com.typesafe.config.Config
import javax.net.SocketFactory
import javax.net.ssl.SSLContext

import scala.collection.JavaConverters._
import scala.util.Try

Expand Down Expand Up @@ -39,7 +41,8 @@ case class ConnectionParams(
saslConfig: SaslConfig = DefaultSaslConfig.PLAIN,
sharedExecutor: Option[java.util.concurrent.ExecutorService] = None,
shutdownTimeout: Int = ConnectionFactory.DEFAULT_SHUTDOWN_TIMEOUT,
socketFactory: SocketFactory = SocketFactory.getDefault
socketFactory: SocketFactory = SocketFactory.getDefault,
sslContextOpt: Option[SSLContext] = None
) {
// TODO - eliminate ClusterConnectionFactory after switching to use RabbitMQ's topology recovery features.
protected [op_rabbit] def applyTo(factory: ClusterConnectionFactory): Unit = {
Expand All @@ -58,7 +61,16 @@ case class ConnectionParams(
sharedExecutor.foreach(factory.setSharedExecutor)
factory.setShutdownTimeout(shutdownTimeout)
factory.setSocketFactory(socketFactory)
if (ssl) factory.useSslProtocol()
if (ssl) {
sslContextOpt match {
case Some(sslContext) =>
// suitable for production
factory.useSslProtocol(sslContext)
case None =>
// suitable for development
factory.useSslProtocol()
}
}
}
}

Expand Down
12 changes: 9 additions & 3 deletions core/src/main/scala/com/spingo/op_rabbit/RabbitControl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package com.spingo.op_rabbit
import akka.actor.SupervisorStrategy._
import akka.actor._
import akka.util.Timeout
import com.newmotion.akka.rabbitmq.{ ConnectionActor, CreateChannel, ChannelActor, ChannelCreated, ChannelMessage }
import com.newmotion.akka.rabbitmq.{ChannelActor, ChannelCreated, ChannelMessage, Connection, ConnectionActor, CreateChannel}

import scala.concurrent.Promise
import scala.concurrent.duration._

Expand Down Expand Up @@ -67,9 +68,14 @@ private [op_rabbit] class Sequence extends Iterator[Int] {
* `akka-rabbitmq` ConnectionActor
* - [[Subscription]] - Activate the given subscription; responds with a [[SubscriptionRef]]
*/
class RabbitControl(connection: Either[ConnectionParams, ActorRef]) extends Actor with ActorLogging with Stash {
class RabbitControl(connection: Either[ConnectionParams, ActorRef],
setupConnectionCallback: (Connection, ActorRef) => Any = (_, _) => ()) extends Actor with ActorLogging with Stash {
def this() = this(Left(ConnectionParams.fromConfig()))
def this(connectionParams: ConnectionParams) = this(Left(connectionParams))
def this(connectionParams: ConnectionParams, setupConnectionCallback: (Connection, ActorRef) => Any) = {
this(Left(connectionParams), setupConnectionCallback)
}

def this(actorRef: ActorRef) = this(Right(actorRef))

val sequence = new Sequence
Expand All @@ -93,7 +99,7 @@ class RabbitControl(connection: Either[ConnectionParams, ActorRef]) extends Acto
val connectionFactory = new ClusterConnectionFactory
connectionParams.applyTo(connectionFactory)
context.actorOf(
ConnectionActor.props(connectionFactory),
ConnectionActor.props(connectionFactory, setupConnection = setupConnectionCallback),
name = CONNECTION_ACTOR_NAME)

case Right(actorRef) => actorRef
Expand Down
2 changes: 1 addition & 1 deletion project/version.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=2.1.0
version=2.1.0