Skip to content

Rabbitmq connection setup expose channel rpc timeout #192

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

Open
wants to merge 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ case class ConnectionParams(
sharedExecutor: Option[java.util.concurrent.ExecutorService] = None,
shutdownTimeout: Int = ConnectionFactory.DEFAULT_SHUTDOWN_TIMEOUT,
socketFactory: SocketFactory = SocketFactory.getDefault,
sslContextOpt: Option[SSLContext] = None
sslContextOpt: Option[SSLContext] = None,
channelRpcTimeout: Int = ConnectionFactory.DEFAULT_CHANNEL_RPC_TIMEOUT
) {
// TODO - eliminate ClusterConnectionFactory after switching to use RabbitMQ's topology recovery features.
protected [op_rabbit] def applyTo(factory: ClusterConnectionFactory): Unit = {
Expand Down Expand Up @@ -71,6 +72,8 @@ case class ConnectionParams(
factory.useSslProtocol()
}
}

factory.setChannelRpcTimeout(channelRpcTimeout)
}
}

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